So i tried the code and did everything i could currently but i think the cause of the problem is that the “toggleState” is not changing whenver i switch the widget on the app. After it initialized the serial monitor shows that the “toggleState” is equal to 0 even though i set it to 1 in the beginning.
I’d suggest that you post your latest code in full, along with the serial output from boot-up, including the Blynk logo etc.
Pete.
I tried to make an arduino code that I can translate to later in the node code. Here it is:
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID "TMPLMViRV5PY"
#define BLYNK_DEVICE_NAME "TEST WIFI"
#define BLYNK_AUTH_TOKEN "m-NbVhz5dHeT6AzfMjZ_FhwXqQ8NJl_F"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Unidentified Network";
char pass[] = "Test";
// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1
// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 38400
#define VPIN_BUTTON V1
#define RELAY_PIN 8
ESP8266 wifi(&EspSerial);
void setup()
{
pinMode(RELAY_PIN, OUTPUT);
// Debug console
Serial.begin(115200);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, wifi, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);
}
BLYNK_CONNECTED()
{
// Request the latest state from the server
Blynk.syncVirtual(VPIN_BUTTON);
}
// When App button is pushed - switch the state
BLYNK_WRITE(VPIN_BUTTON)
{
if(param.asInt() == 1)
{
// execute this code if the switch widget is now ON
digitalWrite(RELAY_PIN,HIGH); // Set relay pin to HIGH
Serial.print("HIGH");
}
else
{
// execute this code if the switch widget is now OFF
digitalWrite(RELAY_PIN,LOW); // Set relay pin to LOW
Serial.print("LOW");
}
}
void loop()
{
Blynk.run();
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
}
And the serial boot up is as follows:
[9]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v1.1.0 on Arduino Uno
#StandWithUkraine https://bit.ly/swua
[521] Connecting to Unidentified Network
[13558] AT version:1.2.0.0(Jul 1 2016 20:04:45)
SDK version:1.5.4.1(39cb9a32)
v1.0.0
Ma1821
[14574] Failed to enable MUX
[21659] +CIFSR:STAIP,"192.168.1.11"
+CIFSR:STAMAC,"ec:fa:bc:c3:24:fd"
[21660] Connected to WiFi
[31848] Ready (ping: 13ms).
LOW
As you can see. The screen display shows “LOW” and when i try to change the state on the app it does not change.
Can you post screenshots of your V1 datastream setup, and the widget you have attached to the V1 datastream (in dashboard edit mode)?
Pete.
When you said “app” did you actually mean app, or web dashboard as you’ve shown in the screenshots?
Are you aware that widgets added to the mobile app dashboard have to be configured independently of any web dashboard widgets?
Pete.
Yes i am aware that there is a different configuration on the app on mobile. I have configured it as well by using buttons on switch mode. But still the results are same. Either way the problem remains
Try this example
Okay so this is what i have right now:
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID "TMPLMViRV5PY"
#define BLYNK_DEVICE_NAME "TEST WIFI"
#define BLYNK_AUTH_TOKEN "m-NbVhz5dHeT6AzfMjZ_FhwXqQ8NJl_F"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Unidentified Network";
char pass[] = "Test";
int toggleState = 1;
// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1
// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 38400
#define VPIN_BUTTON V1
#define RELAY_PIN 8
ESP8266 wifi(&EspSerial);
void setup()
{
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, toggleState);
// Debug console
Serial.begin(115200);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, wifi, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);
}
BLYNK_CONNECTED()
{
// Request the latest state from the server
Blynk.syncVirtual(VPIN_BUTTON);
}
// When App button is pushed - switch the state
BLYNK_WRITE(VPIN_BUTTON)
{
toggleState = param.asInt();
if(toggleState == 1)
{
// execute this code if the switch widget is now ON
digitalWrite(RELAY_PIN,HIGH); // Set relay pin to HIGH
Serial.print(toggleState);
}
else
{
// execute this code if the switch widget is now OFF
digitalWrite(RELAY_PIN,LOW); // Set relay pin to LOW
Serial.print(toggleState);
}
}
void loop()
{
Blynk.run();
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
}
It works on mobile but it doesnt work on the web dashboard
Someone says you need to code it further so that it can work on the web dashboard as well?