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

边栏推荐
- 几道高频的JVM面试题
- MySQL backup -- common errors in xtrabackup backup
- 系统设计学习(三)Design Amazon‘s sales rank by category feature
- TYUT太原理工大学2022软工导论简答题
- System design learning (I) design pastebin com (or Bit.ly)
- How do architects draw system architecture blueprints?
- 继承和多态(下)
- 《软件测试》习题答案:第一章
- Alibaba cloud microservices (III) sentinel open source flow control fuse degradation component
- CorelDRAW plug-in -- GMS plug-in development -- Introduction to VBA -- GMS plug-in installation -- Security -- macro Manager -- CDR plug-in (I)
猜你喜欢

《软件测试》习题答案:第一章

Alibaba cloud microservices (II) distributed service configuration center and Nacos usage scenarios and implementation introduction

Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing

Chromatic judgement bipartite graph

阿里云微服务(三)Sentinel开源流控熔断降级组件

Rt-ppp test using rtknavi

继承和多态(上)

RTKLIB: demo5 b34f. 1 vs b33

Novatel board oem617d configuration step record

MySQL 三万字精华总结 + 面试100 问,吊打面试官绰绰有余(收藏系列
随机推荐
C code implementation of robust estimation in rtklib's pntpos function (standard single point positioning spp)
View UI plus released version 1.3.1 to enhance the experience of typescript
TYUT太原理工大学2022“mao gai”必背
Differences and application scenarios between MySQL index clock B-tree, b+tree and hash indexes
初识C语言(下)
阿里云微服务(二) 分布式服务配置中心以及Nacos的使用场景及实现介绍
Music playback (toggle & playerprefs)
Tyut Taiyuan University of technology 2022 "Mao Gai" must be recited
继承和多态(上)
阿里云微服务(四) Service Mesh综述以及实例Istio
4.30动态内存分配笔记
System design learning (III) design Amazon's sales rank by category feature
图书管理系统小练习
Employment of cashier [differential constraint]
Alibaba cloud microservices (II) distributed service configuration center and Nacos usage scenarios and implementation introduction
记录:下一不小心写了个递归
System design learning (I) design pastebin com (or Bit.ly)
2年经验总结,告诉你如何做好项目管理
错误:排序与角标越界
KF UD decomposition pseudo code implementation advanced [2]