Menu widget

Hi all,

I’m wondering if it’s possible to read text from menu widget from hardware side?

Read from, no… Labels in Widgets don’t seem to be designed for “end user” editing (AKA when project active), they can be written from the sketch or when editing, but not read from the sketch… no real world reason to need that.

@GG07: What would be the application for this - if it was avail?

I have a button widget and when pressed sends an email. So initially the email address, subject and message was coded into the hardware. I recently modified this by adding 3 x text input widgets (email address, subject and message) so I could modify the email address, subject and message from the Blynk app. Now I want a drop down menu to select a different email address. Is this possible some other way perhaps?

Well the menu wouldn’t send the label text to the hardware anyhow… only the index [1], [2]… etc…

image

depending on how many emails you want displayed at a time, a combo of Display Widgets and a Segmented Switch to chose from the choices

Thanks Gunner, any ideas at all? … Is this something Blynk could include in the future. I guess there would need to be a demand for it.

Opps… I was still editing… see above :slight_smile:

Thanks @Gunner for your idea and speedy replies.

@GG07: Something like this could do the job:

[...]
String emailAddress;
String _emailAddress[4] = {"","mail1@domain1.com","mail2@domain2.com","mail3@domain3.com"};

BLYNK_WRITE(V0) {   // Menu Widget on V0
  int index = param.asInt();
  switch (index)
  {
    case 1:
    case 2:
    case 3:
               emailAddress = _emailAddress[index];
               break;
    default:
               //Serial.println("Unknown item selected");
               break;
  }
}
[...]

Thank you @IBK for your help also. Does this way allow me to enter email addresses from app side? Ideally this is what I would like.

Yes you can set email addresses with text input or terminal widgets.

Thanks @Costas but Ideally I want to enter email addresses from app side and select an email address from drop down menu.

Combine text input with menu widget. Your sketch can update the menu items.

1 Like

OK thanks @Costas I’ll give this a try.

@GG07: I’d try something like this:

[...]

String emailAddress;
String _emailAddress[4];

BLYNK_WRITE(V1) {   // Text Input Widget on V1
  _emailAddress[1] = param.asStr();
}

BLYNK_WRITE(V2) {   // Text Input Widget on V2
  _emailAddress[2] = param.asStr();
}

BLYNK_WRITE(V3) {   // Text Input Widget on V3
  _emailAddress[3] = param.asStr();
}

BLYNK_WRITE(V0) {   // Menu Widget on V0
  int index = param.asInt();
  switch (index)
  {
    case 1:
    case 2:
    case 3:
               emailAddress = _emailAddress[index];
               break;
    default:
               //Serial.println("Unknown item selected");
               break;
  }
}

[...]

1 Like

Thanks again @IBK. I’ll be Having a go at this today.

Well after a few hours of fine tuning I’ve successfully got what I wanted with the tools Blynk currently provide.

Thanks again to @IBK @Gunner @Costas for their ideas and speedy responses to help me achieve this.

Here’s the code that relates to this issue which enables me to select an email address from a drop down menu and select a subject / message which is also pre-defined from a drop down menu. A button widget is then pressed to send the email.

Both the email addresses and subject messages are pre-defined via text input widgets.

Please let me know if you think the code can be improved or condensed any…very much appreciated.

//varibales declared
String emailAddress;
String _emailAddress[4];
String emailSubject;
String _emailSubject[4];

//Virtual Pins synced - text input widgets and drop down menu widgets
BLYNK_CONNECTED() {
    Blynk.syncVirtual(V93, V94, V95, V98, V99, V100, V103, V104);
}

//Button Widget to send email.
BLYNK_WRITE(V105) {
  if (param.asInt() == 1){
  Blynk.email(emailAddress.c_str(), emailSubject.c_str(), emailSubject.c_str());
  }
}

//Text Input Widgets V93, V94, V95 for email addresses also a blynk set property to update drop down menu with changes
BLYNK_WRITE(V93) {
  _emailAddress[1] = param.asStr();
  Blynk.setProperty(V103, "labels", _emailAddress[1].c_str(), _emailAddress[2].c_str(), _emailAddress[3].c_str());
}

BLYNK_WRITE(V94) {
  _emailAddress[2] = param.asStr();
  Blynk.setProperty(V103, "labels", _emailAddress[1].c_str(), _emailAddress[2].c_str(), _emailAddress[3].c_str());
}

BLYNK_WRITE(V95) {
  _emailAddress[3] = param.asStr();
  Blynk.setProperty(V103, "labels", _emailAddress[1].c_str(), _emailAddress[2].c_str(), _emailAddress[3].c_str());
}

 //Text Input Widgets V98, V99, V100 for Email subject / Message also a blynk set property to update drop down menu with changes
BLYNK_WRITE(V98) {
  _emailSubject[1] = param.asStr();
  Blynk.setProperty(V104, "labels", _emailSubject[1].c_str(), _emailSubject[2].c_str(), _emailSubject[3].c_str());
}

BLYNK_WRITE(V99) {
  _emailSubject[2] = param.asStr();
  Blynk.setProperty(V104, "labels", _emailSubject[1].c_str(), _emailSubject[2].c_str(), _emailSubject[3].c_str());
}

BLYNK_WRITE(V100) {
  _emailSubject[3] = param.asStr();
  Blynk.setProperty(V104, "labels", _emailSubject[1].c_str(), _emailSubject[2].c_str(), _emailSubject[3].c_str());
}

// Menu Widget on V103 for email address
BLYNK_WRITE(V103) {   
  int index = param.asInt();
  switch (index)
  {
case 1:
case 2:
case 3:
case 4:
            emailAddress = _emailAddress[index];
           break;
default:
           //Serial.println("Unknown item selected");
           break;
  }
}

// Menu Widget on V104 for email subject
BLYNK_WRITE(V104) {  
  int index1 = param.asInt();
  switch (index1)
  {
case 1:
case 2:
case 3:
case 4:
            emailSubject = _emailSubject[index1];
           break;
default:
           //Serial.println("Unknown item selected");
           break;
  }
}
   
void setup()
[...]
//update menu widgets items on device power up
  Blynk.setProperty(V103, "labels", _emailAddress[1].c_str(), _emailAddress[2].c_str(), _emailAddress[3].c_str());

   Blynk.setProperty(V104, "labels", _emailSubject[1].c_str(), _emailSubject[2].c_str(), _emailSubject[3].c_str());
   [...]
3 Likes

Genial!!!