Greetings everyone, i need help with my project where i am trying to use on/off switch toggle when the esp takes a signal from the arduino, and then read a status of that on/off switch from the server with another esp8266 to do action, for example: if my train enters the station and stops, it send to the cloud that train stopped at base, then the base reads the status of this switch to open a protection sheild gate
3. Add details :
• Hardware model: esp8266
• Blynk server
• Blynk Library version 1.2.0
• using Arduino ide
sorry for the inconvenience, and thank you for the fast reply.
void setup() {
Serial.begin(115200);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
Serial.println("Started.... ");
}
// in the next section, the value is not getting called from the server even when i try to print the data on serial monitor
BLYNK_WRITE(V1) {
int pinValue = param.asInt();
if (pinValue == 1) {
digitalWrite(2, HIGH);
} else {
digitalWrite(2, LOW);
}
}
void loop() {
Blynk.run();
// receive from arduino and send to cloud
if (Serial.available()) {
String data_rcvd = Serial.readString();
data_rcvd.trim();
if (data_rcvd == "Rail_1_on") {
Blynk.virtualWrite(V1, 1);
}
if (data_rcvd == "Rail_1_off") {
Blynk.virtualWrite(V1, 0);
}
}
}
i`m sorry Pete, but it seems i didnt explain my problem well, my problem is the code below doesn’t retrieve data status from the cloud.
thats why it is always 0 so no change happens, and no result on serial monitor if i tried to print the result.
this is a received serial signal from Arduino to the esp8266 to toggle on/off relating to the received string.
and it does change automatically the switch state on the cloud, with every time esp gets a string it is compared and the status is changed
however, I am trying to recall the status of that V1 to toggle another switch that will lead to another function to be executed.
although, it is working only when i manually change the status of the switch from the cloud.
and this is my project example. this operation should be completely automated with sensors
I’ve already explained that BLYNK_WRITE(Vpin) isn’t triggered by a Blynk.virtualWrite(VPin) from the same device.
This is to avoid the possibility of an infinite loop being created.
As I already said, you shouldn’t be using Blynk to trigger that other function, just trigger the function directly in your sketch when the appropriate criteria is met.
Understood, but I want to trigger it from another device not the same device, can I overwrite the library or subscribe to a premium plan that will make me able to trigger the function from another device?
You can trigger it from another device (device B) , provided that device has its own Auth token and you use the Auth token of device A in an HTTP(S) REST API call.
Depending on your use-case and the frequency of these data transfers, you may also be able to use Automations.