Search

Register

Thanks for signing-up! You will receive an email with further instructions to activate your account!

username already taken
You already have an account? .

Login

Forgot password?
Don't have an account yet? Register now for using the UI-Designer and the forum or creating projects.
Login to create topics and posts!



NodeRed and Arduino

#1 March 17, 2020 00:54:37 by meccip

NodeRed and Arduino

Hello,
First, I hope i find all of you well regarding the COVID19 problem !!

My question is about node red and arduino connection, it is not about netIO.

So, i have this code in arduino that communicate with netIO, my question is can I use this code with nodered to send and receive data like in netIO ?

Any info about this is welcome.
Thank you.

...........

void androidInterface() {
int index = 0; // reading the socket IF
char Remote[BUFSIZ];
EthernetClient clientApp = androidServer.available();
if (clientApp) {
if (clientApp.connected()) {
while (clientApp.available()) {
char c = clientApp.read();
if (c != '\n' && c != '\r') { // no linefeed or CR, so keep reading
Remote[index] = c;
index++;
if (index >= BUFSIZ)
index = BUFSIZ -1;
continue;
}
Remote[index] = 0;
}

if (strstr(Remote, "led1state")) {
if (LED_state[0]==0) { // send switch initialize back to NetIO APP
clientApp.println("led1stateoff");
}
if (LED_state[0]==1) { // send switch initialize back to NetIO APP
clientApp.println("led1stateon");
}
}
if (strstr(Remote, "led1on")) {
clientApp.println("OK");
LED_state[0]=1;
}
if (strstr(Remote, "led1off")) {
clientApp.println("OK");
LED_state[0]=0;
}

} // end of if clientApp.connected
} // end of if clientApp
} // end of android interface function

#2 March 19, 2020 01:39:15 by meccip

NodeRed and Arduino

I managed to turn on/off the LED with a simple node red switch and tcp request node. (send “led1on” when switch is pressed)
I got stuck with state reading.
How to get led state and write to switch node to know when it is on or off ?
Any ideas will be nice.

#3 May 4, 2020 18:10:12 by meccip

NodeRed and Arduino

I finished my project. For those who are interested, here is the code

Flow for NodeRed
[{"id":"41bbed4e.8d935c","type":"ui_text","z":"71f58a08.e79514","group":"4f257404.dafbec","order":6,"width":0,"height":0,"name":"Extra Charger State","label":"<font color={{msg.color}}>Extra Charger</font>","format":"<font color={{msg.color}}>{{msg.payload}}</font>","layout":"row-spread","x":1020,"y":200,"wires":[],"info":"**tre**"},{"id":"a41d62a8.409df","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":1190,"y":200,"wires":[]},{"id":"6acab53.6cb83cc","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.payload=='extraON')\n{\n  msg.color='white'\n  msg.payload='Charging'  \nreturn [msg,null,null,null,null,null];\n}\nif (msg.payload=='extraOFF')\n{\n  msg.color='#969696'\n  msg.payload='No Charging'  \nreturn [msg,null,null,null,null,null];\n}\n\nif (msg.payload=='onPower')\n{\n  msg.color='#f252d8'\n  msg.payload='on Power Line'  \nreturn [null,msg,null,null,null,null];\n}\nif (msg.payload=='onBattery')\n{\n  msg.color='#34f7b4'\n  msg.payload='on Battery'  \nreturn [null,msg,null,null,null,null];\n}\n\nif (msg.payload=='auto')\n{\n  msg.color='white'\n  msg.payload='AUTO'  \nreturn [null,null,msg,null,null,null];\n}\nif (msg.payload=='manual')\n{\n  msg.color='white'\n  msg.payload='Manual'  \nreturn [null,null,msg,null,null,null];\n}\n\nif (msg.payload=='line220vON')\n{\n  msg.color='#34f7b4'\n  msg.payload='Active'  \nreturn [null,null,null,msg,null,null];\n}\nif (msg.payload=='line220vOFF')\n{\n  msg.color='#f252d8'\n  msg.payload='Failure'  \nreturn [null,null,null,msg,null,null];\n}\n\nif (msg.payload=='low')\n{\n  msg.color='#f252d8'\n  msg.payload='Low'  \nreturn [null,null,null,null,msg,null];\n}\nif (msg.payload=='charged')\n{\n  msg.color='#34f7b4'\n  msg.payload='Charged'  \nreturn [null,null,null,null,msg,null];\n}\n\nif (msg.payload=='inv220vON')\n{\n  msg.color='#34f7b4'\n  msg.payload='Active'  \nreturn [null,null,null,null,null,msg];\n}\nif (msg.payload=='inv220vOFF')\n{\n  msg.color='#f252d8'\n  msg.payload='Failure'  \nreturn [null,null,null,null,null,msg];\n}\n","outputs":6,"noerr":0,"x":770,"y":460,"wires":[["a41d62a8.409df","41bbed4e.8d935c"],["14c2bd3e.636293","c3760980.9140c8"],["4b3a82eb.d8525c","4d80622b.dbc7ec"],["ab5358ab.c035d","57637079.3c01f"],["eb87c7a1.82a83","c6b8e029.95f068"],["3fe46a06.a3ca3e","52b6a726.5c2a5"]]},{"id":"14c2bd3e.636293","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":1190,"y":260,"wires":[]},{"id":"4b3a82eb.d8525c","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":1190,"y":320,"wires":[]},{"id":"c3760980.9140c8","type":"ui_text","z":"71f58a08.e79514","group":"4f257404.dafbec","order":9,"width":0,"height":0,"name":"Switch Transfer State","label":"<font color={{msg.color}}>Switch Transfer State</font>","format":"<font color={{msg.color}}>{{msg.payload}}</font>","layout":"row-spread","x":1020,"y":240,"wires":[],"info":"**tre**"},{"id":"3f3e69a1.3bbb6e","type":"ui_button","z":"71f58a08.e79514","name":"on/off","group":"4f257404.dafbec","order":11,"width":"0","height":"0","passthru":false,"label":"<span class=swtext>SW Trigger State</span><span class=swpayload>{{msg.text}}</span>","tooltip":"","color":"{{msg.color}}","bgcolor":"{{msg.background}}","icon":"","payload":"","payloadType":"str","topic":"button","x":1050,"y":320,"wires":[["291fe472.41319c"]],"info":"****"},{"id":"291fe472.41319c","type":"switch","z":"71f58a08.e79514","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"button","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":950,"y":360,"wires":[["d0cd60b9.03393"]]},{"id":"d0cd60b9.03393","type":"function","z":"71f58a08.e79514","name":"","func":"var obtaindata = global.get (\"switch\")\nif (obtaindata == \"AUTO\"){msg.payload = 'manual'}\nif (obtaindata == \"Manual\"){msg.payload = 'auto'}\nreturn msg;","outputs":1,"noerr":0,"x":1070,"y":360,"wires":[["829577e9.d44c68"]]},{"id":"19c0ae87.c3c2e9","type":"function","z":"71f58a08.e79514","name":"","func":"var obtaindata = global.get (\"switch\")\n\nif (obtaindata == \"AUTO\"){\n    msg.color = \"white\";\n    msg.background = \"#454545\";\n    msg.text = \"AUTO\";\n    return [msg,null];\n}\nif (obtaindata == \"Manual\"){\n    msg.color = \"#f252d8\";\n    msg.background = \"#454545\";\n    msg.text = \"Manual\";\n    return [null,msg];        \n}\n","outputs":2,"noerr":0,"x":930,"y":320,"wires":[["3f3e69a1.3bbb6e"],["3f3e69a1.3bbb6e"]]},{"id":"6469b24e.52784c","type":"ui_template","z":"71f58a08.e79514","group":"4f257404.dafbec","name":"Text Transform for buttons","order":15,"width":0,"height":0,"format":"<div ng-bind-html=\"msg.payload\"></div>\n<style>\nbutton{\n    text-transform: none !important;\n    padding: 0 17px 0 12px !important;\n    font-size: 16px;\n    }\n.swtext{\n float:left;\n}\n.swpayload{\n float:right;\n font-weight:bold;\n}\n</style>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"global","x":680,"y":40,"wires":[[]]},{"id":"4d80622b.dbc7ec","type":"change","z":"71f58a08.e79514","name":"global switch start","rules":[{"t":"set","p":"switch","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":970,"y":280,"wires":[["19c0ae87.c3c2e9"]]},{"id":"3fe46a06.a3ca3e","type":"ui_text","z":"71f58a08.e79514","group":"4f257404.dafbec","order":8,"width":0,"height":0,"name":"Inverter Power State","label":"<font color={{msg.color}}>Inverter Power Line State</font>","format":"<font color={{msg.color}}>{{msg.payload}}</font>","layout":"row-spread","x":1020,"y":440,"wires":[],"info":"**tre**"},{"id":"ab5358ab.c035d","type":"ui_text","z":"71f58a08.e79514","group":"4f257404.dafbec","order":7,"width":0,"height":0,"name":"Main Power State","label":"<font color={{msg.color}}>Main Power Line State</font>","format":"<font color={{msg.color}}>{{msg.payload}}</font>","layout":"row-spread","x":1010,"y":400,"wires":[],"info":"**tre**"},{"id":"57637079.3c01f","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":1190,"y":380,"wires":[]},{"id":"52b6a726.5c2a5","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":1190,"y":494,"wires":[]},{"id":"eb87c7a1.82a83","type":"ui_text","z":"71f58a08.e79514","group":"4f257404.dafbec","order":5,"width":0,"height":0,"name":"Device Voltage State","label":"<font color={{msg.color}}>Voltage State</font>","format":"<font color={{msg.color}}>{{msg.payload}}</font>","layout":"row-spread","x":1020,"y":482,"wires":[],"info":"**tre**"},{"id":"c6b8e029.95f068","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":1190,"y":434,"wires":[]},{"id":"4c56efda.3453b","type":"switch","z":"71f58a08.e79514","name":"Volt","property":"type","propertyType":"msg","rules":[{"t":"cont","v":"volt1","vt":"str"},{"t":"cont","v":"volt2","vt":"str"},{"t":"cont","v":"volt3","vt":"str"},{"t":"cont","v":"volt4","vt":"str"},{"t":"cont","v":"volt5","vt":"str"},{"t":"cont","v":"volt6","vt":"str"},{"t":"cont","v":"volt7","vt":"str"},{"t":"cont","v":"volt8","vt":"str"}],"checkall":"true","repair":false,"outputs":8,"x":753,"y":806,"wires":[["a45cf29b.a7c53","98fcdbf8.b90bd8"],["6cf1c475.ddf0b4","7ee4abc8.da3df4"],["79688362.b9fadc","19237d08.ba89db"],["c735af42.0fef28","518155c7.31fe8c"],["931709bb.efbe6","2f201ce9.a6422c"],["e2ac1e9e.872ad","94ad6729.5f63d"],["dad1bd92.cc056","d5d51a4a.25b048"],["ade6e58b.d589f8","ed313aac.134a58"]]},{"id":"df7a6f30.99da2","type":"function","z":"71f58a08.e79514","name":"split value","func":"var fields = msg.payload.trim().split(':');\nmsg.type     = fields[0];\nmsg.value    = parseFloat(fields[1]);\n\nreturn msg;","outputs":1,"noerr":0,"x":530,"y":860,"wires":[["4c56efda.3453b","437258fd.144358"]]},{"id":"a45cf29b.a7c53","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1200,"y":670,"wires":[]},{"id":"6cf1c475.ddf0b4","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1201.499984741211,"y":715.3332977294922,"wires":[]},{"id":"757a8adc.9d50a4","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1210,"y":1071,"wires":[]},{"id":"bbb88655.488ae","type":"inject","z":"71f58a08.e79514","name":"Bank Temp","topic":"","payload":"nodetemp","payloadType":"str","repeat":"10","crontab":"","once":true,"onceDelay":"","x":130,"y":220,"wires":[["829577e9.d44c68"]]},{"id":"f734db90.69fe1","type":"inject","z":"71f58a08.e79514","name":"Bank Voltage","topic":"","payload":"nodevolt","payloadType":"str","repeat":"3","crontab":"","once":true,"onceDelay":"","x":140,"y":180,"wires":[["829577e9.d44c68"]]},{"id":"f42f4c04.07384","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1210,"y":1119,"wires":[]},{"id":"bb933534.e1f55","type":"ui_text","z":"71f58a08.e79514","group":"43d94986.cc0ac8","order":1,"width":"2","height":"2","name":"Battery 1","label":"<font color={{msg.color}}>Battery 1</font>","format":"<font color={{msg.color}}>{{msg.value}} V</font>","layout":"col-center","x":1060,"y":671,"wires":[]},{"id":"aba3974b.7c1428","type":"ui_text","z":"71f58a08.e79514","group":"43d94986.cc0ac8","order":3,"width":"2","height":"1","name":"Temp 1","label":"","format":"<font color={{msg.color}}>{{msg.value}} °C</font>","layout":"row-center","x":1061.9999771118164,"y":1071.3333168029785,"wires":[]},{"id":"98fcdbf8.b90bd8","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='12.2' & msg.value<='14.8')\n{\n  msg.color='white'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":930,"y":671,"wires":[["bb933534.e1f55"]]},{"id":"56ee20e3.a8c81","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='3' & msg.value<='35')\n{\n  msg.color='yellow'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":931.9999771118164,"y":1071.3333168029785,"wires":[["aba3974b.7c1428"]]},{"id":"a12165ff.a9fcf","type":"ui_text","z":"71f58a08.e79514","group":"43d94986.cc0ac8","order":4,"width":"2","height":"1","name":"Humi 1","label":"","format":"<font color={{msg.color}}>{{msg.value}} %</font>","layout":"row-center","x":1061.9999771118164,"y":1118.3333168029785,"wires":[]},{"id":"7a2b720f.d4e954","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='20' & msg.value<='55')\n{\n  msg.color='#4eb4fc'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":931.9999771118164,"y":1118.3333168029785,"wires":[["a12165ff.a9fcf"]]},{"id":"7119ae32.2c6a18","type":"ui_text","z":"71f58a08.e79514","group":"43d94986.cc0ac8","order":2,"width":"2","height":"2","name":"Battery 2","label":"<font color={{msg.color}}>Battery 2</font>","format":"<font color={{msg.color}}>{{msg.value}} V</font>","layout":"col-center","x":1060,"y":715,"wires":[]},{"id":"7ee4abc8.da3df4","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='12.2' & msg.value<='14.8')\n{\n  msg.color='white'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":930,"y":715,"wires":[["7119ae32.2c6a18"]]},{"id":"437258fd.144358","type":"switch","z":"71f58a08.e79514","name":"Temp","property":"type","propertyType":"msg","rules":[{"t":"cont","v":"temp1","vt":"str"},{"t":"cont","v":"humi1","vt":"str"},{"t":"cont","v":"temp2","vt":"str"},{"t":"cont","v":"humi2","vt":"str"},{"t":"cont","v":"temp3","vt":"str"},{"t":"cont","v":"humi3","vt":"str"},{"t":"cont","v":"temp4","vt":"str"},{"t":"cont","v":"humi4","vt":"str"},{"t":"cont","v":"invtemp","vt":"str"},{"t":"cont","v":"invhumi","vt":"str"},{"t":"cont","v":"invfan","vt":"str"},{"t":"cont","v":"ctrltemp","vt":"str"},{"t":"cont","v":"ctrlhumi","vt":"str"},{"t":"cont","v":"ctrlfan","vt":"str"},{"t":"cont","v":"mq2","vt":"str"}],"checkall":"true","repair":false,"outputs":15,"x":753,"y":1229,"wires":[["56ee20e3.a8c81","757a8adc.9d50a4"],["7a2b720f.d4e954","f42f4c04.07384"],["8979306b.8399f","b96fabac.71e1e8"],["feca1c1d.4eeb8","8bcdd9d3.8cf03"],["658ed687.95f34","b1281c24.0cec68"],["8e98c083.76833","fe4dc838.dde25"],["b829e533.d892d","2ed30a2f.568576"],["909e716.9b4271","127313ae.a77204"],["6225675a.3455","c7b18e92.89fb1"],["efa5ce61.577108","7fc44b43.00599c"],["e4cc4ba5.7030b8","b4f747b1.f2c4"],["aa8e4421.b1d1f","3c0dd846.2b4c38"],["3cfaf143.2e4b26","8da3444e.78fb48"],["cd11268c.d2ea2","d3fe1923.1e2958"],["7ae952c9.fe6a34","2e939af3.dcc846"]]},{"id":"4f04e99b.1176c","type":"ui_text","z":"71f58a08.e79514","group":"43d94986.cc0ac8","order":5,"width":"2","height":"2","name":"Battery 3","label":"<font color={{msg.color}}>Battery 3</font>","format":"<font color={{msg.color}}>{{msg.value}} V</font>","layout":"col-center","x":1060,"y":762,"wires":[]},{"id":"8d5598cf.99477","type":"ui_text","z":"71f58a08.e79514","group":"43d94986.cc0ac8","order":7,"width":"2","height":"1","name":"Temp 2","label":"","format":"<font color={{msg.color}}>{{msg.value}} °C</font>","layout":"row-center","x":1062,"y":1166,"wires":[]},{"id":"79688362.b9fadc","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='12.2' & msg.value<='14.8')\n{\n  msg.color='white'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":930,"y":762,"wires":[["4f04e99b.1176c"]]},{"id":"8979306b.8399f","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='3' & msg.value<='35')\n{\n  msg.color='yellow'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":932,"y":1166,"wires":[["8d5598cf.99477"]]},{"id":"bf5fef28.aeba5","type":"ui_text","z":"71f58a08.e79514","group":"43d94986.cc0ac8","order":8,"width":"2","height":"1","name":"Humi 2","label":"","format":"<font color={{msg.color}}>{{msg.value}} %</font>","layout":"row-center","x":1062,"y":1212,"wires":[]},{"id":"feca1c1d.4eeb8","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='20' & msg.value<='55')\n{\n  msg.color='#4eb4fc'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":932,"y":1212,"wires":[["bf5fef28.aeba5"]]},{"id":"ada2ce89.336ce","type":"ui_text","z":"71f58a08.e79514","group":"43d94986.cc0ac8","order":6,"width":"2","height":"2","name":"Battery 4","label":"<font color={{msg.color}}>Battery 4</font>","format":"<font color={{msg.color}}>{{msg.value}} V</font>","layout":"col-center","x":1060,"y":809,"wires":[]},{"id":"c735af42.0fef28","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='12.2' & msg.value<='14.8')\n{\n  msg.color='white'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":930,"y":809,"wires":[["ada2ce89.336ce"]]},{"id":"19237d08.ba89db","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1203,"y":762,"wires":[]},{"id":"518155c7.31fe8c","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1205.499984741211,"y":808.3332977294922,"wires":[]},{"id":"b96fabac.71e1e8","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1209.0000228881836,"y":1165.6666831970215,"wires":[]},{"id":"8bcdd9d3.8cf03","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1209.0000228881836,"y":1211.6666831970215,"wires":[]},{"id":"2f201ce9.a6422c","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1202,"y":855,"wires":[]},{"id":"94ad6729.5f63d","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1202.499984741211,"y":901.3332977294922,"wires":[]},{"id":"b1281c24.0cec68","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1209,"y":1259,"wires":[]},{"id":"8e98c083.76833","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1210,"y":1307,"wires":[]},{"id":"eb8c3b48.542a48","type":"ui_text","z":"71f58a08.e79514","group":"43d94986.cc0ac8","order":9,"width":"2","height":"2","name":"Battery 5","label":"<font color={{msg.color}}>Battery 5</font>","format":"<font color={{msg.color}}>{{msg.value}} V</font>","layout":"col-center","x":1061,"y":857,"wires":[]},{"id":"1c02a463.2aed0c","type":"ui_text","z":"71f58a08.e79514","group":"43d94986.cc0ac8","order":11,"width":"2","height":"1","name":"Temp 3","label":"","format":"<font color={{msg.color}}>{{msg.value}} °C</font>","layout":"row-center","x":1061.9999771118164,"y":1260.3333168029785,"wires":[]},{"id":"931709bb.efbe6","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='12.2' & msg.value<='14.8')\n{\n  msg.color='white'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":931,"y":857,"wires":[["eb8c3b48.542a48"]]},{"id":"658ed687.95f34","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='3' & msg.value<='35')\n{\n  msg.color='yellow'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":931.9999771118164,"y":1260.3333168029785,"wires":[["1c02a463.2aed0c"]]},{"id":"3879f763.d3e87","type":"ui_text","z":"71f58a08.e79514","group":"43d94986.cc0ac8","order":12,"width":"2","height":"1","name":"Humi 3","label":"","format":"<font color={{msg.color}}>{{msg.value}} %</font>","layout":"row-center","x":1061.9999771118164,"y":1307.3333168029785,"wires":[]},{"id":"fe4dc838.dde25","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='20' & msg.value<='55')\n{\n  msg.color='#4eb4fc'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":931.9999771118164,"y":1307.3333168029785,"wires":[["3879f763.d3e87"]]},{"id":"14a06a9b.298f35","type":"ui_text","z":"71f58a08.e79514","group":"43d94986.cc0ac8","order":10,"width":"2","height":"2","name":"Battery 6","label":"<font color={{msg.color}}>Battery 6</font>","format":"<font color={{msg.color}}>{{msg.value}} V</font>","layout":"col-center","x":1061,"y":902,"wires":[]},{"id":"e2ac1e9e.872ad","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='12.2' & msg.value<='14.8')\n{\n  msg.color='white'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":931,"y":902,"wires":[["14a06a9b.298f35"]]},{"id":"c9ed6c9.9f5d89","type":"ui_text","z":"71f58a08.e79514","group":"43d94986.cc0ac8","order":13,"width":"2","height":"2","name":"Battery 7","label":"<font color={{msg.color}}>Battery 7</font>","format":"<font color={{msg.color}}>{{msg.value}} V</font>","layout":"col-center","x":1060,"y":949,"wires":[]},{"id":"c4cd1d40.294678","type":"ui_text","z":"71f58a08.e79514","group":"43d94986.cc0ac8","order":15,"width":"2","height":"1","name":"Temp 4","label":"","format":"<font color={{msg.color}}>{{msg.value}} °C</font>","layout":"row-center","x":1061.9999771118164,"y":1355.3333168029785,"wires":[]},{"id":"dad1bd92.cc056","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='12.2' & msg.value<='14.8')\n{\n  msg.color='white'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":930,"y":949,"wires":[["c9ed6c9.9f5d89"]]},{"id":"b829e533.d892d","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='3' & msg.value<='35')\n{\n  msg.color='yellow'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":931.9999771118164,"y":1355.3333168029785,"wires":[["c4cd1d40.294678"]]},{"id":"a4076dd7.c8661","type":"ui_text","z":"71f58a08.e79514","group":"43d94986.cc0ac8","order":16,"width":"2","height":"1","name":"Humi 4","label":"","format":"<font color={{msg.color}}>{{msg.value}} %</font>","layout":"row-center","x":1061.9999771118164,"y":1406.3333168029785,"wires":[]},{"id":"127313ae.a77204","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='20' & msg.value<='55')\n{\n  msg.color='#4eb4fc'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":931.9999771118164,"y":1406.3333168029785,"wires":[["a4076dd7.c8661"]]},{"id":"66b88d20.e74a6c","type":"ui_text","z":"71f58a08.e79514","group":"43d94986.cc0ac8","order":14,"width":"2","height":"2","name":"Battery 8","label":"<font color={{msg.color}}>Battery 8</font>","format":"<font color={{msg.color}}>{{msg.value}} V</font>","layout":"col-center","x":1060,"y":996,"wires":[]},{"id":"ade6e58b.d589f8","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='12.2' & msg.value<='14.8')\n{\n  msg.color='white'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":930,"y":996,"wires":[["66b88d20.e74a6c"]]},{"id":"d5d51a4a.25b048","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1204,"y":948,"wires":[]},{"id":"ed313aac.134a58","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1205.499984741211,"y":994.3332977294922,"wires":[]},{"id":"2ed30a2f.568576","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1210,"y":1355,"wires":[]},{"id":"909e716.9b4271","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1210,"y":1406,"wires":[]},{"id":"673a6333.a5ebc4","type":"template","z":"71f58a08.e79514","name":"\"CLIENT GOT:\" +","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload}}","x":450,"y":420,"wires":[["1b528f8f.047ad","7e643354.fc90a4"]]},{"id":"829577e9.d44c68","type":"template","z":"71f58a08.e79514","name":"+ newline","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload}}","x":420,"y":300,"wires":[["864e49d2.606a4","ba4acd5b.3b93e8"]]},{"id":"864e49d2.606a4","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":570,"y":280,"wires":[]},{"id":"1b528f8f.047ad","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":450,"y":500,"wires":[]},{"id":"7e643354.fc90a4","type":"yaml","z":"71f58a08.e79514","property":"payload","name":"","x":510,"y":460,"wires":[["9ac902a9.a772a8"]]},{"id":"9ac902a9.a772a8","type":"function","z":"71f58a08.e79514","name":"split array","func":"var outputMsgs = [];\nvar words = msg.payload.trim().split(\",\");\noutputMsgs.push({payload:words});\n\nreturn outputMsgs;","outputs":1,"noerr":0,"x":530,"y":780,"wires":[["a0320418.60d1f"]]},{"id":"a0320418.60d1f","type":"split","z":"71f58a08.e79514","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":530,"y":820,"wires":[["df7a6f30.99da2","6acab53.6cb83cc"]]},{"id":"ab305b22.1cd988","type":"inject","z":"71f58a08.e79514","name":"Devices","topic":"","payload":"nodedevice","payloadType":"str","repeat":"18","crontab":"","once":true,"onceDelay":"","x":120,"y":260,"wires":[["829577e9.d44c68"]]},{"id":"c7b18e92.89fb1","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1210,"y":1454,"wires":[]},{"id":"efa5ce61.577108","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1210,"y":1502,"wires":[]},{"id":"7f42c15f.c74678","type":"ui_text","z":"71f58a08.e79514","group":"4f257404.dafbec","order":2,"width":"0","height":"0","name":"Inverter T","label":"<font color={{msg.color}}>Temperature</font>","format":"<font color={{msg.color}}>{{msg.value}} °C</font>","layout":"row-spread","x":1061.9999771118164,"y":1454.3333168029785,"wires":[]},{"id":"6225675a.3455","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='3' & msg.value<='40')\n{\n  msg.color='yellow'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":931.9999771118164,"y":1454.3333168029785,"wires":[["7f42c15f.c74678"]]},{"id":"357261f6.260d76","type":"ui_text","z":"71f58a08.e79514","group":"4f257404.dafbec","order":3,"width":"0","height":"0","name":"Inverter H","label":"<font color={{msg.color}}>Humidity</font>","format":"<font color={{msg.color}}>{{msg.value}} %</font>","layout":"row-spread","x":1061.9999771118164,"y":1501.3333168029785,"wires":[]},{"id":"7fc44b43.00599c","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='20' & msg.value<='55')\n{\n  msg.color='#4eb4fc'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":931.9999771118164,"y":1501.3333168029785,"wires":[["357261f6.260d76"]]},{"id":"83a5fa1d.342ca8","type":"ui_text","z":"71f58a08.e79514","group":"4f257404.dafbec","order":4,"width":"0","height":"0","name":"Inv Fan","label":"<font color={{msg.color}}>Fan Speed</font>","format":"<font color={{msg.color}}>{{msg.value}} %</font>","layout":"row-spread","x":1062,"y":1548,"wires":[]},{"id":"e4cc4ba5.7030b8","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='12' & msg.value<='90')\n{\n  msg.color='white'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":932,"y":1548,"wires":[["83a5fa1d.342ca8"]]},{"id":"b4f747b1.f2c4","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1209.0000228881836,"y":1547.6666831970215,"wires":[]},{"id":"aa8e4421.b1d1f","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1209,"y":1595,"wires":[]},{"id":"8da3444e.78fb48","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1210,"y":1643,"wires":[]},{"id":"f10fdeed.4b6048","type":"ui_text","z":"71f58a08.e79514","d":true,"group":"43d94986.cc0ac8","order":11,"width":"2","height":"1","name":"Solar T","label":"","format":"<font color={{msg.color}}>{{msg.value}} °C</font>","layout":"row-center","x":1061.9999771118164,"y":1596.3333168029785,"wires":[]},{"id":"3c0dd846.2b4c38","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='3' & msg.value<='35')\n{\n  msg.color='yellow'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":931.9999771118164,"y":1596.3333168029785,"wires":[["f10fdeed.4b6048"]]},{"id":"53abab5c.c746ac","type":"ui_text","z":"71f58a08.e79514","group":"302927c6.465dc8","order":10,"width":"0","height":"0","name":"Solar H","label":"<font color={{msg.color}}>Humidity</font>","format":"<font color={{msg.color}}>{{msg.value}} %</font>","layout":"row-spread","x":1061.9999771118164,"y":1643.3333168029785,"wires":[]},{"id":"3cfaf143.2e4b26","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='20' & msg.value<='55')\n{\n  msg.color='#4eb4fc'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":931.9999771118164,"y":1643.3333168029785,"wires":[["53abab5c.c746ac"]]},{"id":"70195c36.aaa2a4","type":"ui_text","z":"71f58a08.e79514","group":"302927c6.465dc8","order":11,"width":"0","height":"0","name":"Solar Fan","label":"<font color={{msg.color}}>Fan Speed</font>","format":"<font color={{msg.color}}>{{msg.value}} %</font>","layout":"row-spread","x":1061.9999771118164,"y":1693.3333168029785,"wires":[]},{"id":"d3fe1923.1e2958","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='12' & msg.value<='90')\n{\n  msg.color='white'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":931.9999771118164,"y":1693.3333168029785,"wires":[["70195c36.aaa2a4"]]},{"id":"cd11268c.d2ea2","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1210,"y":1693,"wires":[]},{"id":"2e939af3.dcc846","type":"debug","z":"71f58a08.e79514","name":"u","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"value","targetType":"msg","x":1210,"y":1740,"wires":[]},{"id":"1e7497ab.eed5a","type":"ui_text","z":"71f58a08.e79514","group":"4f257404.dafbec","order":1,"width":"0","height":"0","name":"MQ2","label":"<font color={{msg.color}}>MQ2 Smoke Sensor</font>","format":"<font color={{msg.color}}>{{msg.value}} %</font>","layout":"row-spread","x":1051.9999771118164,"y":1739.3333168029785,"wires":[]},{"id":"7ae952c9.fe6a34","type":"function","z":"71f58a08.e79514","name":"","func":"if (msg.value>='70' & msg.value<='180')\n{\n  msg.color='#ff9a00'\n}\n\nelse \n{\n  msg.color='#f252d8'\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":931.9999771118164,"y":1739.3333168029785,"wires":[["1e7497ab.eed5a"]]},{"id":"ba4acd5b.3b93e8","type":"tcp request","z":"71f58a08.e79514","server":"192.168.1.126","port":"2567","out":"char","splitc":"\\n","name":"192.168.1.126","x":440,"y":360,"wires":[["673a6333.a5ebc4"]]},{"id":"4f257404.dafbec","type":"ui_group","z":"","name":"Device-Inverter","tab":"f26544c8.7c5da8","order":3,"disp":true,"width":"6","collapse":false},{"id":"43d94986.cc0ac8","type":"ui_group","z":"","name":"Battery Bank State","tab":"f26544c8.7c5da8","order":4,"disp":true,"width":"6","collapse":false},{"id":"302927c6.465dc8","type":"ui_group","z":"","name":"Solar MPPT Charger","tab":"f26544c8.7c5da8","order":1,"disp":true,"width":"6","collapse":false},{"id":"f26544c8.7c5da8","type":"ui_tab","z":"","name":"EPEver Dashboard","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

Code for Arduino
#include <Ethernet.h>
#define BUFSIZ 64
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xAA, 0xAA, 0xAA }; // MAC address from Ethernet shield sticker under board
IPAddress ip(192, 168, 1, 126); // IP address, may need to change depending on network
EthernetServer androidServer(2567); // set port number for android netIO

void setup(){
Serial.begin(9600); //for debugging purposes
androidServer.begin(); // start the server
}

void loop()
{
androidInterface(); // call function to read socket communication and set ports
}
// end main loop

//--- iPhone interface function
void androidInterface() {
int index = 0; // reading the socket IF
char Remote[BUFSIZ];
EthernetClient clientAppApp = androidServer.available();
if (clientAppApp) {
if (clientAppApp.connected()) {
while (clientAppApp.available()) {
char c = clientAppApp.read();
if (c != '\n' && c != '\r') { // no linefeed or CR, so keep reading
Remote[index] = c;
index++;
if (index >= BUFSIZ)
index = BUFSIZ -1;
continue;
}
Remote[index] = 0;
}

Serial.println(" ");
Serial.print("string recieved from android: ");
Serial.println(Remote);

// DHT22 & Voltage reading for Node Red
// (Bank Battery Voltage)
if (strstr(Remote, "nodevolt")) {
clientApp.print("volt1:");
clientApp.print(voltage1 - voltage2);
clientApp.print(",");
clientApp.print("volt2:");
clientApp.print(voltage2);
clientApp.print(",");
clientApp.print("volt3:");
clientApp.print(voltage3 - voltage4);
clientApp.print(",");
clientApp.print("volt4:");
clientApp.print(voltage4);
clientApp.print(",");
clientApp.print("volt5:");
clientApp.print(voltage5 - voltage6);
clientApp.print(",");
clientApp.print("volt6:");
clientApp.print(voltage6);
clientApp.print(",");
clientApp.print("volt7:");
clientApp.print(voltage7 - voltage8);
clientApp.print(",");
clientApp.print("volt8:");
clientApp.print(voltage8);
clientApp.print(",");
if (lowVoltage == true){clientApp.print("charged");}
if (lowVoltage == false){clientApp.print("low");}
clientApp.print(",");
if (digitalRead(invSwitch) == HIGH){clientApp.print("onBattery");}
if (digitalRead(lineSwitch) == HIGH){clientApp.print("onPower");}
clientApp.print(",");
if (triggerAutoState == true){clientApp.print("auto");}
if (triggerAutoState == false){clientApp.print("manual");}
clientApp.println();
}
// end (Bank Battery Voltage)

// (Bank Battery Temperature-Humidity)
if (strstr(Remote, "nodetemp")) {
float t1 = dht1.readTemperature();
float h1 = dht1.readHumidity();
float t2 = dht2.readTemperature();
float h2 = dht2.readHumidity();
float t3 = dht3.readTemperature();
float h3 = dht3.readHumidity();
float t4 = dht4.readTemperature();
float h4 = dht4.readHumidity();
float h5 = dht5.readHumidity();
float t6 = dht6.readTemperature();
float h6 = dht6.readHumidity();
clientApp.print("temp1:");
clientApp.print(t1);
clientApp.print(",");
clientApp.print("humi1:");
clientApp.print(h1);
clientApp.print(",");
clientApp.print("temp2:");
clientApp.print(t2);
clientApp.print(",");
clientApp.print("humi2:");
clientApp.print(h2);
clientApp.print(",");
clientApp.print("temp3:");
clientApp.print(t3);
clientApp.print(",");
clientApp.print("humi3:");
clientApp.print(h3);
clientApp.print(",");
clientApp.print("temp4:");
clientApp.print(t4);
clientApp.print(",");
clientApp.print("humi4:");
clientApp.print(h4);
clientApp.print(",");
clientApp.print("invtemp:");
clientApp.print(K1);
clientApp.print(",");
clientApp.print("invhumi:");
clientApp.print(h5);
clientApp.print(",");
clientApp.print("invfan:");
clientApp.print(faninvSpeed/255.*100);
clientApp.print(",");
clientApp.print("ctrltemp:");
clientApp.print(t6);
clientApp.print(",");
clientApp.print("ctrlhumi:");
clientApp.print(h6);
clientApp.print(",");
clientApp.print("ctrlfan:");
clientApp.print(fancontrollerSpeed/255.*100);
clientApp.print(",");
clientApp.print("mq2:");
clientApp.print(mq2solarVal);
clientApp.println();
}
// end (Bank Battery Temperature-Humidity-Devices State)
// (Devices State)
if (strstr(Remote, "nodedevice")) {
if (PVinPushnotify == true){clientApp.print("extraON");}
if (PVinPushnotify == false){clientApp.print("extraOFF");}
clientApp.print(",");
if (digitalRead(inv220v) == HIGH){clientApp.print("inv220vON");}
if (digitalRead(inv220v) == LOW){clientApp.print("inv220vOFF");}
clientApp.print(",");
if (digitalRead(line220v) == HIGH){clientApp.print("line220vON");}
if (digitalRead(line220v) == LOW){clientApp.print("line220vOFF");}
clientApp.println();
}
// end (Devices State)
// end DHT22 & Voltage reading for Node Red
} // end of if clientApp.connected
} // end of if clientApp
} // end of android interface function

Code for Arduino is just an exemple to understand how is working with nodeRed. You need to make some modifications in the code to upload in your board.

Edited meccip (May 4, 2020 18:33:40)