Hello,
I am trying to split a payload from a TCP connection.
So, i send a request to my arduino with TCP and i receive this data
"s01on,a01off,s02on,a02off,s03on,a03off,s04off,a04off,slon,alon,suon,auoff,s05on,a05off,s06on,a06off,s07on,a07off,s08on,a08off,s09on,a09off,s10on,a10off,s11on,a11off,r01on,r02on,r03off,r04off,r05off,r06off,r07off,r08off,p01off,p02off,p03off,s12on,s13on,s14on,n01on,n02on,q1on,qa1off,q2on,qa2off,q3off,qa3off,q4on,qa4off"
After i receive this data, i need to split it into a single message
This is what i done so far but i only get the last message from the array.
function onPoll() {
console.log("Polling...");
tcp.send("req2");
sleep(1000);
var data = tcp.receive({timeout: 1000});
console.log("message received: " + data);
var lastResponse = data.trim().split(",").pop();
console.log("response: " + lastResponse);
switch (lastResponse) {
case "qa4off":
console.log("S01 is on");
break;
case "s01off":
console.log("S01 is off");
break;
}
}
This is my log
Polling...
connected
message received: s01on,a01off,s02on,a02off,s03on,a03off,s04off,a04off,slon,alon,suon,auoff,s05off,a05off,s06off,a06off,s07on,a07off,s08on,a08off,s09on,a09off,s10on,a10off,s11on,a11off,r01on,r02on,r03off,r04off,r05off,r06off,r07off,r08off,p01off,p02off,p03off,s12on,s13on,s14on,n01on,n02on,q1on,qa1off,q2on,qa2off,q3off,qa3off,q4on,qa4off
response: qa4off
S01 is on
disconnected
Can someone help me with this ?
Thank you.