2018年12月18日 星期二

ESP32 and Node-RED


ESP32 and Node-RED - https://erik-bartmann.de/











ESP32

#include <WiFi.h> #define MSG 50 //Maximum length of the message //const char* ssid = "<SSID>"; //const char* password = "<Passwort>"; const char* ssid = "alex9ufo"; const char* password = "alex9981"; int pinArray[] = {32, 33, 25, 26}; // IO-Pins WiFiServer server(8088); // Server listens on Port 8088 //=============================================== void setup() { for(int i=0; i<4; i++) pinMode(pinArray[i], OUTPUT); Serial.begin(115200); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected to IP address: "); Serial.println(WiFi.localIP()); server.begin(); // Start server } //=============================================== void loop() { String msg = ""; //message // Wait for a new client WiFiClient client = server.available(); uint8_t data[MSG]; if (client) { Serial.println("New client"); // Check if client connected while (client.connected()) { if (client.available()) { int len = client.read(data, MSG); if (len < MSG) data[len] = '\0'; else data[MSG] = '\0'; Serial.print("Clients message: "); msg = (char *)data; Serial.println(msg); evalMessage(msg); } } } } //=============================================== void evalMessage(String msg) { int pos = msg.indexOf(':'); int pin = msg.substring(0, pos).toInt(); int status = msg.substring(pos + 1).toInt(); Serial.print("pin"); Serial.print(pin); Serial.print(" out-->"); Serial.println(status); digitalWrite(pin, status); } //===============================================

json檔案

[{"id":"6372b83a.142da8","type":"tcp out","z":"dfe6f708.aa2998","host":"192.168.43.101","port":"8088","beserver":"client","base64":false,"end":false,"name":"","x":530,"y":220,"wires":[]},{"id":"459dd59d.28a9fc","type":"ui_switch","z":"dfe6f708.aa2998","name":"","label":"IO 32","group":"97115c54.4a468","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"32:1","onvalueType":"str","onicon":"","oncolor":"","offvalue":"32:0","offvalueType":"str","officon":"","offcolor":"","x":190,"y":140,"wires":[["6372b83a.142da8","ad655753.cc6bb8"]]},{"id":"88a2475d.11d0e8","type":"ui_switch","z":"dfe6f708.aa2998","name":"","label":"IO 33","group":"97115c54.4a468","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"33:1","onvalueType":"str","onicon":"","oncolor":"","offvalue":"33:0","offvalueType":"str","officon":"","offcolor":"","x":190,"y":200,"wires":[["6372b83a.142da8","ad655753.cc6bb8"]]},{"id":"182c39ab.0f6f66","type":"ui_switch","z":"dfe6f708.aa2998","name":"","label":"IO 25","group":"97115c54.4a468","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"25:1","onvalueType":"str","onicon":"","oncolor":"","offvalue":"25:0","offvalueType":"str","officon":"","offcolor":"","x":190,"y":260,"wires":[["6372b83a.142da8","ad655753.cc6bb8"]]},{"id":"80606822.5c5cb8","type":"ui_switch","z":"dfe6f708.aa2998","name":"","label":"IO 26","group":"97115c54.4a468","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"26:1","onvalueType":"str","onicon":"","oncolor":"","offvalue":"26:0","offvalueType":"str","officon":"","offcolor":"","x":190,"y":320,"wires":[["6372b83a.142da8","ad655753.cc6bb8"]]},{"id":"ad655753.cc6bb8","type":"debug","z":"dfe6f708.aa2998","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":490,"y":300,"wires":[]},{"id":"97115c54.4a468","type":"ui_group","z":"","name":"IO Control","tab":"e8d80b82.e89aa8","disp":true,"width":"6","collapse":false},{"id":"e8d80b82.e89aa8","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

沒有留言:

張貼留言

2024產專班 作業2

 2024產專班 作業2   1. 系統圖       ESP32+MFRC522 組成RFID Reader 可以將RFID卡片的UID 透過 MQTT協定    上傳(發行 主題 (:topic) alex9ufo/2024/RFID/RFID_UID  ,, Payload...