当前位置:网站首页>Esp8266wifi development board collects temperature and humidity data and uploads them to the Internet of things platform
Esp8266wifi development board collects temperature and humidity data and uploads them to the Internet of things platform
2022-06-12 01:00:00 【ThingsPanel】
This time, I will mainly explain how to use open source WIFI Internet of things development board ESP-12FWIFI collection DHT11 The data of digital temperature and humidity sensor passes through OLED Exhibition , And pass MQTT Use the collected temperature and humidity data JSON Send the format to the open source Internet of things platform ThingsPanel. And pass ThingsPanel The free temperature and humidity plug-in of the open source platform displays relevant data .
One 、 Hardware preparation
The hardware of this time adopts the new technology ESP-12FWIFI The Internet of things development board is implemented as hardware . Design to all hardware as follows :
ESP-12FWIFI Internet of things development board :
OLED display :
DHT11 Temperature and humidity sensor :
USB cable :
Two 、 Hardware connection
take DHT11 The temperature and humidity sensor is plugged into ESP-12FWIFI Peripheral interface of Internet of things development board , As shown in the figure below :
take OLED The display is plugged into ESP-12FWIFI Internet of things development board 4PIN On port , As shown in the figure below :
Finally, put ESP-12FWIFI The Internet of things development board passes USB Connect the cable to the computer USB On the interface , As shown in the figure below :
3、 ... and 、 Code
Anxinco WINDOWS Construction and use instructions of development environment , Please refer to the installation instructions downloaded from the official website of Anxin :
http://aiclouds3.0-docs.aithinker.com/#/2.device/configuration_windows
After the development environment is built , Through Anxin, you can WINDOWS development environment AiThinkerIDE Open the sample code provided .
The complete code is self fetched :
link :https://pan.baidu.com/s/11arto289Rckv3zEBQ_zn2Q
Extraction code :f2dv
If you have any questions, please consult bloggers or add groups :QQ260150504
Or forum questions :
http://forum.thingspanel.cn/
Hardware Taobao purchasing address ( Jiyi Internet of things ):
https://item.taobao.com/item.htm?spm=a21dvs.23580594.0.0.3bc13d0dnUfTY4&ft=t&id=668712619774
DHT11 Temperature and humidity acquisition part code :
u8 ICACHE_FLASH_ATTR DHT11_Read_Data_Complete(void)
{
u8 C_delay_time = 0; // Time delay
// start-up DHT11 transmission _ success
//-----------------------------------------------------------
if(DHT11_Start_Signal_JX() == 0) // DHT11: Output start signal -> Receive response signal
{
DHT11_Data_Array[0] = DHT11_Read_Byte(); // humidity _ Integers _ part
DHT11_Data_Array[1] = DHT11_Read_Byte(); // humidity _ decimal _ part
DHT11_Data_Array[2] = DHT11_Read_Byte(); // temperature _ Integers _ part
DHT11_Data_Array[3] = DHT11_Read_Byte(); // temperature _ decimal _ part
DHT11_Data_Array[4] = DHT11_Read_Byte(); // Check byte
// If this is the high level of the last bit of data , Then wait for it to end
//-----------------------------------------------------------
while(GPIO_INPUT_GET(GPIO_ID_PIN(5))==1 && C_delay_time<100)
{
os_delay_us(1); // 1us timing
C_delay_time++;
}
C_delay_time = 0 ; // Low level timing starts
// The low level of the end signal is timed for a long time
//-------------------------------------------------------
while(GPIO_INPUT_GET(GPIO_ID_PIN(5))==0 && C_delay_time<100)
{
os_delay_us(1); // 1us timing
C_delay_time++;
}
//-----------------------------------------------------------
if(C_delay_time >= 100)
return 1; // return 1, Express : The low level of the end signal will last for a long time
// data verification
//-----------------------------------------------
if( DHT11_Data_Array[4] ==
DHT11_Data_Array[0] + DHT11_Data_Array[1] +
DHT11_Data_Array[2] + DHT11_Data_Array[3] )
{
// Read DHT11 End of data ,ESP8266 To take over DHT11 The signal line
//-----------------------------------------------------------
// Determine whether the temperature is 0℃ above
//----------------------------------------------
if((DHT11_Data_Array[3]&0x80) == 0)
{
DHT11_Data_Array[5] = 1; // >=0℃
}
else
{
DHT11_Data_Array[5] = 0; // <0℃
DHT11_Data_Array[3] &= 0x7F; // Correct the decimal part of the temperature
}
return 0; // return 0, Express : Temperature and humidity read successfully
}
else return 3; // return 3, Express : Check error
}
//-----------------------------------------------------
else return 2; // return 2, Express : start-up DHT11 transmission , Failure
}
OLED Display part of the code :
void ICACHE_FLASH_ATTR OS_Timer_1_cb(void)
{
if(DHT11_Read_Data_Complete() == 0) // Read DHT11 Temperature and humidity value
{
// The temperature exceeds 30℃,LED bright
//----------------------------------------------------
if(DHT11_Data_Array[5]==1 && DHT11_Data_Array[2]>=30)
GPIO_OUTPUT_SET(GPIO_ID_PIN(4),0); // LED bright
else
GPIO_OUTPUT_SET(GPIO_ID_PIN(4),1); // LED destroy
// Serial port output temperature and humidity
//---------------------------------------------------------------------------------
if(DHT11_Data_Array[5] == 1) // temperature >= 0℃
{
os_printf("\r\n humidity == %d.%d %RH\r\n",DHT11_Data_Array[0],DHT11_Data_Array[1]);
os_printf("\r\n temperature == %d.%d ℃\r\n", DHT11_Data_Array[2],DHT11_Data_Array[3]);
}
else // if(DHT11_Data_Array[5] == 0) // temperature < 0℃
{
os_printf("\r\n humidity == %d.%d %RH\r\n",DHT11_Data_Array[0],DHT11_Data_Array[1]);
os_printf("\r\n temperature == -%d.%d ℃\r\n",DHT11_Data_Array[2],DHT11_Data_Array[3]);
}
// OLED Display temperature and humidity
//---------------------------------------------------------------------------------
DHT11_NUM_Char(); // DHT11 The data value is converted into a string
OLED_ShowString(0,2,DHT11_Data_Char[0]); // DHT11_Data_Char[0] == 【 Humidity string 】
OLED_ShowString(0,6,DHT11_Data_Char[1]); // DHT11_Data_Char[1] == 【 Temperature string 】
//sprintf(wifi_send_buf,WIFI_SEND_MESSAGE,DEVID,temp,hum);
// MQTT_OnConnected(&mqttClient, mqttConnectedCb); // Set up 【MQTT Successfully connected 】 Another way to call a function
}
}
MQTT Communication upload part code :
void ICACHE_FLASH_ATTR mqtt_timer(void *arg)
{
char Buf_Shadow_Report_Data[512] = {
0}; // Report data cache
MQTT_Client* client = (MQTT_Client*)arg;
// If it is currently [MQTT_DATA] state , Then the survival timing operation
//--------------------------------------------------------------------------
if (client->connState == MQTT_DATA) // MQTT_DATA
{
//#################################################################################################################################
C_Report_DHT11_Data++;
if(C_Report_DHT11_Data>=5) // 5 Report data every second
{
C_Report_DHT11_Data = 0 ;
if(DHT11_Read_Data_Complete() == 0) // Read DHT11 Temperature and humidity value
{
os_sprintf( Buf_Shadow_Report_Data,Format_JSON_TH_ESP8266_JX,TOKEN_DEVID,TOKEN_TYPE,// format JSON character string
DHT11_Data_Array[2],DHT11_Data_Array[3],
DHT11_Data_Array[0],DHT11_Data_Array[1] );
os_printf("\r\n------ Shadow_Report_Data:%s -- ",Buf_Shadow_Report_Data); // Data reported to the object shadow
os_printf("Report_Data_Length:%d ------\r\n\r\n",strlen(Buf_Shadow_Report_Data)); // Length of reported data
// MQTT_Publish(client,"thingspaenl.operation",Buf_Shadow_Report_Data,strlen(Buf_Shadow_Report_Data),0,0);
MQTT_Publish(client,"thingspaenl.operation4444",Buf_Shadow_Report_Data,strlen(Buf_Shadow_Report_Data),0,0);
system_os_post(MQTT_TASK_PRIO, 0, (os_param_t)client); // Arrange a task
}
}
//#################################################################################################################################
client->keepAliveTick ++; // client (ESP8266) Heartbeat count ++
// Judge client (ESP8266) Heartbeat count ?> Keep connected 1/2 Time
//--------------------------------------------------------------------------------------------------------------------------
if (client->keepAliveTick>(client->mqtt_state.connect_info->keepalive/2)) //【 notes : The official routine is : Determine whether the connection duration is exceeded 】
{
client->connState = MQTT_KEEPALIVE_SEND; // MQTT_KEEPALIVE_SEND
system_os_post(MQTT_TASK_PRIO,0,(os_param_t)client);// Arrange a task
}
}
// Reconnection waiting time : After entering the reconnection request state , Need to wait 5 second , Then reconnect
//--------------------------------------------------------------------------
else if (client->connState == TCP_RECONNECT_REQ) // TCP Reconnection request ( wait for 5 second )
{
client->reconnectTick ++; // Reconnection timing ++
if (client->reconnectTick > MQTT_RECONNECT_TIMEOUT) // Reconnection request exceeded 5 second
{
client->reconnectTick = 0; // Reconnection timing = 0
client->connState = TCP_RECONNECT; // TCP Reconnect the
system_os_post(MQTT_TASK_PRIO, 0, (os_param_t)client); // Arrange a task
// Reconnect and wait for the timing to end
//-----------------------------------------------------------------
if (client->timeoutCb) // Callback function not created
client->timeoutCb((uint32_t*)client);
}
}
// TCP Send successfully / Message sending 5 The second timer is over => End of message sending (sendTimeout=0)
//----------------------------------------------------------------
if (client->sendTimeout>0) // send out MQTT When the message ,sendTimeout=5
client->sendTimeout --; // sendTimeout Decrement per second ( until =0)
}
Four 、OLED Check the temperature and humidity data 
5、 ... and 、ThingsPanel Platform creation business
Demo platform 、 For installation and plug-in development and installation, please refer to the official website tutorial :
http://wiki.thingspanel.cn/index.php?title=%E9%A6%96%E9%A1%B5
After successful login, start to create business , Video tutorial reference :
https://www.bilibili.com/video/BV1bu41117cX?spm_id_from=333.999.0.0
1、 Log in to the home page 
2、 Business - newly added - Enter a name - preservation 

3、 Editing business
Click Edit business 
Enter the asset name 、 Asset alias 、 Choose plug-ins 
边栏推荐
- In the field of enabling finance, the transformation of state secrets makes security compliance more solid
- 2022 edition of global and Chinese on silicon liquid crystal market supply and demand research and prospect Trend Forecast Report
- 1、 Getting started with flutter learn to write a simple client
- Lambda quick start
- Why are the values of ordereddict not equal- Why are the values of an OrderedDict not equal?
- Before applying data warehouse ODBC, you need to understand these problems first
- C language preprocessing instructions - learning 21
- Lambda中间操作sorted
- Lambda intermediate operation distinct
- [case] building a universal data lake for Fuguo fund based on star ring technology data cloud platform TDC
猜你喜欢

Data visualization big screen - big screen cloud minimalist user manual

Sharing of Manta network parallel chain solutions by Hufu Research Institute

Anfulai embedded weekly report (issue 254): February 21, 2022 to February 27, 2022

What are the advantages of Tiktok applet

Ms-hgat: information diffusion prediction based on memory enhanced sequence hypergraph attention network

Devops landing practice drip and pit stepping records - (1)

Flutter 使用本地图片

Some suggestions on writing code to reproduce the paper!

验证码是自动化的天敌?看看阿里P7大神是怎么解决的

Low code platform design exploration, how to better empower developers
随机推荐
Lambda intermediate operation map
Started with trust and loyal to profession | datapipeline received a thank you letter from Shandong city commercial bank Alliance
Global and Chinese maleic anhydride polypropylene industry investment analysis and prospect trend forecast report 2022 Edition
Explain asynchronous tasks in detail: the task of function calculation triggers de duplication
How to guarantee industrial control safety: system reinforcement
Dr. wangxiting: understanding interpretable recommendation from the perspective of knowledge map and natural language generation
A day when the script boy won't be killed
[answer] should the role with one end of the reflexive association be called "current version"
C language pointer - learning 22
在玻璃上构建电路
Devops landing practice drip and pit stepping records - (1)
Online Fox game server - room configuration wizard - component attribute and basic configuration assignment
JDBC exercises
关于 MySQL 修改密码失败
验证码是自动化的天敌?看看阿里P7大神是怎么解决的
How to optimize the opening speed of website pages to improve the experience?
Chapter V - Fund professional ethics
'virtue and art' in the field of recurrent+transformer video recovery
Tianjin Port coke wharf hand in hand map flapping software to visually unlock the smart coke port
Argodb 3.2 of star ring technology was officially released to comprehensively upgrade ease of use, performance and security