You are not logged in.
Pages: 1
Topic closed
Hello friends from Czech republic,
Everything fine?
I'm after a while again active playing with REX (2.51)
Nice that there are now options with Node-RED.
But not everything works for me so far....
This works so far:
[{"id":"c98b7271.da55f","type":"tab","label":"Flow 1"},{"id":"8a5cbe6b.42b52","type":"function","z":"c98b7271.da55f","name":"filter1","func":"\n msg1 = {};\n msg2 = {};\n msg3 = {};\n\nvar array = msg.payload.split('}'),\n a = array[0], b = array[1], c = array[2];\n \n \n msg1.payload = a;\n \n \n msg2.payload = b;\n \n \n msg3.payload = c;\n \n \n return [msg1,msg2,msg3];\n","outputs":"3","noerr":0,"x":570,"y":180,"wires":[["2aa746d8.c609ba"],[],[]]},{"id":"2aa746d8.c609ba","type":"function","z":"c98b7271.da55f","name":"filter2","func":"\n msg1 = {};\n msg2 = {};\n msg3 = {};\n\nvar array = msg.payload.split(':'),\n a = array[0], b = array[1], c = array[2];\n \n \n msg1.payload = a;\n \n \n msg2.payload = b;\n \n \n msg3.payload = c;\n \n \n return [msg1,msg2,msg3];\n","outputs":"3","noerr":0,"x":710,"y":180,"wires":[[],["c8cf40ef.02522"],[]]},{"id":"6c4e7be.0049c84","type":"inject","z":"c98b7271.da55f","name":"Clock","topic":"","payload":"","payloadType":"date","repeat":"30","crontab":"","once":true,"x":250,"y":180,"wires":[["7f44a190.57deb","ac6d7235.62b87"]]},{"id":"7f44a190.57deb","type":"http request","z":"c98b7271.da55f","name":"GET temp","method":"GET","ret":"txt","url":"http://localhost:8008/api/data/priva_kachel_task/CMP1:u2?data&mime=application/json","tls":"","x":410,"y":180,"wires":[["8a5cbe6b.42b52"]]},{"id":"c8cf40ef.02522","type":"mqtt out","z":"c98b7271.da55f","name":"","topic":"geraniums/temp1","qos":"2","retain":"","broker":"e0bc6b61.f532b8","x":890,"y":180,"wires":[]},{"id":"1ae30473.3d418c","type":"function","z":"c98b7271.da55f","name":"filter1","func":"\n msg1 = {};\n msg2 = {};\n msg3 = {};\n\nvar array = msg.payload.split('}'),\n a = array[0], b = array[1], c = array[2];\n \n \n msg1.payload = a;\n \n \n msg2.payload = b;\n \n \n msg3.payload = c;\n \n \n return [msg1,msg2,msg3];\n","outputs":"3","noerr":0,"x":570,"y":240,"wires":[["9340e487.03db48"],[],[]]},{"id":"9340e487.03db48","type":"function","z":"c98b7271.da55f","name":"filter2","func":"\n msg1 = {};\n msg2 = {};\n msg3 = {};\n\nvar array = msg.payload.split(':'),\n a = array[0], b = array[1], c = array[2];\n \n \n msg1.payload = a;\n \n \n msg2.payload = b;\n \n \n msg3.payload = c;\n \n \n return [msg1,msg2,msg3];\n","outputs":"3","noerr":0,"x":710,"y":240,"wires":[[],["60adaeb4.251c7"],[]]},{"id":"ac6d7235.62b87","type":"http request","z":"c98b7271.da55f","name":"GET setpoint","method":"GET","ret":"txt","url":"http://localhost:8008/api/data/priva_kachel_task/CMP1:u1?data&mime=application/json","tls":"","x":410,"y":240,"wires":[["1ae30473.3d418c"]]},{"id":"60adaeb4.251c7","type":"mqtt out","z":"c98b7271.da55f","name":"","topic":"geraniums/setpoint1","qos":"2","retain":"","broker":"e0bc6b61.f532b8","x":900,"y":240,"wires":[]},{"id":"e0bc6b61.f532b8","type":"mqtt-broker","z":"c98b7271.da55f","broker":"IOT-SERVER","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]
Questions:
How do I get a value from a MQTT message to my REX program?
I've been messing with your weather example, but that does not work.
Can I write the value from Node-RED to a CNR in REX? How do you do that?
Offline
Hi Matthijs,
please try this example project on using REX, MQTT and Node-RED.
Here is the Node-RED flow:
[{"id":"f2578dac.25c0e","type":"mqtt in","z":"2b19612b.951df6","name":"","topic":"rex_topic","qos":"2","broker":"84ac4906.638e88","x":121,"y":448,"wires":[["1de5a67e.df27d2","af48283e.c47138"]]},{"id":"1de5a67e.df27d2","type":"function","z":"2b19612b.951df6","name":"Parse data","func":"return {\n payload: '{\"v\":' + msg.payload + '}',\n headers: {\n \"Content-type\" : \"application/json\"\n }\n};","outputs":1,"noerr":0,"x":309,"y":448,"wires":[["129ab107.989d5f","b5573783.3828a"]]},{"id":"129ab107.989d5f","type":"http request","z":"2b19612b.951df6","name":"POST data to REX API","method":"POST","ret":"obj","url":"http://localhost:8008/api/data/nodered_task/CNR_IN:ycn?data&mime=application/json","tls":"","x":539,"y":449,"wires":[["23305a8f.7feb16"]]},{"id":"b5573783.3828a","type":"debug","z":"2b19612b.951df6","name":"","active":true,"console":"false","complete":"false","x":523,"y":507,"wires":[]},{"id":"23305a8f.7feb16","type":"debug","z":"2b19612b.951df6","name":"","active":false,"console":"false","complete":"false","x":757,"y":449,"wires":[]},{"id":"af48283e.c47138","type":"debug","z":"2b19612b.951df6","name":"","active":false,"console":"false","complete":"false","x":308,"y":391,"wires":[]},{"id":"c433913e.24f92","type":"inject","z":"2b19612b.951df6","name":"","topic":"","payload":"","payloadType":"num","repeat":"5","crontab":"","once":false,"x":139,"y":173,"wires":[["32f2098b.2dd88e"]]},{"id":"32f2098b.2dd88e","type":"http request","z":"2b19612b.951df6","name":"GET data from REX API","method":"GET","ret":"txt","url":"http://localhost:8008/api/data/nodered_task/CNR_OUT:ycn?data&mime=application/json","tls":"","x":341,"y":173,"wires":[["cce75e18.ebc92","8a5159c3.c312e8"]]},{"id":"cce75e18.ebc92","type":"debug","z":"2b19612b.951df6","name":"","active":false,"console":"false","complete":"false","x":600,"y":100,"wires":[]},{"id":"4b4702c7.3fa2dc","type":"mqtt out","z":"2b19612b.951df6","name":"","topic":"rex_topic","qos":"","retain":"","broker":"84ac4906.638e88","x":831,"y":171,"wires":[]},{"id":"8a5159c3.c312e8","type":"function","z":"2b19612b.951df6","name":"Parse data","func":"return {\n payload: JSON.parse(msg.payload).v,\n headers: {\n \"Content-type\" : \"application/json\"\n }\n};","outputs":1,"noerr":0,"x":603,"y":171,"wires":[["4b4702c7.3fa2dc","f45a9395.9deb48"]]},{"id":"f45a9395.9deb48","type":"debug","z":"2b19612b.951df6","name":"","active":true,"console":"false","complete":"false","x":824,"y":237,"wires":[]},{"id":"84ac4906.638e88","type":"mqtt-broker","z":"","broker":"broker.hivemq.com","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]
After importing the flow to Node-RED, you just need to manually enable basic authentication in both HTTP GET and POST nodes and provide login and password for accessing the REX API (default is admin with blank password). It is also a good idea to rename the MQTT topic (rex_topic in the example).
Once you deploy the flow in Node-RED and download the algorithm to RexCore, the flow will read the CNR_OUT value using HTTP GET, extract the numeric value and push it to MQTT broker. It will also read the value from the MQTT topic back, wrap it with JSON formatting and write it to CNR_IN using HTTP POST. As a result, if you change the CNR_OUT value, it will appear at CNR_IN after 5 seconds (that's the refresh rate of the flow).
Rather complicated way to synchronize two variables but I hope it shows everything you need. Looking forward to your feedback!
Kind regards
Jaroslav
Monarco HAT for Raspberry Pi - Lightweight I/O for monitoring, archiving and control.
Raspberry Pi in industrial automation!
Offline
Hello Jaroslav,
Your solution works for me.
It was running for two weeks without problems!
Today, I had a failure, but I think it was a connection problem between the sensor and the WLAN.
The system log of the rexcore gave no problems and works fine.
Kind regards,
Matthijs
Offline
Hi Matthijs,
I'm glad it's working for you. Please keep us updated about your experience regarding the connection stability.
Kind regards,
Jaroslav
Monarco HAT for Raspberry Pi - Lightweight I/O for monitoring, archiving and control.
Raspberry Pi in industrial automation!
Offline
Hi Jaroslav,
It works so well. I do not need MQTT but i was struggling with the HTTP get to read a variable in my Rex program. Node-Red Modbus TCP is badly missing the FLOAT function.
Is there a way to read more than one variable at a time ?
All run well, logging in a SQlite database.
Nice Dashboard in node-red
Thanks a lot.
Benoit
Offline
Hi Benoit,
I'm glad it's working for you. Do you mean reading more variables from REX to Node-RED? And by "at a time" do you mean reading all variables in one HTTP request to REX REST API?
Kind regards,
Jaroslav
Monarco HAT for Raspberry Pi - Lightweight I/O for monitoring, archiving and control.
Raspberry Pi in industrial automation!
Offline
Hi Jaroslav,
Your second option Jaroslav. Of course an example with reading and writing many variable at a time to Rex from Node-Red will be very appreciated.
Thanks for your help.
Benoit
Offline
Hi Benoit,
try this example on reading vector data from REX to Node-RED. The README.md file should contain all the information you need. Let me know.
Best regards
Jaroslav
Monarco HAT for Raspberry Pi - Lightweight I/O for monitoring, archiving and control.
Raspberry Pi in industrial automation!
Offline
Pages: 1
Topic closed