当前位置:网站首页>Internet of things? Come and see Arduino on the cloud
Internet of things? Come and see Arduino on the cloud
2022-06-24 20:21:00 【u012804784】
High quality resource sharing
| Learning route guidance ( Click unlock ) | Knowledge orientation | Crowd positioning |
|---|---|---|
| 🧡 Python Actual wechat ordering applet 🧡 | Progressive class | This course is python flask+ Perfect combination of wechat applet , From the deployment of Tencent to the launch of the project , Create a full stack ordering system . |
| Python Quantitative trading practice | beginner | Take you hand in hand to create an easy to expand 、 More secure 、 More efficient quantitative trading system |

author :HelloGitHub-Anthony
Here is HelloGitHub Introduction of open source hardware development platform Arduino Series of tutorials for .
- Chapter one :Arduino Introduction and development environment construction
- Second articles : Make temperature and humidity display
Last article , We explained how to install Arduino support library 、DHT 11 Temperature and humidity sensors and OLED Use of screen , And use Arduino A small temperature and humidity display is made .
In this particular, we pay attention to All things connected Era , Let's Arduino Temperature and humidity “ On the cloud ” play , There is a scientific name called the Internet of things .
The Internet of things (IoT) Is a network of physical objects , These physical objects are embedded with sensors 、 Software and other technologies , So that it can establish connections with other devices and systems and exchange data through the Internet .
Do you feel a little taller in an instant , But don't worry about the knowledge in this issue , Because the profound I will not !
Today we're going to talk about : How to put the temperature and humidity equipment made in the last phase into the cloud , Through the Internet of things platform Real time data upload and Remote control equipment . The implementation will Arduino The temperature and humidity data measured by the equipment are uploaded to the Internet of things platform , Then the receiving platform sends instructions to the control equipment LED Light switch .
Have you started to sharpen your fists ? Now let's start “ On the cloud ”!
One 、 Realize networking function
1.1 Module introduction
First , If you want to Arduino Servers connected to the Internet of things platform , It is necessary to enable the device to connect to the network first ( Like at home WiFi), Here we need to use ESP-01(s) modular , To achieve this function .
Its usage is similar to that of the components described above , Just use VCC(3.3v)、GND、TX、RX Four lines , And Arduino communicate . What I use here is ESP-01+ Adapter plate , The adapter board realizes 5v->3.3v And Rx and Tx Leading out of the interface , Convenient for subsequent use .

majority ESP-01(s) The module leaves the factory , It's all built in AT Command firmware , When in use, you only need to send to the module AT Command to connect to the network 、 Data transmission and other operations .
About what is AT Instructions , Simply speaking, it is a kind of equipment room Communication message specification , More specific definitions and application scenarios can be understood by readers themselves .
1.2 Module USES
ESP-01 The module wiring mode is as follows :
- GND -> GND
- VCC -> 3.3v( Separate modules ) 5.5v( With adapter plate )
- Tx -> Rx
- Rx -> TX
Use of AT The instructions are as follows :
- AT+RST: Reset module
- AT+CWMODE=1: Switch mode
- AT+CWQAP: To break off WiFi Connect
- AT+CWJAP=“WiFi name ”,“ password ”: Connect WiFi
- AT+CIPSTART=“TCP”,“IP”, port : Connect to server
- AT+CIPMODE=1: Switch to TCP Passthrough mode
- AT+CIPSEND: Start sending data
1.3 Code
Arduino Connect WiFi Code for :
#include
boolean at\_exec(char *data, char *keyword, unsigned long time\_out)
{
Serial.println(data);
Serial.flush();
delay(100); // Waiting response
unsigned long start = millis();
while (Serial.available() < strlen(keyword))
{
if (millis() - start > time_out)
return false;
}
if (Serial.find(keyword))
return true;
else
return false;
while (Serial.available())
Serial.read(); // Clear the serial buffer
}
void setup()
{
Serial.begin(115200);
while (!at_exec("AT+RST", "OK", 1000));
while (!at_exec("AT+CWMODE=1", "OK", 1000));
while (!at_exec("AT+CWQAP", "OK", 1000));
while (!at_exec("AT+CWJAP=\"HelloGithub\",\"PassWord\"", "WIFI CONNECTED", 2000));
while (!at_exec("AT+CIPSTART=\"TCP\",\"183.230.40.40\",1811", "CONNECT", 1000));
while (!at_exec("AT+CIPMODE=1", "OK", 500));
while (!at_exec("AT+CIPSEND", "OK", 500));
//Serial.println("* product ID# Authentication information # Script name *"); // How to obtain this information is discussed below
}
Be careful :
- Disconnect before downloading Arduino and ESP-01 The connection of , Otherwise, the download may fail
- perform
AT+CIPSENDafter , The module will no longer respond AT Instructions , If you need to modify the configuration, you must power off and restart the module - Remember to change
AT+CWJAPParameters of , Corresponding WiFi User name and password
After burning , The connection module restarts Arduino. In the router management interface “ Connected device ” page , See our WiFi equipment , That means success !

Two 、 Internet of things platform
Here we are using OneNet Internet of things platform , It is the Internet of things created by China Mobile PaaS Open platform , Through this platform, you can easily ( free ) Implement the device ” On the cloud “.

below , It will cover the process from registration to cloud on device , All cloud configuration steps required .
2.1 register
open OneNet Official website , Click on the “ register ” Registered account .

2.2 New product
After completing the login account registration , Click on the “ Console ” Go to the control page .
Click after entering “ All products and services ”->“ Multi protocol access ”:

stay “ Multi protocol access interface ” choice TCP transparent transmission -> Add product :

Fill in the relevant information in the pop-up sidebar ,“ Product industry ” and “ Category ” Just fill it in , Finally, click “ determine ” Complete new product .

2.3 Add equipment
Find the product I just created. Mine is “HelloGitHub”, Then click... In the left column “ The equipment list ”, Click on the new page “ Add equipment ”, After filling in the relevant information, click “ add to ”, Complete the operation of adding equipment .

2.4 Write data parsing script
Next , We configure the cloud data parsing script , Don't write it yourself and download it directly Official script You can use it if you change it locally .

In the extracted and downloaded folder , find sample.lua In the file device_timer_init function ( The first 303 That's ok ), Change to the following :
function device\_timer\_init(dev)
-- Send the light switch command regularly --
dev:timeout(0)
dev:add(10,"open","open")
dev:add(12,"close","close")
end
find device_data_analyze function ( At the end of the file ), Change to the following :
function device\_data\_analyze(dev)
local t={}
local a=0
local s = dev:size()
-- We define One time transmission ten byte , Respectively temperature humidity --
add_val(t,"Temperature",a,dev:bytes(1,5))
add_val(t,"Humidity",a,dev:bytes(6,5))
dev:response()
dev:send("received")
return s,to_json(t)
end
If you are interested in using scripts , You can view code comments and access documents on the official website , There will be no more explanation here .
2.5 Upload script
After saving the file , Go back to the just opened “ The equipment list ” Click on “ Upload parsing script ”.


thus , Cloud configuration is complete .
2.6 Connect to the Internet of things platform
modify 1.3 Code for , take “ How to obtain this information is discussed below ” Change this line of code to :
Serial.println("* product ID#ILoveHelloGitHub#HG*");
After configuring the cloud , To obtain the product ID、 Authentication information 、 Script name Equal parameter , Replace to the corresponding position .(* product ID# Authentication information # Script name *)
Last , Re - burn the code and restart ESP-01 modular . Wait a moment , Refresh in the cloud “ The equipment list ” page , See our equipment , Prove that the device is successfully connected to the Internet of things platform .

3、 ... and 、Arduino On the cloud
Go through the front matting , We “ On the cloud ” The most exciting part of our journey is coming . Upload the temperature and humidity data of the environment where the device is located to the cloud !
3.1 Code
Since it is uploading temperature and humidity data , You need us Last issue Speak of the DHT11 modular ( Temperature and humidity sensor ), Then combine the code of connecting the network in this issue , It can be finished in minutes .
But to make the project more interesting , I added an additional parsing IOT platform to send commands , Remote control switch LED Function of .
The code snippet is as follows :
void setup()
{
// Change to your own cloud parameters
Serial.println("* product ID#ILoveHelloGitHub#HG*");
}
// According to the received from the serial port character string Execute the corresponding instruction
bool command\_parse(String command){
...
if (command == "open")
{
digitalWrite(LED_BUILTIN, HIGH);
} else if (command == "close")
{
digitalWrite(LED_BUILTIN, LOW);
}
}
Complete code :https://github.com/HelloGitHub-Team/Article/blob/master/contents/Other/Arduino/3/code.cpp
Last , Modify... In the complete code WiFi Name and password , as well as product ID after , Re - burn the code .
3.2 Upload temperature and humidity data
Just a moment later , View the Internet of things platform “ Equipment information ”, If you see Arduino Uploaded indoor temperature and humidity information , It proves that our code runs successfully .

3.3 Remote control
The following is a demonstration of how to use the Internet of things platform , Switch of remote control lamp .
Open the Internet of things platform , Click on “ Device interface ” Of “ Give orders ”, Select... On the pop-up form “ character string ” Options , Input “open” or “close” Instructions .

Come here , The remote control is completed Arduino built-in LED Light on / Closing effect !

success ! And the flower
Four 、 summary
This article , combination Arduino、 sensor 、WiFi as well as OneNet Internet of things platform , By doing and talking , It describes the whole process of a device from networking to cloud . Although it is an entry-level tutorial , But this knowledge can already help you accomplish , Such as smart switches 、 Practical and interesting projects such as automatic feeders .
Do not underestimate every small progress , Every step is worth a thousand miles .
If the wave of mobile Internet has passed , Will there be any in the next wave The Internet of things And the shadow of ? Anyway, I don't think it's too much for me , What do you think of that ? Welcome to comment on it .
thus , Whole Arduino Series of tutorials , It's over here . The end ! Sprinkle the flowers again
hope ,HelloGitHub Of Arduino Series of tutorials , It can arouse your interest in the Internet of things , After all, interest is the best teacher .
These are the contents of this issue , Here is HelloGitHub Share GitHub The interesting 、 Entry-level open source projects .
Thank you for reading , If you think the content is good , Do remember to like 、 Leaving a message. 、 Share , See you next time !
边栏推荐
- Capacitive inching touch switch module control (stm32f103c8t6)
- Stackoverflow 年度报告 2022:开发者最喜爱的数据库是什么?
- 两位湖南老乡,联手干出一个百亿IPO
- The difference between the lazy man mode and the hungry man mode
- unity实战之lol技能释放范围
- 【Go语言刷题篇】Go从0到入门4:切片的高级用法、初级复习与Map入门学习
- Using dynamic time warping (DTW) to solve the similarity measurement of time series and the similarity identification analysis of pollution concentration in upstream and downstream rivers
- Bat learning notes
- Zadig + 洞态 IAST:让安全溶于持续交付
- Ribbon source code analysis @loadbalanced and loadbalancerclient
猜你喜欢

LCD12864 (ST7565P) Chinese character display (STM32F103)

Test drive citus 11.0 beta (official blog)
![[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map](/img/3a/db240deb4c66b219ef86f40d4c7b7d.png)
[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map

Working for 6 years with a monthly salary of 3W and a history of striving for one PM

Camera module and hardware interface of Camera1 camera

两位湖南老乡,联手干出一个百亿IPO

UART communication (STM32F103 library function)

Bytebase rejoint la communauté de base de données open source d'alicloud polardb

Digital twin industry case: Digital Smart port

R for Data Science (note) -- data transformation (select basic use)
随机推荐
Vs2017 add header file path method
Geoscience remote sensing data collection online
视频平台如何将旧数据库导入到新数据库?
Introduction: continuously update the self-study version of the learning manual for junior test development engineers
Saltstack state state file configuration instance
Maps are grouped according to the values of the passed in parameters (similar to database groupby)
What about the Golden Angel of thunder one? Golden Angel mission details
How does the video platform import the old database into the new database?
Predicate
Where are Xiaomi mobile phone's favorite SMS and how to delete them
What is showcase? What should showcase pay attention to?
Data backup and recovery of PgSQL
Redis installation of CentOS system under Linux, adding, querying, deleting, and querying all keys
Stackoverflow 年度报告 2022:开发者最喜爱的数据库是什么?
R for Data Science (note) -- data transformation (select basic use)
R for Data Science (notes) -- data transformation (used by filter)
用手机摄像头就能捕捉指纹?!准确度堪比签字画押,专家:你们在加剧歧视
First understand redis' data structure - string
IP address to integer
Bytebase rejoint la communauté de base de données open source d'alicloud polardb