当前位置:网站首页>(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
边栏推荐
- 用栈实现队列
- Fairygui bar subfamily (scroll bar, slider, progress bar)
- Experience summary of autumn recruitment of state-owned enterprises
- Introduction pointer notes
- IPv6 experiment
- Answer to "software testing" exercise: Chapter 1
- 六种集合的遍历方式总结(List Set Map Queue Deque Stack)
- Pride-pppar source code analysis
- String class
- E-R graph to relational model of the 2022 database of tyut Taiyuan University of Technology
猜你喜欢
Inheritance and polymorphism (I)
The earth revolves around the sun
View UI plus released version 1.2.0 and added image, skeleton and typography components
学编程的八大电脑操作,总有一款你不会
面渣逆袭:Redis连环五十二问,三万字+八十图详解。
XV Function definition and call
Rt-ppp test using rtknavi
One article to get UDP and TCP high-frequency interview questions!
TYUT太原理工大学2022数据库题库选择题总结
Several high-frequency JVM interview questions
随机推荐
西安电子科技大学22学年上学期《射频电路基础》试题及答案
Atomic and nonatomic
167. Sum of two numbers II - input ordered array - Double pointers
Counter attack of flour dregs: redis series 52 questions, 30000 words + 80 pictures in detail.
如何保障 MySQL 和 Redis 的数据一致性?
(超详细二)onenet数据可视化详解,如何用截取数据流绘图
Voir ui plus version 1.3.1 pour améliorer l'expérience Typescript
121 distributed interview questions and answers
MySQL 30000 word essence summary + 100 interview questions, hanging the interviewer is more than enough (Collection Series
MySQL 三万字精华总结 + 面试100 问,吊打面试官绰绰有余(收藏系列
IPv6 experiment
ROS machine voice
GNSS positioning accuracy index calculation
Alibaba cloud microservices (IV) service mesh overview and instance istio
Design a key value cache to save the results of the most recent Web server queries
阿里云微服务(三)Sentinel开源流控熔断降级组件
Wechat applet development experience
KF UD decomposition pseudo code implementation advanced [2]
Iterable、Collection、List 的常见方法签名以及含义
Shortest Hamilton path (pressure DP)