当前位置:网站首页>(ultra detailed onenet TCP protocol access) arduino+esp8266-01s access to the Internet of things platform, upload real-time data collection /tcp transparent transmission (and how to obtain and write L
(ultra detailed onenet TCP protocol access) arduino+esp8266-01s access to the Internet of things platform, upload real-time data collection /tcp transparent transmission (and how to obtain and write L
2022-07-06 13:20:00 【Lunan wind】
Catalog
Experiment preparation (onenet)
Search china mobile onenet, Login after registration , Access control
Add device information (lua Script add )
test esp8266 modular ( Not connected to MCU )
onenet The platform outputs data in real time
Preface
I have learned from the last article ds18b20 Simple use of temperature sensor ( How to write drivers for subsequent updates ) as well as lcd1602 Show , But considering some special application scenarios , For example, the collection point is too far away 、 Multipoint acquisition, etc , Labor is time-consuming and laborious , Need remote monitoring ?
At first I wanted to choose GPRS Module for transmission , A search found that even the monitoring applet has been done , You can use it (bushi), But the price is a little expensive , Until I found out esp8266 modular , Choose here esp8266-01s( Suggest ), The price is low , Powerful , I don't say much nonsense , Let's start preparing .
Experimental equipment
esp8266-01s,USB to TTL modular ( There is the best , No, not much ), There are several DuPont lines
DS18B20 Temperature sensor
arduino mega2560( The same applies to other models )
Experiment preparation (onenet)
Search china mobile onenet, Login after registration , Access control
Figure 1
choice TCP transparent transmission ( I've added one item here before ) Click on the right to add products ( Feel free to fill in )
Figure 2
Figure 3
Figure 4
Add a device to the device list
Figure 5
Figure 6
Figure 7
Use luastudio Tool open ,lua The script statement is very long , In order to help novice developers, just introduce in detail device_data_analyze(dev) Function USES , Other details can be learned Developing documents
More sentences , Properly understand the notes , It's useful later
Json
OneNET The basic message format of the system is designed as json Format , Its data can be mapped into virtual tables , In the data Key Corresponding to the column of the table ,Value Corresponding column value
You can convert a set of data represented into a string , Then you can easily pass this string between networks or programs , And restore it to the data format supported by each programming language when necessary , Easy to machine parse and generate , And effectively improve the network transmission efficiency
Add device information (lua Script add )
Add custom code to the parsing function
function device_data_analyze(dev)
local t={}
local a=0
-- Add user-defined code --
-- for example : --
local s = dev:size()
add_val(t,"ds18b20_test",a,dev:bytes(1,s),"yqer123")
dev:response()
dev:send("received")
-- return $1,$2 --
-- for example : --
return s,to_json(t)
end
t--table Data point storage ,“ds18b20_test” Data stream name , There is no need to create... In the equipment ,a-- Time stamp , by 0 Indicates the current time
dev:bytes(1,s) Return the data ,1, Data starting point ,s Number of data bits , If not modified, the default data length is , When multiple devices are connected, they can be captured according to the acquisition bits of each device in the data packet
Then connect the device authentication information , Transfer to the device in the product
Save after modification , Upload lua To platform , After the serial port sends a message, the device is connected with lua Script Association
test esp8266 modular ( Not connected to MCU )
Add an interrupt first , take it easy , Let's test esp8266 Whether the module is normal
esp826601s | USB to TTL |
3V3 | 3V3 |
RX | TX |
TX | RX |
GND | GND |
Table 1
Figure 8
Access computer , Open the serial port debugging assistant ( By the way, turn on the mobile hotspot settings wifi Name and password , Don't use Chinese , Try to be simple )
Figure nine
AT+UART=9600,8,1,0,0
( enter )
Set up WiFi Application mode AT+CWMODE=3(1、station Pattern 2、AP Pattern 3、station+AP)
At each step, pay attention to enter and then send
Figure ten
AT+CWJAP="HUAWEI nova3","12345678#%"
Figure eleven
Figure twelve
AT+CIPSTART="TCP","183.230.40.40",1811
Fig13
There are so many pictures that they seem lengthy , Direct orders AT+CIPMODE=1( Passthrough mode ), return OK Later AT+CIPSEND( To transmit data )
Here are two steps
Fig14
Communicate with server
Instructions * product id( Not a device id)# Device authentication information # Script name ( Not necessarily the script file name )*
Fig15
Get a response , Show online
Fig15
Access the MCU
arduinomega2560 | esp826601s | DS18B20 Temperature sensor |
TX | RX | |
RX | TX | |
7 | DAT | |
GND | GND | GND |
5V 3.3V( Be careful ) | 3.3V | VCC |
Table two
The whole program
#include <OneWire.h>
#include <DallasTemperature.h> //ds18b20 library
#define Onewire_bus 7 //ds18b20 Connect 7 Pin
OneWire oneWire(Onewire_bus);
DallasTemperature sensors(&oneWire);
//boolean Successfully returns true, Failure to return false
boolean send_cmd(String data, char *keyword)
{
boolean result = false;
if (data != "") // about tcp Connection command , Just wait for the second reply
{
Serial.println(data); // send out AT Instructions
}
if (data == "AT") // seek esp8266 Whether it works properly
delay(1000);
else
while (!Serial.available()); // wait for wifi Module response
delay(200);
if (Serial.find(keyword)) // Return keyword judgment , such as ok
{
return true;
}
else
{
return false;
}
while (Serial.available()) Serial.read(); // Clear the serial buffer
delay(500);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while (!send_cmd("AT", "OK"));
while (!send_cmd("AT+CWMODE=3", "OK")); // Working mode
while (!send_cmd("AT+CWJAP=\"HUAWEI nova3\",\"1234567#%$\"", "OK")); // Access AP
while (!send_cmd("AT+CIPSTART=\"TCP\",\"183.230.40.40\",1811", "OK")); // Access server
while (!send_cmd("AT+CIPMODE=1", "OK")); // Passthrough mode
while (!send_cmd("AT+CIPSEND", ">")); // Start sending
Serial.println("*514523#yqer123#test1*"); // Send message information , product ID+ Equipment authentication code + Script name
}
void loop() {
// put your main code here, to run repeatedly:
delay(50);
// Serial.print(" Get the temperature :"); // Send a few words
sensors.requestTemperatures(); // Get the temperature
// Serial.println(sensors.getTempCByIndex(0));
float temp=sensors.getTempCByIndex(0);
Serial.print(String(temp));
}
Serial port monitoring results , Slow response , The delay can be appropriately increased
onenet The platform outputs data in real time 
matters needing attention
This test adopts hard serial port , Before burning the program , Single chip microcomputer TX,RX No access , Otherwise, you will not be able to upload
Try not to live wire
Add more pictures after , No sorting
Fill in the missing place
The figure is convenient. Only one device is connected in this experiment , Multi device scenarios are similar
//------------------------------------- Split line -------------------------------------------
The previous single equipment has been very detailed
The same goes for multiple devices , Only need lua Assign the data flow to the corresponding device in the ( Bind through device authentication information ) That's all right.
If you need me, I'll continue to do more
Add multiple devices , Set different authentication information and record it
open lua Script , Add device authentication information
dev.bytes Select the starting point and number of digits
The device is online , Open data flow observation
The intercepted segment has been sent to each device
matters needing attention 2
The program segment only needs to bind the product id And the authentication information of one of the devices , Other devices are done in the script
Multi data output format
Serial.print(String(int(wd))+String(int(sd))+ String(float(deepcm))+String(int(TU_value))+String(int(tdsValue)))
The visualization operation will be updated later ( Application development seems to be castrated ) Or other MCU applications
Other access protocols are also welcome
Sorting is not easy to , Praise is my motivation to update
边栏推荐
- ROS machine voice
- 图书管理系统小练习
- Ten minutes to thoroughly master cache breakdown, cache penetration, cache avalanche
- [rtklib 2.4.3 B34] version update introduction I
- View UI Plus 发布 1.2.0 版本,新增 Image、Skeleton、Typography组件
- Data manipulation language (DML)
- 错误:排序与角标越界
- Redis介绍与使用
- Common method signatures and meanings of Iterable, collection and list
- Record: the solution of MySQL denial of access when CMD starts for the first time
猜你喜欢
Introduction and use of redis
arduino+水位传感器+led显示+蜂鸣器报警
Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing
System design learning (III) design Amazon's sales rank by category feature
阿里云微服务(三)Sentinel开源流控熔断降级组件
架构师怎样绘制系统架构蓝图?
View UI plus released version 1.2.0 and added image, skeleton and typography components
系统设计学习(三)Design Amazon‘s sales rank by category feature
Several high-frequency JVM interview questions
Data manipulation language (DML)
随机推荐
[GNSS data processing] Helmert variance component estimation analysis and code implementation
记录:下一不小心写了个递归
12 excel charts and arrays
121 distributed interview questions and answers
165. Compare version number - string
FileInputStream和BufferedInputStream的比较
View UI Plus 发布 1.3.0 版本,新增 Space、$ImagePreview 组件
继承和多态(下)
Alibaba cloud microservices (I) service registry Nacos, rest template and feign client
What are the advantages of using SQL in Excel VBA
Iterable、Collection、List 的常见方法签名以及含义
ROS machine voice
[while your roommate plays games, let's see a problem]
How to ensure data consistency between MySQL and redis?
Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing
[GNSS] robust estimation (robust estimation) principle and program implementation
arduino+DS18B20温度传感器(蜂鸣器报警)+LCD1602显示(IIC驱动)
Employment of cashier [differential constraint]
[rtklib] preliminary practice of using robust adaptive Kalman filter under RTK
抽象类和接口