BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Menu widgets issues on Blynk 2.0

I’m having trouble with the menu widget. I want to point out that I used this widget in “old blynk” in a complex app without problems, but now it seems not to work.

I am using arduino MKR1010 and iOS and I have prepared a simple app and a test software.

The app consists of a single widget: menu connected to vpin V0, like this:
image
image
my aim is to obtain a choice menu imposed on the hardware side consisting of “S0, S1 … S9”.

Firts try. I download the “Blynk.Edgent” example and make changes to update the menu once connected to the cloud.

// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLwuxyywbi"
#define BLYNK_DEVICE_NAME "TestMenu"
#define BLYNK_FIRMWARE_VERSION        "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
#include "BlynkEdgent.h"

String MenuItem[10]={"S0","S1","S2","S3","S4","S5","S6","S7","S8","S9"};
int flag_upd_menu=0;

void setup()
  {
  Serial.begin(9600);
  delay(2000);
  BlynkEdgent.begin();
  }

void loop() 
  {
  BlynkEdgent.run();
  if (Blynk.connected())
    {
    if (flag_upd_menu==0)
      {
      flag_upd_menu=1;
      BlynkParamAllocated items(128);
      for (int i=0;i<10;i++) items.add(MenuItem[i]);
      Blynk.setProperty(V0, "labels", items); 
      }      
    }
  }

Result:
image
And there is no way to make the other items appear!

I think: maybe when I call Blynkparamallocated the hardware is not yet connected to the cloud (even if Blynk.connected () says yes), so…

Second try: I’ll wait (we say) 15 s after Blynk.connected() says…connected!

// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLwuxyywbi"
#define BLYNK_DEVICE_NAME "TestMenu"
#define BLYNK_FIRMWARE_VERSION        "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
#include "BlynkEdgent.h"

String MenuItem[10]={"S0","S1","S2","S3","S4","S5","S6","S7","S8","S9"};
int flag_upd_menu=0;
long BaseTime=0;
void setup()
  {
  Serial.begin(9600);
  delay(2000);
  BlynkEdgent.begin();
  }

void loop() 
  {
  BlynkEdgent.run();
  if (Blynk.connected())
    {
    if (millis()-BaseTime>15000) //wait 15 s after blynk connection before update
      {
      if (flag_upd_menu==0)
        {
        flag_upd_menu=1;
        BlynkParamAllocated items(128);
        for (int i=0;i<10;i++) items.add(MenuItem[i]);
        Blynk.setProperty(V0, "labels", items); 
        SerialUSB.println("menu items updated!");
        }
      }      
    }
  else BaseTime=millis();
  }

Result:
image
I say: ok I found a solution, I don’t like it so much but it works … But if I lock the phone and after 2-3 minutes I go to see the menu again … I only find S0 !!!

What am I doing wrong?

Is there a bug (or more than one)?

When Blynk.connected says connected is that so?

Obviously I have to suspend my project because this widget is essential for me, so help me!

The first thing you need to do is to move that code out of the void loop.

If you want to do something once, when the device connects to Blynk then put it in the BLYNK_CONNECTED() callback function.

Pete.

1 Like

Thank for your prompt reply, here it is.

// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLwuxyywbi"
#define BLYNK_DEVICE_NAME "TestMenu"
#define BLYNK_FIRMWARE_VERSION        "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
#include "BlynkEdgent.h"

String MenuItem[10]={"S0","S1","S2","S3","S4","S5","S6","S7","S8","S9"};

BLYNK_CONNECTED()
  {
  BlynkParamAllocated items(128);
  for (int i=0;i<10;i++) items.add(MenuItem[i]);
  Blynk.setProperty(V0, "labels", items);
  SerialUSB.println("Menu' updated!");    
  }

void setup()
  {
  Serial.begin(9600);
  delay(2000);
  BlynkEdgent.begin();
  }

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

But, unfortunately, same result (i.e. only S0) :sob: :sob:

Bresca

Your datastream seems to be set-up with a minimum value of 1, yet your are using 0 as the starting index start for your array. What happens if you change this?

Pete.

I’ve tried to change datastream in this way:

result is:

so it is good, but if I lock my phone and after 1-2 minutes i go back to see menu, I see:

:sob: :sob:

I think it is time for blynk developers to say something :pray: :pray:

Bresca

I think you should log it as an issue on the GitHub issues page.

Pete.

Opened an issue on Github. Thank to @PeteKnight for initial support

If it can be useful, I got the similar behavior with an android phone.

Below the issue link
Menu widget issues · Issue #209 · blynkkk/blynk_Issues (github.com)

Closed today. Now it is working!