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:
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:
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:
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!