Problem with menu widget - First Menu Item Returns "0" instead of "1" - Wrong Numbering

I have a menu widget with 4 menu items.

when I select:

  • the first one I get nothing in the arduino
  • the second one I get “1” instead of 2
  • the third one I get “2” instead of 3
  • the fourth one I get “3” instead of 4

HW - NodeMCU 1.0

Here is the code:

#define BLYNK_PRINT Serial

#include <Ethernet.h>
#include <BlynkSimpleEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>

const char* auth     = "xxx";

const char* ssid     = "xxx";
const char* password = "xxx"; 

BLYNK_CONNECTED()
{
  Blynk.syncAll();
}


BLYNK_WRITE(V4)
{
  if (param.asInt()==1)    Serial.println ("1");
  if (param.asInt()==2)    Serial.println ("2");
  if (param.asInt()==3)    Serial.println ("3");
  if (param.asInt()==4)    Serial.println ("4");
}


void setup()
{
  Serial.begin(115200);

  Blynk.begin(auth, ssid, password);
  while (Blynk.connect() == false) {}
}

void loop()
{
  Blynk.run();
}

I think perhaps you need to consider that sometimes zero does NOT mean nothing…

Are you using iOS or Android?

IOS pavel app

xxxxxxxxxxxxxxxxxx

It’s fixed and will be available in next release

I think perhaps you need to consider that sometimes zero does NOT mean nothing…

Please explain.

When using lists sometimes the first item is 0 not 1… But if it’s a bug, then not in this case…

When using lists sometimes the first item is 0 not 1… But if it’s a bug, then not in this case.

BLYNK_WRITE(V4)
{
 Serial.println(param.asInt());
}

and you are right - I get “0” for the first item instead of the expeted “1”

The widget does use “item 1, item 2, etc.” However, @Dave1829 was alluding to was the fact that computer languages normally begin a list with item “0”, rather than “1”. Until the discrepancy is resolved, wouldn’t the simplest thing be to make your code comply with that convention?

BLYNK_WRITE(V4)
{
  if (param.asInt()==0)    Serial.println ("1");
  if (param.asInt()==1)    Serial.println ("2");
  if (param.asInt()==2)    Serial.println ("3");
  if (param.asInt()==3)    Serial.println ("4");
}

yes of course.
Thats what I did.
I mentioned it because this is not the expected behaviour.

Andreas