Help needed for errors and behaviour not understood

I have this node:

[{"id":"6a0bb249.a7d50c","type":"serial in","z":"2788693.17e8d16","name":"","serial":"9939954d.414a","x":75,"y":110.00000762939453,"wires":[["ecfc3405.1f6968"]]},{"id":"e4698ad2.53ac","type":"debug","z":"2788693.17e8d16","name":"","active":true,"console":"true","complete":"payload","x":482.8333740234375,"y":459.5,"wires":[]},{"id":"ecfc3405.1f6968","type":"switch","z":"2788693.17e8d16","name":"redirection payload ","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"<","vt":"str"},{"t":"eq","v":"t","vt":"str"},{"t":"eq","v":"a","vt":"str"}],"checkall":"false","outputs":3,"x":116.83335876464844,"y":445.3333740234375,"wires":[["bf9d5354.71114"],[],[]]},{"id":"bf9d5354.71114","type":"function","z":"2788693.17e8d16","name":"","func":"var outputMsgs = [];\nvar myVars = msg.payload.split(\"\\t\");\nfor(var w in myVars){\n//    outputMsgs.push({payload:myVars[w]});\n    outputMsgs.push({payload:myVars[w]});\n    \n}\noutputMsgs.shift(); //  remove 1st element of the array\noutputMsgs.pop();   //  remove last element \\r\\n\n\noutputMsgs[0].topic = \"now\";    //  affectation d'1 topic pour le graph\noutputMsgs[1].topic = \"timer\";\noutputMsgs[2].topic = \"T_amb\";\noutputMsgs[3].topic = \"Tc_K\";\noutputMsgs[4].topic = \"Consigne\";\noutputMsgs[5].topic = \"Feedback\";\noutputMsgs[6].topic = \"flag_capteur\";\noutputMsgs[7].topic = \"Pyro\";\noutputMsgs[8].topic = \"output_dac\";\noutputMsgs[9].topic = \"adc1_V_retour_MCP_DAC\";\noutputMsgs[10].topic = \"ERR\";\nvar A = Math.round(outputMsgs[5].payload - outputMsgs[4].payload);\noutputMsgs.push({payload:A});\noutputMsgs[11].topic = \"Consigne/feedback\";\noutputMsgs.topic = \"global\"\nreturn [outputMsgs[0], outputMsgs[1], outputMsgs[2], outputMsgs[3], outputMsgs[4], outputMsgs[5], outputMsgs[6], outputMsgs[7], outputMsgs[8], outputMsgs[9], outputMsgs[10], outputMsgs[11], outputMsgs];\n","outputs":"13","noerr":0,"x":125,"y":270.6666564941406,"wires":[["a44ed837.15356","f306d8fd.9f86a8"],["cca205b3.9695c8"],["4cc145ad.c22da4"],["754ba1ba.aa2c1"],["74bdf184.6d8c98","f306d8fd.9f86a8"],["f3f0ec03.a68238","f306d8fd.9f86a8"],["30e453be.caab14"],["f35d6ee6.332888","f306d8fd.9f86a8"],["375ce9d6.08b3a6","f306d8fd.9f86a8"],["134e68f2.4ed237"],["125231d4.d2ca06"],["ed091a4d.79f85"],["e4698ad2.53ac","9ee95d09.e23f68"]],"outputLabels":["now","timer","internal_C","température_Tc_K","Consigne","feedback","flag_pyro","température_pyro","output","adc1_sortie_MCP4725","","",""]},{"id":"754ba1ba.aa2c1","type":"ui_gauge","z":"2788693.17e8d16","name":"","group":"52880442.6f8dfc","order":2,"width":0,"height":0,"gtype":"gage","title":"Thermocouple","label":"°C","format":"{{value}}","min":0,"max":"1200","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":520.8333740234375,"y":210.00001525878906,"wires":[]},{"id":"a44ed837.15356","type":"ui_text","z":"2788693.17e8d16","group":"1708d647.04db7a","order":3,"width":0,"height":0,"name":"","label":"Secondes écoulées","format":"{{msg.payload}}","layout":"col-center","x":424.16668701171875,"y":83.16666412353516,"wires":[]},{"id":"cca205b3.9695c8","type":"ui_text","z":"2788693.17e8d16","group":"1708d647.04db7a","order":5,"width":0,"height":0,"name":"","label":"Timer","format":"{{msg.payload}}","layout":"col-center","x":466.16668701171875,"y":151.1666717529297,"wires":[]},{"id":"4cc145ad.c22da4","type":"ui_text","z":"2788693.17e8d16","group":"1708d647.04db7a","order":6,"width":0,"height":0,"name":"Tamb","label":"T_amb","format":"{{msg.payload}}","layout":"col-center","x":355.16668701171875,"y":200.1666717529297,"wires":[]},{"id":"74bdf184.6d8c98","type":"ui_gauge","z":"2788693.17e8d16","name":"","group":"12a6957e.88ac3b","order":1,"width":0,"height":0,"gtype":"gage","title":"Consigne","label":"C°","format":"{{value}}","min":0,"max":"1050","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":352.16668701171875,"y":242.83331298828125,"wires":[]},{"id":"f3f0ec03.a68238","type":"ui_gauge","z":"2788693.17e8d16","name":"","group":"a0898c66.f0283","order":2,"width":0,"height":0,"gtype":"gage","title":"feedback","label":"°C","format":"{{value}}","min":0,"max":"1200","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":502.16668701171875,"y":258.83331298828125,"wires":[]},{"id":"f35d6ee6.332888","type":"ui_gauge","z":"2788693.17e8d16","name":"","group":"d518e72d.e17d78","order":1,"width":0,"height":0,"gtype":"gage","title":"Pyromètre","label":"°C","format":"{{value}}","min":"250","max":"1200","colors":["#00acb5","#00b500","#ca3838"],"seg1":"1000","seg2":"1100","x":510.16668701171875,"y":317.83331298828125,"wires":[]},{"id":"375ce9d6.08b3a6","type":"ui_gauge","z":"2788693.17e8d16","name":"","group":"d183329a.5b0ba8","order":1,"width":0,"height":0,"gtype":"gage","title":"output_MCP4725_digit","label":"bit","format":"{{value}}","min":0,"max":"4095","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":688.1666564941406,"y":346.83331298828125,"wires":[]},{"id":"cd49d46.7b81d28","type":"ui_text","z":"2788693.17e8d16","group":"1708d647.04db7a","order":4,"width":0,"height":0,"name":"","label":"Capteur en usage","format":"{{msg.payload}}","layout":"col-center","x":686.8333435058594,"y":288.3333740234375,"wires":[]},{"id":"f306d8fd.9f86a8","type":"ui_chart","z":"2788693.17e8d16","name":"","group":"959ffa36.2e3e78","order":0,"width":0,"height":0,"label":"chart","chartType":"line","legend":"false","xformat":"mm:ss","interpolate":"linear","nodata":"","dot":true,"ymin":"","ymax":"","removeOlder":"5","removeOlderPoints":"","removeOlderUnit":"60","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":336.8333740234375,"y":476.73333740234375,"wires":[[],[]]},{"id":"134e68f2.4ed237","type":"ui_gauge","z":"2788693.17e8d16","name":"","group":"d183329a.5b0ba8","order":2,"width":0,"height":0,"gtype":"gage","title":"V_dac_MCP","label":"V","format":"{{value}}","min":0,"max":"5","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":458.0832824707031,"y":352.75,"wires":[]},{"id":"64914e7.d6aadb","type":"function","z":"2788693.17e8d16","name":"","func":"var outputMsgs = [];\nvar myVars = msg.payload.split(\"\\t\");\nfor(var w in myVars){\n//    outputMsgs.push({payload:myVars[w]});\n    outputMsgs.push({payload:myVars[w]});\n    \n}\noutputMsgs.shift(); //  remove 1st element of the array\noutputMsgs.pop();   //  remove last element \\r\\n\n\noutputMsgs[0].topic = \"now\";\noutputMsgs[1].topic = \"timer\";\noutputMsgs[2].topic = \"T_amb\";\noutputMsgs[3].topic = \"Tc_K\";\noutputMsgs[4].topic = \"Consigne\";\noutputMsgs[5].topic = \"Feedback\";\noutputMsgs[6].topic = \"flag_capteur\";\noutputMsgs[7].topic = \"Pyro\";\noutputMsgs[8].topic = \"output_dac\";\noutputMsgs[9].topic = \"adc1_V_retour_MCP_DAC\";\n//outputMsgs\n\nreturn [outputMsgs[0], outputMsgs[1], outputMsgs[2], outputMsgs[3], outputMsgs[4], outputMsgs[5], outputMsgs[6], outputMsgs[7], outputMsgs[8], outputMsgs[9]];\n","outputs":"10","noerr":0,"x":191.88333129882812,"y":551.88330078125,"wires":[[],[],[],[],[],[],[],[],[],[]],"outputLabels":["now","timer","internal_C","température_Tc_K","Consigne","feedback","flag_pyro","température_pyro","output","adc1_sortie_MCP4725"]},{"id":"30e453be.caab14","type":"function","z":"2788693.17e8d16","name":"Tc_K ON / Pyrometre ON","func":"if (msg.payload == 0){\n    msg.payload = \"Tc_K ON\";\n} else if(msg.payload == 1){\n    msg.payload = \"Pyrometre ON\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":437.5666809082031,"y":285.48333740234375,"wires":[["cd49d46.7b81d28"]]},{"id":"d919a6de.786358","type":"function","z":"2788693.17e8d16","name":"","func":"var outputMsgs = [];\nvar myVars = msg.payload.split(\"\\t\");\nfor(var w in myVars){\n//    outputMsgs.push({payload:myVars[w]});\n    outputMsgs.push({payload:myVars[w]});\n    \n}\noutputMsgs.shift(); //  remove 1st element of the array\noutputMsgs.pop();   //  remove last element \\r\\n\n\n/*outputMsgs[0].topic = \"now\";\noutputMsgs[1].topic = \"timer\";\noutputMsgs[2].topic = \"T_amb\";\noutputMsgs[3].topic = \"Tc_K\";\noutputMsgs[4].topic = \"Consigne\";\noutputMsgs[5].topic = \"Feedback\";\noutputMsgs[6].topic = \"flag_capteur\";\noutputMsgs[7].topic = \"Pyro\";\noutputMsgs[8].topic = \"output_dac\";\noutputMsgs[9].topic = \"adc1_V_retour_MCP_DAC\";\n*///outputMsgs\n\nreturn [outputMsgs[0], outputMsgs[1], outputMsgs[2], outputMsgs[3], outputMsgs[4], outputMsgs[5], outputMsgs[6], outputMsgs[7], outputMsgs[8], outputMsgs[9], outputMsgs];\n","outputs":"11","noerr":0,"x":393.8833312988281,"y":577.88330078125,"wires":[[],[],[],[],[],[],[],[],[],[],[]],"outputLabels":["now","timer","internal_C","température_Tc_K","Consigne","feedback","flag_pyro","température_pyro","output","adc1_sortie_MCP4725",""]},{"id":"ed091a4d.79f85","type":"ui_gauge","z":"2788693.17e8d16","name":"","group":"1708d647.04db7a","order":7,"width":0,"height":0,"gtype":"gage","title":"Consigne / feedback","label":"°C","format":"{{value}}","min":"-100","max":"100","colors":["#0073b5","#00b500","#ca3838"],"seg1":"-20","seg2":"20","x":477.5666809082031,"y":412.95001220703125,"wires":[]},{"id":"125231d4.d2ca06","type":"ui_text","z":"2788693.17e8d16","group":"1708d647.04db7a","order":0,"width":0,"height":0,"name":"","label":"Errors","format":"{{msg.payload}}","layout":"row-spread","x":460.5666809082031,"y":384.3833312988281,"wires":[]},{"id":"9ee95d09.e23f68","type":"file","z":"2788693.17e8d16","name":"","filename":"/home/harold/arduinoDataloggerToFile/arduino_dataloggerToFile","appendNewline":true,"createDir":false,"overwriteFile":"false","x":787.5,"y":695,"wires":[]},{"id":"9939954d.414a","type":"serial-port","z":"","serialport":"/dev/ttyUSB0","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","newline":"\\n","bin":"false","out":"char","addchar":false},{"id":"52880442.6f8dfc","type":"ui_group","z":"","name":"Group 2","tab":"bdf79f7a.36f0a8","order":2,"disp":true,"width":"6","collapse":true},{"id":"1708d647.04db7a","type":"ui_group","z":"","name":"Group 1","tab":"bdf79f7a.36f0a8","order":1,"disp":true,"width":"6","collapse":false},{"id":"12a6957e.88ac3b","type":"ui_group","z":"","name":"Group 3","tab":"bdf79f7a.36f0a8","order":3,"disp":true,"width":"6","collapse":false},{"id":"a0898c66.f0283","type":"ui_group","z":"","name":"Group 4","tab":"bdf79f7a.36f0a8","order":4,"disp":true,"width":"6","collapse":false},{"id":"d518e72d.e17d78","type":"ui_group","name":"Group 5","tab":"bdf79f7a.36f0a8","order":5,"disp":true,"width":6},{"id":"d183329a.5b0ba8","type":"ui_group","z":"","name":"Debug","tab":"bdf79f7a.36f0a8","order":6,"disp":true,"width":"6","collapse":true},{"id":"959ffa36.2e3e78","type":"ui_group","z":"","name":"Default","tab":"31bd863e.f5000a","disp":true,"width":"22","collapse":false},{"id":"bdf79f7a.36f0a8","type":"ui_tab","z":"","name":"Curing","icon":"dashboard"},{"id":"31bd863e.f5000a","type":"ui_tab","z":"","name":"Graph","icon":"dashboard","order":3}]

On the arduino I’m sending through serial the following:

Serial.print("<\t");
      Serial.print(now);
      Serial.print("\t");
      Serial.print(timer);
      Serial.print("\t");
      Serial.print(temperatures.internal_C);
      Serial.print("\t");
      Serial.print(temperatures.Tc_K);
      Serial.print("\t");
      Serial.print(setpoint);
      Serial.print("\t");
      Serial.print(input);
      Serial.print("\t");
      Serial.print(temperatures.flag_pyro);
      Serial.print("\t");
      Serial.print(temperatures.T_pyro);
      Serial.print("\t");
      Serial.print(sortie_MCP); //  0<MCP4725<4095
      Serial.print("\t");
      Serial.print(temperatures.adc1_Voltage);
      Serial.print("\t");
      Serial.print(temperatures.nb_of_errors);
      Serial.println("\t");

I can see my value till “output_MCP4725_digit” on the dashboard different gauges, but none following that value ! “V_dac_MCP” and “Errors” plus the last value which is calculated in the function node itself “Consigne / feedback”
plus I have some error that I don’t know how to deal with !

[error] [function:bf9d5354.71114] TypeError: Cannot set property 'topic' of undefined

This “tab-separated-value” string of output could be able turned into an object with named fields by passing it through the csv node, set to use a “tab” delimiter – assuming you are not getting any stray characters coming through the serial comm link.

Since the order of data fields is fixed by the arduino code, just put the matching fields names as the headers in the csv node’s configuration – and avoid those coding issues.

1 Like

yes agreed - not sure why the <\t is need to start with (or at the end)… or why there are a couple of println in there - rather than just one at the end… but yes the CSV node would be my choice to create the necessary object from this.

(well the extra println would cause the string to terminate so the serial node will hen end up to that point - which would then be without the last values)

@dceejay : The <\t is needed at the start to recognise the data to be taken into account as there are some other Serial.print() from the arduino sometimes !
Yes you’re right about the couple of println. I modified it.

Should I do something like this ?

[{"id":"9babb748.13192","type":"serial in","z":"5be7c8bb.14ff5","name":"","serial":"9939954d.414a","x":92,"y":167,"wires":[["d9d0c80e.9d1f28"]]},{"id":"d9d0c80e.9d1f28","type":"switch","z":"5be7c8bb.14ff5","name":"redirection payload ","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"<","vt":"str"},{"t":"eq","v":"t","vt":"str"},{"t":"eq","v":"a","vt":"str"}],"checkall":"false","outputs":3,"x":299.8333740234375,"y":165.3333740234375,"wires":[["97755f7e.f1ba6"],[],[]]},{"id":"97755f7e.f1ba6","type":"csv","z":"5be7c8bb.14ff5","name":"","sep":"\\t","hdrin":true,"hdrout":true,"multi":"one","ret":"\\n","temp":"now, timer, T_amb, Tc_K, Consigne, Feedback,  flag_capteur, Pyro, output_dac, adc1_V, Err,  Consigne/feedback","x":497.5,"y":153,"wires":[[]]},{"id":"9939954d.414a","type":"serial-port","z":"","serialport":"/dev/ttyUSB0","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","newline":"\\n","bin":"false","out":"char","addchar":false}]

but what to do from the csv node to send the data to my dashboard ?

mistake, reply removed !

well you should be able to just set the required property in the gauge etc {{msg.payload.T_amb}} etc

Thank you very much indeed !
I figured out how to set my data on the dashboard.

It’s much easier with the CSV node, even for debugging !
Great Thanks again !

Sorry for the disturbance. Just the fact of asking my question gave me some new ideas to solve my problem !
The following message has no more object.

One more question about storing the data in a file using FILE node.
After the CSV node it gives one line for each message with a lot of couple “value_name” : value.

{"none":"<","now":355762,"timer":1054,"T_amb":28.44,"Tc_K":173.5,"Consigne":211.44,"Feedback":173.5,"flag_capteur":0,"Pyro":248.93,"output_dac":1897,"adc1_V":2.33,"Err":0}
{"none":"<","now":356786,"timer":1024,"T_amb":28.44,"Tc_K":175.75,"Consigne":211.85,"Feedback":175.75,"flag_capteur":0,"Pyro":248.75,"output_dac":1805,"adc1_V":2.22,"Err":0}
{"none":"<","now":357839,"timer":1053,"T_amb":28.44,"Tc_K":177.25,"Consigne":212.27,"Feedback":177.25,"flag_capteur":0,"Pyro":248.75,"output_dac":1751,"adc1_V":2.14,"Err":0}
{"none":"<","now":358863,"timer":1024,"T_amb":28.44,"Tc_K":177,"Consigne":212.68,"Feedback":177,"flag_capteur":0,"Pyro":248.89,"output_dac":1784,"adc1_V":2.16,"Err":0}

How could I store these data in a file in a nicer way : Let say, the name of the values on a first line, then below, its own value for each messages received, one column for each value. Or maybe an even better proposition ?

depending on what you want it for, why not store the data in a database?

Well, I 've been once exploring that solution but it seems to be a big stuff for so small data !
Plus, when stored in database, you need to know what you’re doing to retrieve your data from database !
But if you are able to guide and give advices, I’m open to listen ! I’m just a poor beginner !:grinning:

Well here is a place to start: https://www.w3schools.com/sql/

The first questions to answer are why are you storing the data and what you want to do with it when you retrieve it? Also how long do you want to store it for? The answers to those questions may help to determine the best way to save it.

Well storing one line of values. You may as well just store the raw data as a tab separated file.