No the data is from application that i developed which use built-in accelerometer sensor in smartphone to send data in real-time to MQTT,the average data send is about 3000 per minute
Sorry for late reply, i was restricted
No the data is from application that i developed which use built-in accelerometer sensor in smartphone to send data in real-time to MQTT,the average data send is about 3000 per minute
If you developed the app then do you not have control of the format? If instead of publishing the strings you posted, you published JSON strings, for example
{"X-AXIS": 0.153, "Y-AXIS": 0.114, "Z-AXIS": 9.807}
then in node-red you could tell the MQTT In node to interpret the string as JSON and it would automatically convert it to a javascript object for you, eliminating all the string manipulation in node-red.
since i am new im quite clueless to be honest,,,however the application is developed via MIT app inventor using code-block and sends as string so the data recieve as below
Are you not able to change the format of the string to be as I suggested?
You have the quotes in the wrong place, check my post more carefully.
Then set the MQTT In output field to Parsed JSON, feed it into a debug node and see what you get.
Is that after you have fixed the quotes, which you originally had in the wrong place as I posted a few minutes ago. If yes then set the output back to string and see what you get in the debug.
As I said in my post a few minutes ago, you still have the quotes in the wrong place. Go back and check my posts more carefully.
yes i notice it now i will fix it and try again, will post here the result
after fixing
in MQTT
in node red(using JSON string)
it works, but how do i split it into individual csv of X-axis Y-axis and Z-axis alongside time and date for each data
you would just need to remove the function node, the flow should then work as it was.
And what exactly is the JSONata expression? you need to supply more info
how do i send like this,
if im able to send like this it will be easier to check each parts
To export a flow highlight all the nodes (you can use shift or ctrl to highlight multipe) then press Ctrl e, and copy to clipboard.
Then when you post it press the </> button and paste flow json between the backticks
e.g.
```
code
```
[{"id":"fade33b0.31dc2","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"64915f5c.0a7238","type":"change","z":"fade33b0.31dc2","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"\t\"X-AXIS,\" & $$.payload.X-AXIS & $moment().tz(\"Asia/Tokyo\").format(\",DD/MM/YYYY,h:mm:ss a\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":280,"wires":[["55a1aba7.7cb53c","8258bfd2.d739a"]]},{"id":"85bcb7f0.7b1cc8","type":"change","z":"fade33b0.31dc2","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"\t\"Y-AXIS,\" & $$.payload.Y-AXIS & $moment().tz(\"Asia/Tokyo\").format(\",DD/MM/YYYY,h:mm:ss a\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":340,"wires":[["8258bfd2.d739a","a2609af6.5d05b"]]},{"id":"258a1d49.c7bce2","type":"change","z":"fade33b0.31dc2","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"\t\"Z-AXIS,\" & $$.payload.Z-AXIS & $moment().tz(\"Asia/Tokyo\").format(\",DD/MM/YYYY,h:mm:ss a\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":400,"wires":[["8258bfd2.d739a","90b1a43d.e74fa"]]},{"id":"b539e42d.73bd48","type":"ui_gauge","z":"fade33b0.31dc2","name":"","group":"8b5cde76.edd58","order":5,"width":0,"height":0,"gtype":"gage","title":"X-AXIS","label":"m/s2","format":"{{msg.payload[\"X-AXIS\"]}}","min":"-10","max":10,"colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":520,"y":520,"wires":[]},{"id":"70d60df4.60ab3c","type":"ui_gauge","z":"fade33b0.31dc2","name":"","group":"8b5cde76.edd58","order":5,"width":0,"height":0,"gtype":"gage","title":"Y-AXIS","label":"m/s2","format":"{{msg.payload[\"Y-AXIS\"]}}","min":"-10","max":10,"colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":520,"y":580,"wires":[]},{"id":"685e5157.f187b8","type":"ui_gauge","z":"fade33b0.31dc2","name":"","group":"8b5cde76.edd58","order":5,"width":0,"height":0,"gtype":"gage","title":"Z-AXIS","label":"m/s2","format":"{{msg.payload[\"Z-AXIS\"]}}","min":"-10","max":10,"colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":520,"y":640,"wires":[]},{"id":"8258bfd2.d739a","type":"debug","z":"fade33b0.31dc2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":220,"wires":[]},{"id":"55a1aba7.7cb53c","type":"file","z":"fade33b0.31dc2","name":"","filename":"C:\\Users\\User\\Desktop\\x-axis.csv","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"utf8","x":860,"y":280,"wires":[[]]},{"id":"a2609af6.5d05b","type":"file","z":"fade33b0.31dc2","name":"","filename":"C:\\Users\\User\\Desktop\\y-axis.csv","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"utf8","x":860,"y":340,"wires":[[]]},{"id":"90b1a43d.e74fa","type":"file","z":"fade33b0.31dc2","name":"","filename":"C:\\Users\\User\\Desktop\\z-axis.csv","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"utf8","x":860,"y":400,"wires":[[]]},{"id":"3124b708.80021","type":"mqtt in","z":"fade33b0.31dc2","name":"","topic":"SENSE","qos":"0","datatype":"json","broker":"277379c9.ca83a6","nl":false,"rap":true,"rh":0,"x":110,"y":500,"wires":[["64915f5c.0a7238","85bcb7f0.7b1cc8","258a1d49.c7bce2","b539e42d.73bd48","70d60df4.60ab3c","685e5157.f187b8"]]},{"id":"8b5cde76.edd58","type":"ui_group","name":"","tab":"8f03e639.85956","order":1,"disp":true,"width":"12","collapse":false},{"id":"277379c9.ca83a6","type":"mqtt-broker","name":"","broker":"broker.hivemq.com","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"8f03e639.85956","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]
Ok the issue is when you edited the expression you put
"X-AXIS," & $$.payload.X-AXIS & $moment().tz("Asia/Bangkok").format(",DD/MM/YYYY,h:mm:ss a")
while it should be
"X-AXIS," & $$.payload.`X-AXIS` & $moment().tz("Asia/Bangkok").format(",DD/MM/YYYY,h:mm:ss a")
notice the backticks around `X-AXIS` that is needed otherwise -
would be taken as a minus character and JSONata tries to preform a calculation with the strings either side. This causes the error
[edit] the issue was cause by the forum rendering of the code i posted as it contained `. I have corrected the post so others will not be caught out