What is causing the On/Off payload values to switch from the entered values in Node-Red “Edit switch node”? I have noted the warnings in the course material and I have had some luck getting them to work but not always. I have entered the digits “1” and “0” as numbers and strings but they always change back to “true” and “false” . This appears contrary to course instructions but I can’t make it work reliably enough.
Hello, can you add to those fields the words “on” and “off”. Then, in the code if/else statements, can you change it also to “on” and “off”? Instead of “1” and “0”…
If you need further help let me know. Thanks for your patience. Regards,
Rui
I thought of that later but have not had a chance to try it. But I will today and let you know what happens. It always seems to want to change it to “true” or “false” no matter if I select number or string.
I will keep you posted.
Ok! Keep me updated, if the error persists I’ll have to double-check and update the course. Regards,
Rui
Rui,
I tried as previously discussed. The code is here. This allowed the use of either “1” or “true”, “0” or “false”. However, I still found some irregularity here as sometimes the inputs would change after clicking “DONE” . For the most part, input error would be caught and reported after selecting “DEPLOY” . The flow error would be reported. This is getting pretty picky but frustrating for someone new to this stuff. (me)
Thanks for your help, I still need to learn how to copy code from the IDE to insert into this forum..
______________________
if(topic==”home/office/esp1/gpio2″){
Serial.print(“Changing GPIO 2 to “);
if(messageTemp == “true”);
else if(messageTemp == “1”){
digitalWrite(ledGPIO2, HIGH);
Serial.print(“On”);
}
else if(messageTemp == “false”);
else if(messageTemp == “0”)
{
digitalWrite(ledGPIO2, LOW);
Serial.print(“Off”);
}
}
Yes, I totally understand and I’ll update the course with that change in 1 or 2 weeks.
If you enter in the Node-RED fields the words “on” and “off“. Then, your code should look like this:
if(topic=="home/office/esp1/gpio2"){ Serial.print("Changing GPIO 2 to "); if(messageTemp == "on"){ digitalWrite(ledGPIO2, HIGH); Serial.print("On"); } else if(messageTemp == "off"){ digitalWrite(ledGPIO2, LOW); Serial.print("Off"); } }
Does that work for you? Thanks!
Rui,
This issue has reared it’s ugly head again. I have been working through the course again and ran into this issue. The last time I was able to add and if/else statement that would allow the choice of two variables (true or 1) (false or 0). However, it appears that the “mqtt_esp8266” example has been changed and I am not sure how this code can be changed to accept either value. Here is the current version:
// Switch on the LED if an 1 was received as first character
if ((char)payload[0] == ‘1’) {
digitalWrite(BUILTIN_LED, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is active low on the ESP-01)
} else {
digitalWrite(BUILTIN_LED, HIGH); // Turn the LED off by making the voltage HIGH
}
can you point me to some info that will allow me to tackle this?
Thanks
Rui,
I was able to get passed this issue even though I do not understand it fully. I do understand my error in making the entries in the payload of the switch node. I had to make sure the 1/0 was being entered as a number and not a string. So for now I am moving on to accomplish my goal with the “simple” push button remote for my sonoff devices.
I’m glad you were able to find a work around! Sorry about the trouble during this process.
Having same problem as the members above.
In the pdf file Rui mentions:
“Important:sometimes the switch nodekeeps the default values trueand falseafter you press Done. If your project isn’t working, double-check thatyour On Payloadand your Off Payloadfields are set to1and 0, respectively”
Is there a fix for this or a really good trick??. It’s really frustrating, tried like 10 times and it kept going back to true & false! Don’t know what I did but then it finally stayed. Argghh!!!
The original posted asked this 2 years ago. Still no fix????
Hello Robert.
I’m sorry to hear that! I honestly thought this issued was fixed by now, I didn’t realize there was people still having this error on Node-RED. Can you change the text on Node-RED nodes of the payload to the text “on” and “off”, instead of “1” and “0”.
Then, in the void callback() function change messageTemp comparisons to “on” and “off”:
if(messageTemp == "on"){
And off:
else if(messageTemp == "off"){
Thanks for your patience!
Thank you Rui. I just tried that and it works! Now I can go to the next module…
P.S. having a blast with this course! Best $25 I ever spent. 🙂
Most have tried this 100 times over several days. Finally got it to change from True and False to 1 and 0 by first changing to on and off, then deploying it with the error, then going back to edit the node to 1 and 0, redeploy and it stayed 1 and 0. No idea how or why but it works.