I’m trying to send values that read from the GPS widget, V1, to be printed on the terminal widget,V0, when ever I’m enter “1” in the terminal. However, for some reasons, the GPS widget keep sending values and printed to the terminal widget even when the statement, " State", is false. Anyone know what am I doing wrong here. Here is the code:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "xxxxx";
char ssid[] = "xxxxx";
char pass[] = "xxxxx";
int State = 0;
WidgetTerminal terminal(V0);
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
BLYNK_WRITE(V0){
terminal.print(" Choose the below options: ");
terminal.print('\n');
terminal.print(" 1. My GPS position ");
terminal.flush();
if( String("1") == param.asStr()){
State = 2;
}
else if( String("clear") == param.asStr()){
terminal.clear();
terminal.flush();
}
}
BLYNK_WRITE(V1){
GpsParam gps(param);
float Lat = gps.getLat();
float Lon = gps.getLon();
if( State = 2){
Blynk.virtualWrite(V0,"Longtitude: ");
Blynk.virtualWrite(V0,Lon);
Blynk.virtualWrite(V0," ");
Blynk.virtualWrite(V0," Latitude: ");
Blynk.virtualWrite(V0,Lat);
State = 0;
delay(500);
}
else{
State = 0;
}
}
void loop()
{
Blynk.run();
Serial.println(State);
delay(500);
}
Thank you very much!