当前位置:网站首页>(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)
endt--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

边栏推荐
- 《软件测试》习题答案:第一章
- TYUT太原理工大学2022数据库大题之分解关系模式
- Pride-pppar source code analysis
- Answer to "software testing" exercise: Chapter 1
- ROS machine voice
- 系统设计学习(二)Design a key-value cache to save the results of the most recent web server queries
- Heap sort [handwritten small root heap]
- One article to get UDP and TCP high-frequency interview questions!
- Decomposition relation model of the 2022 database of tyut Taiyuan University of Technology
- Relational algebra of tyut Taiyuan University of technology 2022 database
猜你喜欢

12 excel charts and arrays

IPv6 experiment

(超详细二)onenet数据可视化详解,如何用截取数据流绘图

Fairygui bar subfamily (scroll bar, slider, progress bar)

Small exercise of library management system

Tyut Taiyuan University of technology 2022 "Mao Gai" must be recited

Role movement in the first person perspective
![[dry goods] cycle slip detection of suggestions to improve the fixed rate of RTK ambiguity](/img/9d/7284c1399964d3fb48886f12e4941c.jpg)
[dry goods] cycle slip detection of suggestions to improve the fixed rate of RTK ambiguity

The overseas sales of Xiaomi mobile phones are nearly 140million, which may explain why Xiaomi ov doesn't need Hongmeng

凡人修仙学指针-2
随机推荐
Small exercise of library management system
[GNSS data processing] Helmert variance component estimation analysis and code implementation
RTKLIB: demo5 b34f. 1 vs b33
Common method signatures and meanings of Iterable, collection and list
阿里云一面:并发场景下的底层细节 - 伪共享问题
Abstract classes and interfaces
Several high-frequency JVM interview questions
Dark chain lock (lca+ difference on tree)
165. Compare version number - string
Redis介绍与使用
TYUT太原理工大学2022数据库大题之E-R图转关系模式
Relational algebra of tyut Taiyuan University of technology 2022 database
IPv6 experiment
Fairygui bar subfamily (scroll bar, slider, progress bar)
All in one 1405: sum and product of prime numbers
2-year experience summary, tell you how to do a good job in project management
阿里云微服务(一)服务注册中心Nacos以及REST Template和Feign Client
一文搞定 UDP 和 TCP 高频面试题!
Fgui project packaging and Publishing & importing unity & the way to display the UI
Inheritance and polymorphism (I)