当前位置:网站首页>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
边栏推荐
- Office is being updated and the application cannot start normally
- 【Linux】——使用xshell在Linux上安装MySQL及实现Webapp的部署
- [Verilog quick start of Niuke online question brushing series] ~ one out of four multiplexer
- TypeScript基础类型
- 【C语言练习——打印空心正方形及其变形】
- 解决ValueError: Iterable over raw text documents expected, string object received.
- Line animation
- Oracle 条件、循环语句
- Maskrcnn,fast rcnn, faster rcnn优秀视频
- What is the difference between AC and DC?
猜你喜欢
![[Verilog quick start of Niuke online question brushing series] ~ one out of four multiplexer](/img/1f/becda82f3136678c58dd8ed7bec8fe.png)
[Verilog quick start of Niuke online question brushing series] ~ one out of four multiplexer

jsp连接oracle实现登录注册(简单)

Sharing | intelligent environmental protection - ecological civilization informatization solution (PDF attached)

Yin Yang master page

联想混合云Lenovo xCloud,新企业IT服务门户

Interpretation of cloud native microservice technology trend

开发者的时代红利在哪里?

MySQL 45 talk | 05 explain the index in simple terms (Part 2)

What does mysql---where 1=1 mean
![Video tutorial on website operation to achieve SEO operation [21 lectures]](/img/1f/9ae2ed5bfec5749c764630d1daccea.jpg)
Video tutorial on website operation to achieve SEO operation [21 lectures]
随机推荐
Solution of dam safety automatic monitoring system for medium and small reservoirs
Data warehouse: financial / banking theme layer division scheme
学术搜索相关论文
TypeScript接口
原动力×云原生正发声 降本增效大讲堂
qtcanpool 知 05:无边框
When using the MessageBox of class toplevel, a problem pops up in the window.
Share a powerful tool for factor Mining: genetic programming
Introduction to uicollectionviewdiffabledatasource and nsdiffabledatasourcesnapshot
Shutter nestedscrollview sliding folding head pull-down refresh effect
Qtcanpool knowledge 07:ribbon
Yunda's cloud based business in Taiwan construction 𞓜 practical school
Install kubebuilder
1404. number of steps to reduce binary representation to 1
CSCI GA scheduling design
JS中的链表(含leetcode例题)<持续更新~>
Maskrcnn,fast rcnn, faster rcnn优秀视频
To batch add background pictures and color changing effects to videos
Jenkins继续集成2
Create NFS based storageclass on kubernetes