Initializing widgets from my Pi Pico W

I'm wondering if there is a way to initialize a switch or slider from the program on my Pi Pico W when it first runs. I tried sending a feed to them, but it made a race condition.

Thanks in advance.

MQTT?

Put a command into a thread and use the MQTT node to start a flow wto set the widgets when it receives a message.

You could use the contents of the message and a switch node to action only one widget if you want to.

Can you give me any more details? I'm new to this and have no idea how to do what you suggest.

Forgive me - I'm on an iPad and limited as to what I can access at the mo for examples :frowning:

For a general intro to MQTT have a look at http://www.steves-internet-guide.com/mqtt/ and his Configuring the Node-Red MQTT Publish and Subscribe Nodes

There is an intro to MQTT on the Pico at How to Send and Receive Data Using Raspberry Pi Pico W and MQTT (Updated) | Tom's Hardware

I've gone over both of those in great detail., but they don't seem to address initializing the widgets. I will look again.

They will not - without knowing what the widgets are its hard to give any advice on that - these really help to address the race condition by single threading the request.

A bit more detail (and flow) could help give more targeted advice.

I'm using the Switch and the Numeric Node. I don't see a way to set a default value. I also don't see a way to make them stop sending values. I keep getting the last topic and message over and over until I select a new one. I have a feeling that is what was causing the race condition. I would send a message to the switch or Numeric node and it would not stop sending even though my program only sent it once.

Make the mqtt topic storing the value be a retained topic and feed that into the switch. Code it so that it does not send the value out again to prevent a loop.

Right now I just send it once before the start of the while true: loop, so it should not be sent over and over. Looking at the HiveMQ feed, I didn't see it, so it seems to be at Node-Red. I'm not sure what to configure to clear that out after it gets it.

When I monitor the feed in HiveMQ I see it only sent once. If connect a MQTT input node to a debug, I only see it once. If I then also connect the same MQTT input to the switch the debug shows the message over and over. I don't get it.

Are you talking about a ui-switch in the node red dashboard? If so then set it to not pass messages through.

This is a dashboard switch. Not sure what a UI switch is. I'd post a picture, but I can't figure out how.

That is a ui-switch (or ui_switch if using the old dashboard). In either case disable message pass through.

Yes, that does initialize it in Node-Red, but the position on the dashboard does not show the proper possition. Any ideas how to fix that? After it is operated it works fine.

Copy to the clipboard and CTRL-V in the forum works for me, or there is an upload button
image

Make sure you have 'show state of input` selected.

That did it, thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.