I installed node-red on a laptop running Ubuntu 18.04. It was installed from the Snap Store so I am not relly sure how to change settings.js.
The flow goes like this:
node-red-node-openweathermap 0.2.1 access OpenWeatherMAPI API
|
Function Node converts some values and creates an SQL
| insert query in msgTopic.
node-red-node-mysql 0.0.19 Insert data to Database
The query works okay but the SQL node is throwing this error exactly every 20 seonds. I think that is the default timeout in the settings.js file. Data only comes from the OWM node around every ten minutes.
Error: ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: NO)
Problem comes then I try to retrieve the data with another flow in another tab. This flow consist of Inject > SQL > Function Node > Chart Node. The function Node formats the data for the Chart node.
The chart shows on the tab but it never shows data. Only the group label and chart label are shown - no X,Y axis or data. The inject node has the Select Query in. This node injects thhe query as I can see from a debug node. Adebug node after SQL node only shows a blank message.
On another note I tried SQLite node but can only create a :memory:. I cannot get it to connect to a database on the physical (loacal hard) drive. SQL DB Browser will connect to the the physical table. I will attach the two flows.
I am sorry for typos. I have bad tremors in both hand and arms.
Collect and insert flow.
[{"id":"16666702.703cc9","type":"tab","label":"OWMap","disabled":false,"info":""},{"id":"899919a9.ed9758","type":"openweathermap in","z":"16666702.703cc9","name":"OWM Conditions","wtype":"current","lon":"-94.9183","lat":"31.6591","city":"","country":"","language":"en","x":120,"y":60,"wires":[["a5ec3971.0fecd8","9ceedf81.4fd52"]]},{"id":"a5ec3971.0fecd8","type":"function","z":"16666702.703cc9","name":"","func":"\nvar mp = msg.payload;\n \n\nvar tempF = Number(mp.tempc) * 1.8 + 32;\nvar tempK = Number(mp.tempk);\nvar humidity = Number(mp.humidity);\n\nvar dewPtK = Math.pow(humidity/100, (1/8)) * (112 + 0.9 * tempK) + 0.1 * tempK - 112;\n\nvar dewPtF = (dewPtK-273.15) * 1.8 +32;\n\nvar visMi = Number(msg.data.visibility) * 3.28083 /5280;\n\nvar windSpMPH = Number(mp.windspeed) * 2.23694;\n\nvar sql = "INSERT INTO tblObs (dt, location, tempf, humidity, dewPt, pressure, clouds, visibility, ";\nsql = sql + "windSp, windDir) ";\n\nsql = sql + "VALUES (" + msg.data.dt + ", '" + msg.location.city + "', " + tempF + ", " + mp.humidity;\nsql = sql + ", " + dewPtF + ", " + mp.pressure + ", " + mp.clouds + ", " + visMi + ", ";\nsql = sql + windSpMPH + ", " + mp.winddirection + ");"\n\nmsg.topic = sql;\n\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":60,"wires":[["4c8f8e92.9034e"]]},{"id":"4c8f8e92.9034e","type":"mysql","z":"16666702.703cc9","mydb":"40d9596e.d88058","name":"","x":500,"y":60,"wires":[]},{"id":"6f1acf71.68ecf","type":"comment","z":"16666702.703cc9","name":"Open weather map collector","info":"","x":160,"y":20,"wires":},{"id":"9ceedf81.4fd52","type":"debug","z":"16666702.703cc9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":320,"y":140,"wires":},{"id":"40d9596e.d88058","type":"MySQLdatabase","z":"","host":"127.0.0.1","port":"3306","db":"OWMap","tz":""}]
Retreive and Graph Flow.
[{"id":"310f7da9.ca9662","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"db713f49.e4dfc","type":"comment","z":"310f7da9.ca9662","name":"Temp, Dewpt, & Humidity","info":"","x":150,"y":60,"wires":},{"id":"3342e14e.28400e","type":"inject","z":"310f7da9.ca9662","name":"","topic":"Select dt, tempF, humidity, dewPt, clouds from tblObs Where dt >= DATE_SUB(Now(), INTERVAL 2 DAY) Order By dt","payload":"","payloadType":"str","repeat":"240","crontab":"","once":true,"onceDelay":"","x":90,"y":100,"wires":[["47abcf48.c708","7deda106.86dd1"]]},{"id":"38055ba1.35de04","type":"function","z":"310f7da9.ca9662","name":"M Graph","func":"\nvar d0 = ;\nvar d1 = ;\nvar d2 = ;\nvar d3 = ;\n\nlabels = [""];\n\nfor (var i = 0; i< msg.payload.length; i++){\n \n var timestamp = new Date(msg.payload[i].dt); \n \n //Adjust time to show on graph as local\n var to = timestamp.getTimezoneOffset();\n timestamp = timestamp - to * 60 * 1000;\n \n if (i === 0) {var tFirst = timestamp}\n \n var temp = (msg.payload[i].tempF) * (9/5) + 32;\n d0.push({"x":timestamp, "y":tempF}); \n \n var dewpt = (msg.payload[i].dewPt) * (9/5) + 32;\n d1.push({"x":timestamp, "y":dewPt}); \n\n \n var t = parseFloat(msg.payload[i].temp);\n var dp = parseFloat(msg.payload[i].dewpt);\n \n \n d2.push({"x":timestamp, "y":humidity}); \n\n}\n\nvar tLast = timestamp;\n\nt = 32; \nd3.push({"x":tFirst, "y":t});\nd3.push({"x":tLast, "y":t});\n\nmsg.payload = [{"series":["Temperature", "Humidity", "Dewpt","Freezing"],"data": [d0, d1, d2,d3], labels}];\n\nreturn msg;\n\n","outputs":1,"noerr":0,"x":400,"y":100,"wires":[["6b1034c1.4406cc"]]},{"id":"6b1034c1.4406cc","type":"ui_chart","z":"310f7da9.ca9662","name":"","group":"ef4ed59f.7bd018","order":0,"width":0,"height":0,"label":"Temperature, Humidty & Dewpoint","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"100","removeOlder":"2","removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#ff8000","#80ff00","#0000ff","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":620,"y":100,"wires":[]},{"id":"47abcf48.c708","type":"mysql","z":"310f7da9.ca9662","mydb":"40d9596e.d88058","name":"","x":240,"y":100,"wires":[["38055ba1.35de04","6024c326.00032c"]]},{"id":"7deda106.86dd1","type":"debug","z":"310f7da9.ca9662","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":200,"y":180,"wires":},{"id":"6024c326.00032c","type":"debug","z":"310f7da9.ca9662","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":430,"y":180,"wires":},{"id":"ef4ed59f.7bd018","type":"ui_group","z":"","name":"Graphs","tab":"c7061180.fe759","order":1,"disp":true,"width":"8","collapse":false},{"id":"40d9596e.d88058","type":"MySQLdatabase","z":"","host":"127.0.0.1","port":"3306","db":"OWMap","tz":""},{"id":"c7061180.fe759","type":"ui_tab","z":"","name":"Current Conditions","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
Query to create table.
CREATE TABLE tblObs
(
dt
INTEGER NOT NULL,
location
TEXT,
tempF
NUMERIC,
humidity
NUMERIC,
dewPt
NUMERIC,
pressure
NUMERIC,
clouds
NUMERIC,
visibility
NUMERIC,
windSp
NUMERIC,
windDir
NUMERIC
);
Thank you,
Richard Watkins