当前位置:网站首页>6. graduation design temperature and humidity monitoring system (esp8266 + DHT11 +oled real-time upload temperature and humidity data to the public network server and display the real-time temperature
6. graduation design temperature and humidity monitoring system (esp8266 + DHT11 +oled real-time upload temperature and humidity data to the public network server and display the real-time temperature
2022-06-28 05:43:00 【Zhang San programming sharing】
List of articles
Hardware environment
- ESP8266 Development board ;
- DHT11 A temperature and humidity sensor ;
- OLED 128*64 Resolution display screen one ;
The hardware wiring diagram is shown below :
Software environment
1. WiFi Networking and HttpPost To configure
Refer to my other blog post , This blog post shows how to build PostHttpClient engineering , After modification, upload the data to the public network server Web The server ,
《5. ESP8266 Use PostHttpClient Routine uploads data to Web Server background 》.
2. DHT11 Temperature and humidity reading and OLED Display configuration
Refer to my other blog post , This blog post shows how to use ESP8266 NodeMCU Development board acquisition DHT11 Temperature and humidity sensor and display the data in OLED On the screen ,《4. ESP8266 adopt OLED real-time display DHT11 Temperature and humidity parameters 》.
3. Web Server configuration ( Used to receive HTTP Data request )
If the server system is windos, You can refer to the previous blog 《 Raspberry pie + sensor + Public network server Component's own IOT platform ( 3、 ... and )WEB Server configuration 》;
If the server system is Ubuntu, According to my B Station video synchronization setup ,B standing ID Programming and sharing for Zhang San , The address is :https://space.bilibili.com/243861879, This account will update the server configuration process in real time .
Web The process of setting up a server environment is the most complicated , If it is Xiaobai, it can be based on B The content of the station video is built step by step .
Code git take Web The code of the server is downloaded locally , The order is as follows :
git clone git://116.198.42.221/ESP8266_IOT.git
Use_Mysql The code under the directory is Django All codes of the project , After downloading, run in the server , You need to modify one of them mysql Database related information
Experimental process
1. ESP8266 NodeMCU Complete code
Upload the following code to ESP8266 NodeMCU in , The code only needs to modify the server address and WiFi Relevant information is enough
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h> // Include DHT library code
//begin********http head and define***************
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#define SERVER_IP "116.198.42.221" // Here is my internet server IP Address , This needs to be modified
#ifndef STASSID
#define STASSID "WiFi name"
#define STAPSK "WiFi password"
#endif
//end********http head and define***************
#define DHTPIN 14 // DHT11 data pin is connected to ESP8266 GPIO14 (NodeMCU D5)
#define DHTTYPE DHT11 // DHT11 sensor is used
DHT dht(DHTPIN, DHTTYPE); // Configure DHT library
char temperature[] = "00.0";
char humidity[] = "00.0";
// OLED FeatherWing buttons map to different pins depending on board.
// The I2C (Wire) bus may also be different.
#if defined(ESP8266)
#define BUTTON_A 0
#define BUTTON_B 16
#define BUTTON_C 2
#define WIRE Wire
#elif defined(ESP32)
#define BUTTON_A 15
#define BUTTON_B 32
#define BUTTON_C 14
#define WIRE Wire
#elif defined(ARDUINO_STM32_FEATHER)
#define BUTTON_A PA15
#define BUTTON_B PC7
#define BUTTON_C PC5
#define WIRE Wire
#elif defined(TEENSYDUINO)
#define BUTTON_A 4
#define BUTTON_B 3
#define BUTTON_C 8
#define WIRE Wire
#elif defined(ARDUINO_FEATHER52832)
#define BUTTON_A 31
#define BUTTON_B 30
#define BUTTON_C 27
#define WIRE Wire
#elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040)
#define BUTTON_A 9
#define BUTTON_B 8
#define BUTTON_C 7
#define WIRE Wire1
#else // 32u4, M0, M4, nrf52840 and 328p
#define BUTTON_A 9
#define BUTTON_B 6
#define BUTTON_C 5
#define WIRE Wire
#endif
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &WIRE);
void setup() {
Serial.begin(9600);
Serial.println("OLED FeatherWing test");
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32
//display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // initialize with the I2C addr 0x3D (for the 128x64)
Serial.println("OLED begun");
// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
display.display();
delay(1000);
// Clear the buffer.
display.clearDisplay();
display.display();
Serial.println("IO test");
pinMode(BUTTON_A, INPUT_PULLUP);
pinMode(BUTTON_B, INPUT_PULLUP);
pinMode(BUTTON_C, INPUT_PULLUP);
// text display tests
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
dht.begin(); // Initialize the DHT library
// Clear the display buffer.
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.setCursor(10, 5);
display.print("DHT11 TEMPERATURE:");
display.setCursor(19, 37);
display.print("DHT11 HUMIDITY:");
display.display();
//begin************WiFi Setup*****************
WiFi.begin(STASSID, STAPSK);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected! IP address: ");
Serial.println(WiFi.localIP());
//end************WiFi Setup*****************
}
void loop() {
// Read humidity
byte RH = dht.readHumidity();
//Read temperature in degree Celsius
byte Temp = dht.readTemperature();
temperature[0] = Temp / 10 + '0';
temperature[1] = Temp % 10 + '0';
humidity[0] = RH / 10 + '0';
humidity[1] = RH % 10 + '0';
// print data on serial monitor
Serial.printf("Temperature = %02u°C\r\n", Temp);
Serial.printf("Humidity = %02u %%\r\n\r\n", RH);
// Clear the display buffer.
display.clearDisplay();
// print data on the SSD1306 display
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.setCursor(10, 5);
display.print("DHT11 TEMPERATURE:");
display.setCursor(19, 37);
display.print("DHT11 HUMIDITY:");
display.display();
display.setCursor(46, 20);
display.print(temperature);
display.setCursor(46, 52);
display.print(humidity);
display.drawRect(71, 20, 3, 3, WHITE); // Put degree symbol ( ° )
display.display();
//begin********HttpPost wait for WiFi connection
if ((WiFi.status() == WL_CONNECTED)) {
WiFiClient client;
HTTPClient http;
Serial.print("[HTTP] begin...\n");
// configure traged server and url
http.begin(client, "http://" SERVER_IP "/IOT/add_environments"); //HTTP
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
Serial.print("[HTTP] POST...\n");
// start connection and send HTTP header and body
String content = "temperatures=";
String str2 = temperature;
String str3 = "&humidity=";
String str4 = humidity;
String str5 = "&pressure=111";
content.concat(str2);
content.concat(str3);
content.concat(str4);
content.concat(str5);
//const String content = "temperatures=" + temperature + "&humidity=" + humidity +"&pressure=111";
int httpCode = http.POST(content);
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] POST... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK) {
const String& payload = http.getString();
Serial.println("received payload:\n<<");
Serial.println(payload);
Serial.println(">>");
}
} else {
Serial.printf("[HTTP] POST... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
//end********HttpPost wait for WiFi connection
delay(5000);
}
2. The server Web Background code runs
Use git Download the code locally , Revise it settings.py Database configuration information in the file , Get into Use_Mysql Catalog , Run the following command :
cd Use_Mysql/
sudo python3 manage.py runserver 0.0.0.0:80
Environment data added to the database :
Web The server received from ESP8266 Of HttpPost request :
Front-end get_environments request :
3. Experimental results show that
Access through the front-end address :http://116.198.42.221/IOT/get_environments/
Front end display effect :
ESP8266 + DHT11 + OLED Show the effect :
Overall renderings :
Video shows :
Graduation project --ESP8266 Self built networked temperature and humidity monitoring system
边栏推荐
- 1404. 将二进制表示减到1的步骤数
- 猿粉猿动力-开发者活动袭!
- Docker installs mysql5.7 and starts binlog
- Zzuli:1072 frog climbing well
- numpy. reshape, numpy. Understanding of transfer
- WordPress zibll sub theme 6.4.1 happy version is free of authorization
- 解决ValueError: Iterable over raw text documents expected, string object received.
- 中小型水库大坝安全自动监测系统解决方案
- Leecode question brushing-ii
- Data middle office: construction ideas and implementation experience of data governance
猜你喜欢
随机推荐
MySQL 45 talk | 05 explain the index in simple terms (Part 2)
Online yaml to JSON tool
MySQL export query results to excel file
Flink window mechanism (two waits and the last explanation)
numpy.reshape, numpy.transpose的理解
Yunda's cloud based business in Taiwan construction 𞓜 practical school
Typescript base type
Zzuli:1072 frog climbing well
How to design an awesome high concurrency architecture from scratch (recommended Collection)
Data middle office: six questions data middle office
Linked list in JS (including leetcode examples) < continuous update ~>
5GgNB和ng-eNB的主要功能
Detailed usage configuration of the shutter textbutton, overview of the shutter buttonstyle style and Practice
一看就会 MotionLayout使用的几种方式
联想混合云Lenovo xCloud,新企业IT服务门户
解决ValueError: Iterable over raw text documents expected, string object received.
[JVM] - memory partition in JVM
Concurrent wait/notify description
CSCI GA scheduling design
独立站卖家都在用的五大电子邮件营销技巧,你知道吗?