Hi all,
with your help I was able to create my first node-red flow. Now I want to understand what could be made in a better way.
I think there is a way to reduce the nodes in terms of data transformations after the insert to the database.
Here is my first flow:
[{"id":"566c79f1.69cd18","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"58bd3ead.0e604","type":"http request","z":"566c79f1.69cd18","name":"","method":"GET","ret":"txt","url":"http://192.168.178.90:8080/last/1","tls":"","x":294.5,"y":213,"wires":[["2a87241d.fb2a2c"]]},{"id":"61769823.4a6978","type":"inject","z":"566c79f1.69cd18","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"*/1 0-23 * * *","once":false,"onceDelay":"0","x":294,"y":157,"wires":[["58bd3ead.0e604"]]},{"id":"2a87241d.fb2a2c","type":"json","z":"566c79f1.69cd18","name":"","property":"payload","action":"obj","pretty":false,"x":463.5,"y":214,"wires":[["942129dd.a9ab18"]]},{"id":"cca1fc32.48a92","type":"mysql","z":"566c79f1.69cd18","mydb":"edd790d3.2eb0e","name":"","x":502.5,"y":380,"wires":[["e5dfc632.8d0bd8"]]},{"id":"942129dd.a9ab18","type":"template","z":"566c79f1.69cd18","name":"Data insert","field":"topic","fieldType":"msg","format":"text","syntax":"mustache","template":"INSERT INTO gosdm630.input_data (\n UniqueDeviceId,\n Timestamp,\n Unix,\n ModbusDeviceId,\n Power_L1,\n Power_L2,\n Power_L3,\n Voltage_L1,\n Voltage_L2,\n Voltage_L3,\n Current_L1,\n Current_L2,\n Current_L3,\n Cosphi_L1,\n Cosphi_L2,\n Cosphi_L3,\n Import_L1,\n Import_L2,\n Import_L3,\n TotalImport,\n Export_L1,\n Export_L2,\n Export_L3,\n TotalExport,\n THD_L1,\n THD_L2,\n THD_L3,\n THD_AVG,\n Freq\n)\nVALUES( \n '{{payload.UniqueId}}',\n '{{payload.Timestamp}}',\n {{payload.Unix}},\n {{payload.ModbusDeviceId}},\n {{payload.Power.L1}},\n {{payload.Power.L2}},\n {{payload.Power.L3}},\n {{payload.Voltage.L1}},\n {{payload.Voltage.L2}},\n {{payload.Voltage.L3}},\n {{payload.Current.L1}},\n {{payload.Current.L2}},\n {{payload.Current.L3}},\n {{payload.Cosphi.L1}},\n {{payload.Cosphi.L2}},\n {{payload.Cosphi.L3}},\n {{payload.Import.L1}},\n {{payload.Import.L2}},\n {{payload.Import.L3}},\n {{payload.TotalImport}},\n {{payload.Export.L1}},\n {{payload.Export.L2}},\n {{payload.Export.L3}},\n {{payload.TotalExport}},\n {{payload.THD.VoltageNeutral.L1}},\n {{payload.THD.VoltageNeutral.L2}},\n {{payload.THD.VoltageNeutral.L3}},\n {{payload.THD.AvgVoltageNeutral}},\n {{payload.Frequency}} \n \n)","output":"str","x":291.5,"y":380,"wires":[["cca1fc32.48a92"]]},{"id":"adca0623.064f38","type":"mysql","z":"566c79f1.69cd18","mydb":"edd790d3.2eb0e","name":"","x":499,"y":457,"wires":[["fc03fd2c.c581d"]]},{"id":"fc03fd2c.c581d","type":"template","z":"566c79f1.69cd18","name":"Data preparation","field":"topic","fieldType":"msg","format":"text","syntax":"plain","template":"\nINSERT INTO `gosdm630`.`data`\n(`ID`,\n`UniqueDeviceId`,\n`Timestamp_raw`,\n`Timestamp`,\n`Unix_raw`,\n`Unix_vz`,\n`ModbusDeviceId`,\n`Power_L1`,\n`Power_L2`,\n`Power_L3`,\n`TotalPower`,\n`Voltage_L1`,\n`Voltage_L2`,\n`Voltage_L3`,\n`Current_L1`,\n`Current_L2`,\n`Current_L3`,\n`Cosphi_L1`,\n`Cosphi_L2`,\n`Cosphi_L3`,\n`Import_L1`,\n`Import_L2`,\n`Import_L3`,\n`TotalImport`,\n`Export_L1`,\n`Export_L2`,\n`Export_L3`,\n`TotalExport`,\n`THD_L1`,\n`THD_L2`,\n`THD_L3`,\n`THD_AVG`,\n`Freq`\n\n)\n\nSELECT `input_data`.`ID`,\n `input_data`.`UniqueDeviceId`,\n `input_data`.`Timestamp`,\n (str_to_date(substring_index(`input_data`.`Timestamp`,'.', 1),'%Y-%m-%dT%H:%i:%s')) AS timestamp,\n #convert(`input_data`.`Timestamp`,DATETIME),\n `input_data`.`Unix`,\n (input_data.Unix*1000),\n `input_data`.`ModbusDeviceId`,\n `input_data`.`Power_L1`,\n `input_data`.`Power_L2`,\n `input_data`.`Power_L3`,\n (`input_data`.`Power_L1`+`input_data`.`Power_L2`+`input_data`.`Power_L3`) AS TotalPower,\n `input_data`.`Voltage_L1`,\n `input_data`.`Voltage_L2`,\n `input_data`.`Voltage_L3`,\n `input_data`.`Current_L1`,\n `input_data`.`Current_L2`,\n `input_data`.`Current_L3`,\n `input_data`.`Cosphi_L1`,\n `input_data`.`Cosphi_L2`,\n `input_data`.`Cosphi_L3`,\n `input_data`.`Import_L1`,\n `input_data`.`Import_L2`,\n `input_data`.`Import_L3`,\n `input_data`.`TotalImport`,\n `input_data`.`Export_L1`,\n `input_data`.`Export_L2`,\n `input_data`.`Export_L3`,\n `input_data`.`TotalExport`,\n `input_data`.`THD_L1`,\n `input_data`.`THD_L2`,\n `input_data`.`THD_L3`,\n `input_data`.`THD_AVG`,\n `input_data`.`Freq`\nFROM `gosdm630`.`input_data`;\n;","output":"str","x":334,"y":526,"wires":[["42597d4f.22d4f4"]]},{"id":"7c6a8bce.6ec284","type":"debug","z":"566c79f1.69cd18","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":495,"y":651,"wires":[]},{"id":"e5dfc632.8d0bd8","type":"template","z":"566c79f1.69cd18","name":"Data cleanup","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"delete from `gosdm630`.`input_data` \nwhere `input_data`.`ID` <= \t(select max(`data`.`id`) \n\t\t\t\t\t\t\tfrom `gosdm630`.`data`);\n","output":"str","x":292,"y":458,"wires":[["adca0623.064f38"]]},{"id":"42597d4f.22d4f4","type":"mysql","z":"566c79f1.69cd18","mydb":"edd790d3.2eb0e","name":"","x":557.5,"y":528,"wires":[["7c6a8bce.6ec284"]]},{"id":"edd790d3.2eb0e","type":"MySQLdatabase","z":"","host":"192.168.178.107","port":"3306","db":"gosdm630","tz":""}]
Thx and KR
Itchy2