Seite 1 von 1
How to use node-red to turn off an LED
Verfasst: 22 Sep 2023, 19:51
von zhengtzer
Hi
i know how to publish a switch status through mqtt and display on node-red dashboard

- node-red.png (46.04 KiB) 3811 mal betrachtet
but now i am stuck on the other way around, how can i turn off an LED through subcribe?

- subcribe.png (27.47 KiB) 3811 mal betrachtet
thanks
Jonathan
Re: How to use node-red to turn off an LED
Verfasst: 22 Sep 2023, 22:18
von rugee-f
You can write a python prog where your incomming MQTT messages affect the TXT 4 IO (similar like you tried in RoboProCoding - I did this in plain python code...)
But the easier way to handle the IO of the TXT4 direct from Node-Red is to use the TXT4 API with HTTP requests.
With that you do not need a Python software layer to use the IO.

Re: How to use node-red to turn off an LED
Verfasst: 23 Sep 2023, 16:19
von zhengtzer
Hi
"But the easier way to handle the IO of the TXT4 direct from Node-Red is to use the TXT4 API with HTTP requests.
With that you do not need a Python software layer to use the IO."
thanks for guiding me, and i tried to figure out whole day, now txt4.0 can receive the message, but the LED just cant be turn off
can you help me to look through and see which part had i do wrongly?tyty
my RPC

- subcribePayload.png (213.67 KiB) 3692 mal betrachtet
my flow

- node-red.png (125.2 KiB) 3692 mal betrachtet
my dashboard, know how to "control" the LED on dashboard only

- nodeRedDashboard.png (42.19 KiB) 3692 mal betrachtet
thanks
Jonathan
Re: How to use node-red to turn off an LED
Verfasst: 23 Sep 2023, 22:01
von rugee-f
I do not often use Blockly - with that I could not help you much.
I am using plain Python code - there I initialized my TXT4 IO as lamp (PWM) outputs and declared MQTT topics for the PWM setpoints.

- declare_1.png (93.97 KiB) 3670 mal betrachtet
With incoming MQTT message on the setpoint topic I wrote the setpoint value to the TXT output.
0 for LED OFF and 255 for LED ON.

- declare_2.png (84.14 KiB) 3670 mal betrachtet