Node-Red & MySQL & Line Notify
注意
S =msg.payload
msg.topic = "INSERT INTO led ( `LED_Status`) VALUES ( '" + S + "');"
return msg;
Node-Red & MySQL & Line Notify
注意
S =msg.payload
msg.topic = "INSERT INTO led ( `LED_Status`) VALUES ( '" + S + "');"
return msg;
Node-Red & MySQL random 2 number Store To MySQL Database
[{"id":"6a6300bd.5b3a6","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"e85555cf.03b198","type":"debug","z":"6a6300bd.5b3a6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":570,"y":40,"wires":[]},{"id":"7fa0d45f.9028ec","type":"function","z":"6a6300bd.5b3a6","name":"MySQL Function","func":"temperature = msg.payload[0]\nhumidity = msg.payload[1]\n\n//humidity = msg.payload.humidity\n//temperature = msg.payload.temperature\nmsg.topic = \"INSERT INTO temp_humi ( `temperature`, `humidity`) VALUES ( \"+ temperature+\", \"+ humidity +\");\"\nreturn msg;\n\n","outputs":1,"noerr":0,"x":450,"y":200,"wires":[["bb82ea59.32bd68","db671226.0ba2f"]]},{"id":"bb82ea59.32bd68","type":"mysql","z":"6a6300bd.5b3a6","mydb":"3ec1eff7.3a59c","name":"MySQLDatabase","x":690,"y":200,"wires":[[]]},{"id":"8a986dfc.3816c","type":"inject","z":"6a6300bd.5b3a6","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":80,"y":140,"wires":[["9ed27499.0d9ca8","7740e351.41719c"]]},{"id":"9ed27499.0d9ca8","type":"random","z":"6a6300bd.5b3a6","name":"","low":"-50","high":"50","inte":"true","property":"payload","x":240,"y":120,"wires":[["fd7b9e51.97bab"]]},{"id":"7740e351.41719c","type":"random","z":"6a6300bd.5b3a6","name":"","low":"1","high":"100","inte":"true","property":"payload","x":240,"y":160,"wires":[["fd7b9e51.97bab"]]},{"id":"fd7b9e51.97bab","type":"join","z":"6a6300bd.5b3a6","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":390,"y":120,"wires":[["e85555cf.03b198","7fa0d45f.9028ec"]]},{"id":"db671226.0ba2f","type":"debug","z":"6a6300bd.5b3a6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":660,"y":300,"wires":[]},{"id":"3ec1eff7.3a59c","type":"MySQLdatabase","z":"","name":"","host":"127.0.0.1","port":"3306","db":"mysql_test1","tz":"GMT +8"}]
Node-RED & MySQL (Insert , Delete , Update , Select )
Setting MySQL DataBase
/Template
<table style="width:100%">
<tr>
<th>Index</th>
<th>Sensor</th>
<th>Temperature</th>
<th>Humidity</th>
</tr>
<tr ng-repeat="x in msg.payload | limitTo:20">
<td>{{$index}}</td>
<td align="center">{{msg.payload[$index].SensorName}}</td>
<td align="center">{{msg.payload[$index].Temperature}}</td>
<td align="center">{{msg.payload[$index].Humidity}}</td>
</tr>
</table>
/Insert
INSERT INTO `sensor` (`SensorName`, `Temperature`, `Humidity`) VALUES ('Sensor1', '25', '78');
INSERT INTO `sensor` (`SensorName`, `Temperature`, `Humidity`) VALUES ('Sensor2', '45', '56');
INSERT INTO `sensor` (`SensorName`, `Temperature`, `Humidity`) VALUES ('Sensor3', '38', '88');
SELECT * FROM sensor
DELETE FROM sensor WHERE Sensor_Id = 6
UPDATE sensor SET Temperature = 0 WHERE Sensor_Id = 7
/ PhpMyAdmin Setting
[{"id":"5a02d23f.8784ec","type":"tab","label":"流程4","disabled":false,"info":""},{"id":"e8de394c.aad598","type":"mysql","z":"5a02d23f.8784ec","mydb":"73a92d28.0c3eb4","name":"Test","x":370,"y":300,"wires":[["3e0abcb2.4bb474","4edf2cfa.0ee964"]]},{"id":"e3ca7c3f.1e92f","type":"inject","z":"5a02d23f.8784ec","name":"Insert Data1","topic":"INSERT INTO `sensor` (`SensorName`, `Temperature`, `Humidity`) VALUES ('Sensor1', '25', '78');","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":180,"wires":[["e8de394c.aad598"]]},{"id":"3e0abcb2.4bb474","type":"debug","z":"5a02d23f.8784ec","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":570,"y":300,"wires":[]},{"id":"15998a8.733e176","type":"inject","z":"5a02d23f.8784ec","name":"Insert Data2","topic":"INSERT INTO `sensor` (`SensorName`, `Temperature`, `Humidity`) VALUES ('Sensor2', '45', '56');","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":240,"wires":[["e8de394c.aad598"]]},{"id":"e5c239a7.944e78","type":"inject","z":"5a02d23f.8784ec","name":"Insert Data3","topic":"INSERT INTO `sensor` (`SensorName`, `Temperature`, `Humidity`) VALUES ('Sensor3', '38', '88');","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":300,"wires":[["e8de394c.aad598"]]},{"id":"595c5780.0c9f98","type":"inject","z":"5a02d23f.8784ec","name":"Select","topic":"SELECT * FROM sensor","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":340,"wires":[["e8de394c.aad598"]]},{"id":"d2cc1836.ca4e98","type":"inject","z":"5a02d23f.8784ec","name":"Delete","topic":"DELETE FROM sensor WHERE Sensor_Id = 6","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":380,"wires":[["e8de394c.aad598"]]},{"id":"a64a4ae2.71f728","type":"inject","z":"5a02d23f.8784ec","name":"UpDate Record 7","topic":"UPDATE sensor SET Temperature = 0 WHERE Sensor_Id = 7","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":420,"wires":[["e8de394c.aad598"]]},{"id":"4edf2cfa.0ee964","type":"ui_template","z":"5a02d23f.8784ec","group":"6c9116b.b62d4e8","name":"","order":9,"width":0,"height":0,"format":"<table style=\"width:100%\">\n <tr>\n <th>Index</th> \n <th>Sensor</th>\n <th>Temperature</th> \n <th>Humidity</th>\n </tr>\n <tr ng-repeat=\"x in msg.payload | limitTo:20\">\n <td>{{$index}}</td>\n <td align=\"center\">{{msg.payload[$index].SensorName}}</td>\n <td align=\"center\">{{msg.payload[$index].Temperature}}</td> \n <td align=\"center\">{{msg.payload[$index].Humidity}}</td>\n </tr>\n</table>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":560,"y":360,"wires":[[]]},{"id":"73a92d28.0c3eb4","type":"MySQLdatabase","z":"","name":"MySQL_Test2","host":"localhost","port":"3306","db":"mysql_test2","tz":""},{"id":"6c9116b.b62d4e8","type":"ui_group","z":"","name":"Test","tab":"eeb8e179.a47a4","order":1,"disp":true,"width":"6","collapse":false},{"id":"eeb8e179.a47a4","type":"ui_tab","z":"","name":"MySQL","icon":"dashboard","disabled":false,"hidden":false}]
XAMPP是完全免費且易於安裝的Apache發行版本,其中包含MariaDB、PHP和Perl。XAMPP開放源碼套件的設置讓安裝和使用出奇容易。
下載點
https://www.apachefriends.org/zh_tw/index.html
參考來源
安裝後 需要修改MySQL 設定 才能 啟動 Apache 與MySQL
MQTT 架構 mosquitto 安裝 開發工具 mqttlens 安裝
源自於 https://yazelin.github.io/usc2017nsp/week1.html
發佈者Publisher、代理人Broker和訂閱者Subscriber
注意:「不勾選」Service
注意:安裝時將DLL檔安裝至Bin資料夾內
從預設路徑(:c:/OpenSSL-Win32/bin)中複製dll檔
到mosquitto資料夾中
下載完後直接移動至mosquitto資料夾內
(若案裝失敗以系統管理員身份執行Chrome後重新安裝)
Node-Red --> MQTT --> Fuxa FUXA(一個開源的 Web HMI / SCADA 自動化監控軟體)的專案設定檔 。 這份設定檔完整定義了 HMI 監控畫面的 後端通訊(MQTT 連線、點位標籤) 與 前端網頁圖形介面(SVG 畫布...