I want to send a string as an MQTT message. However I struggle when trying to set up a text field that is deployed as soon as a button is pressed.
I have a stepper motor connected to an Arduino Wifi. In node-red I want to set up a control panel with two buttons (Forward and Backward) and a textfield that takes the number of steps the stepper motor should travel.
My issue is firstly how to get the value of the text field being put into a string like "forward:4000".
I.e. Forward-button was pressed with 4000 written into the text field.
Secondly, there seems very limited ways of when the output of the "text input" node is sent, i.e. "Send value on focus leave" which doesn't work as expcected, "When changed, send" which is definitely to often as I don't want to sent a message before I have finished writing the value, "If msg arrives on input, pass through to output" that doesn't make any sence to my as the text of the text field can't be added (at least I haven't found out how...)
You may could help me of how to establish a solution for my problem?
Welcome to the forum @radioman85
The simplest way to solve this is to feed the text node into a Change node configured to store the latest value in a flow context value. Then feed the button into a Change node that picks that value up (or pick it up in a Function node if you are already using one to build the control message).
Thank you for replying so fast. I somehow don't get it as I beleive it should be a very simple task to read out a text field on button event. May I'm little to cosseted by .NET.
I.e. something as simple as
void buttonForward_Click(object sender, EventArgs e)
// Get the text from the text field
string text = txtNumber.Text;
mqttSend(topic, "Forware:" + text);
However, how can I configure a change node to make it store values? As I have Set, Change, Delete and Move. Not one of them make me beleive to "store" anything?
Use Set, then one the options for set is flow context. I am on my phone so can't post an example. Also search for
Node red working with context
For more info from the docs.
Also I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.
Select the flow in the set dropdown
delay option in the properties of the
text input node.
Setting this value the node sends changes only when the delay period has passed ... after the last key stroke.
Thank you all for your inputs. I'll run through it and try to get it running.
It isn't that you are less cosseted in node red, just differently.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.