Posts

Showing posts from October, 2021

#6 監測資料寫入InfluxDB資料庫, 長期保存並在NodeRED資訊看板裡顯示

Image
大家好, 今天來和大家分享 “一起來學樹莓派, 寫入InfluxDB 資料庫”. 上集分享的是資料送到 MQTT 顯示到資訊看板後, 時間後後資料就消失了. 本集是把所有的資料收集起來之後, 可以用來以後做為資料分析的依據. 以前你可能要把資料寫到 Thinkspeak server上, 現在自己家裡的樹莓派上就可以做到了! 一起來學樹莓派吧! 這影片內容有: 安裝 InfluxDB 資料庫 比較 InfluxDB 與關聯式資庫的不同 如何把ESP32送到 MQTT 資料寫入InfluxDB 資料庫 讀取InfluxDB 資料庫, 再把這些資料在資訊看板上顯示出來 Format code for writing InfluxDB // Create the object key to match DB filed name from topic name(studio/temp1) msg.payload["temp"] = msg.payload["studio/temp1"]; // Delete the unwanted studio/temp1 delete msg.payload["studio/temp1"]; // Update temp from string to float msg.payload["temp"] = parseFloat(msg.payload["temp"]); msg.payload["humd"] = msg.payload["studio/humd1"]; delete msg.payload["studio/humd1"]; msg.payload["humd"] = parseFloat(msg.payload["humd"]); //remove unused topic delete msg.topic; //Create a temporary array var data = []; data.push(msg.payload); //Add object to DB Tag(in

#5 2021 一起學 Raspberry Pi 4 - 溫溼度感測器DHT11由 ESP32 經 MQTT 送到 Node-RED

Image
大家好, 今天來和大家分享如何把 DHT11溫溼度感測器上的資料由ESP32 讀取, 並用MQTT Client 發佈到 Mosquitto Server(MQTT), 再送到 Node-RED上, 再把這些資料在資訊看板上顯示出來.  本篇使用到的程式碼: //---- Setup update frequency -----// const long TEMP_updateInterval = 10000; // How long to change temp and update, 10000 = 10 sec unsigned long TEMP_currentMillis = 0; unsigned long TEMP_previousMillis = 0; // store last time temp update #include "DHT.h" #define DHTPIN 23 //ESP32 pin 23 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor /* SimpleMQTTClient.ino The purpose of this exemple is to illustrate a simple handling of MQTT and Wifi connection. Once it connects successfully to a Wifi network and a MQTT broker, it subscribe to a topic and send a message to it. It will also send a message delayed 5 seconds later. */ #include "EspMQTTClient.h" EspMQTTClient client( "Your_WiFi_AP", // Wi-Fi AP name "Wi-FI_Password", // Wi-Fi Password "192.168.0.119", //