For the sketch provided with this lesson, I had to set node-red ui_switch on value to “1” rather than the “On” value given in the course text. Also set “Off” value to “0”. When configured as described in lesson built in led would light on boot and switch in node-red-ui indicated On, moving switch to Off switched led off, but even though switch activity was logged “On” or “Off” in serial output stream led would not switch back on again until reboot. I would like to understand where this difference in terms comes into effect. Is it in the Arduino compiler, the ESP8266 firmware, the node-red script, or the mqtt server? Can these terms (On for True, Off for False, etc.) be flexible or interchangeable? Must they match across the whole process from source code to the transistor that turns the pin on or off? I really want to learn coding but little frustrating glitches like this make me realize how much there is to learn. Discouragement often results from a lack of understanding simple details usually taken for granted.
Hi Scot,
This is a great question. I totally can see why it seems a bit confusing.
The commands True/1 or False/0 can often be used interchangeably. With Node-RED, if you write 1 it understands as a True.
The “On” or “Off” strings have no meaning for the programming side of things. You could write anything, for example “TurnOn” or “TurnOff”. The LEDs would only turn on, if you had a condition that verified those exact strings.
The best thing is to make everything match both in the ESP8266 code and in the Node-RED side to ensure that everything will work as expected. I recommend that you use 1 and 0 from now on.
I’ll update the image in the course to use 1’s and 0’s in the Node-RED node.
Thank you for bringing this up and I apologize for the poor job clarifying that subject in the course,
Rui