i want to collect data and then send it to database, but it said msg.topic : the query is not defined as a string". i don't know how to fix it.
Difficult to tell from just a picture.
Either share your flow or show where you set topic.
Ps, try adding node.warn(typeof msg.topic)
in the function AFTER you have generated your SQL statement.
[{"id":"faa8e95.a885c18","type":"tab","label":"Database1","disabled":false,"info":"定時send data to database\ndata有變化會send database"},{"id":"b406cf79.f68bd","type":"delay","z":"faa8e95.a885c18","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"15","rateUnits":"minute","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":500,"y":140,"wires":[["444c3494.0790ec","9e9af451.5699d8"]]},{"id":"6b1cc7cb.f7c658","type":"rbe","z":"faa8e95.a885c18","name":"block","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":770,"y":220,"wires":[["635751e4.1dd69"]]},{"id":"9e9af451.5699d8","type":"debug","z":"faa8e95.a885c18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":140,"wires":[]},{"id":"553bdf96.1262","type":"function","z":"faa8e95.a885c18","name":"小數點後兩個位","func":"msg.payload = (msg.payload*1).toFixed(2);\n return msg; ","outputs":1,"noerr":0,"initialize":"","finalize":"","x":320,"y":220,"wires":[["b406cf79.f68bd","444c3494.0790ec"]]},{"id":"d0b7b024.a5c61","type":"ui_template","z":"faa8e95.a885c18","group":"5be80bfc.629394","name":"UI Table","order":2,"width":"6","height":"3","format":"<table style=\"width:100%\">\n <tr>\n <th>aadate</th> \n <th>bbdate</th> \n <th>ccdate</th>\n <th>date</th>\n </tr>\n <tr ng-repeat=\"x in msg.payload | limitTo:2\">\n <td>{{msg.payload[$index].currenttime}}</td>\n <td>{{msg.payload[$index].temperature}}</td> \n <td>{{msg.payload[$index].humidity}}</td>\n </tr>\n</table>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","x":820,"y":440,"wires":[[]]},{"id":"6d2618c7.3560f8","type":"inject","z":"faa8e95.a885c18","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"900","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":380,"wires":[["30fb4ee.3c440b2"]]},{"id":"30fb4ee.3c440b2","type":"sqlite","z":"faa8e95.a885c18","mydb":"2c912755.393d98","sqlquery":"msg.topic","sql":"","name":"database1","x":350,"y":380,"wires":[["1e897b24.c714a5"]]},{"id":"444c3494.0790ec","type":"function","z":"faa8e95.a885c18","name":"","func":"var aa1 = msg.payload;\nflow.set(\"data\",aa1);\nvar newaa1 = msg.payload\nif (newaa1 != aa1)// If定時data不同於即時data\n {newaa1 = aa1 }// 即時data會取代定期data\n//問題是定期data每15分鐘一次, 如果在15分鐘內有變化,即時data如何傳入database?\nelse \n { newaa1 == msg.payload} \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":610,"y":220,"wires":[["9e9af451.5699d8","6b1cc7cb.f7c658"]]},{"id":"114328f5.edffd7","type":"comment","z":"faa8e95.a885c18","name":"take data from database","info":"// get data from database1 and send it to UI table","x":190,"y":320,"wires":[]},{"id":"a1e2c30d.41b5b","type":"comment","z":"faa8e95.a885c18","name":"store data to database","info":"data in > 0.00> 15min/1 or check data > store as bb1\ncheck data > data != newdata > data = newdata\nIf newdata = data > block unchanged number ","x":180,"y":120,"wires":[]},{"id":"b5edccd1.4ade7","type":"mqtt in","z":"faa8e95.a885c18","name":"","topic":"abc123","qos":"2","datatype":"auto","broker":"532a0205.3d9cfc","x":130,"y":180,"wires":[["553bdf96.1262"]]},{"id":"1e897b24.c714a5","type":"function","z":"faa8e95.a885c18","name":"get data every 15mins","func":"var values = flow.get([\"data\"]);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":600,"y":380,"wires":[["d0b7b024.a5c61","ea81ef4b.c6753"]]},{"id":"635751e4.1dd69","type":"sqlite","z":"faa8e95.a885c18","mydb":"2c912755.393d98","sqlquery":"msg.topic","sql":"","name":"database1","x":910,"y":220,"wires":[[]]},{"id":"ea81ef4b.c6753","type":"debug","z":"faa8e95.a885c18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":380,"wires":[]},{"id":"b14d0e3e.7bb1e","type":"comment","z":"faa8e95.a885c18","name":"show data in UI table","info":"","x":640,"y":460,"wires":[]},{"id":"f08a4770.76aa28","type":"inject","z":"faa8e95.a885c18","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"30","payloadType":"num","x":130,"y":260,"wires":[["553bdf96.1262"]]},{"id":"5be80bfc.629394","type":"ui_group","name":"Data","tab":"da0180c5.64fa9","order":3,"disp":true,"width":"6","collapse":false},{"id":"2c912755.393d98","type":"sqlitedb","db":"/home/pi/datebase1.db","mode":"RWC"},{"id":"532a0205.3d9cfc","type":"mqtt-broker","name":"OrgPi4-202","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"da0180c5.64fa9","type":"ui_tab","name":"IP Camera","icon":"photo_camera"}]
Hi, in order to make code more readable and importable it is important to surround your code with three backticks
```
like this
```
You can edit and correct your post by clicking the pencil icon.
See this post for more details - How to share code or flow json
Also add a debug node showing what is going into the db node and check that msg.topic contains the correct query. Set the debug node to show Complete Message.
Thanks for helping.i will add a debug.
You must create your sql query and put it in msg.topic.
Nowhere in your flow do I see a valid sql query - Do you know how to format an sql 'insert' statement?
If not, you might want to do some reading.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.