当前位置:网站首页>(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
边栏推荐
猜你喜欢
Alibaba cloud microservices (I) service registry Nacos, rest template and feign client
Answer to "software testing" exercise: Chapter 1
MYSQL索引钟B-TREE ,B+TREE ,HASH索引之间的区别和应用场景
如何保障 MySQL 和 Redis 的数据一致性?
arduino+DS18B20温度传感器(蜂鸣器报警)+LCD1602显示(IIC驱动)
arduino+水位传感器+led显示+蜂鸣器报警
Problems and solutions of robust estimation in rtklib single point location spp
Experience summary of autumn recruitment of state-owned enterprises
Database operation of tyut Taiyuan University of technology 2022 database
View UI plus released version 1.2.0 and added image, skeleton and typography components
随机推荐
Shortest Hamilton path (pressure DP)
Introduction pointer notes
国企秋招经验总结
View UI Plus 发布 1.3.1 版本,增强 TypeScript 使用体验
How do architects draw system architecture blueprints?
初识C语言(上)
系统设计学习(三)Design Amazon‘s sales rank by category feature
4.30 dynamic memory allocation notes
Atomic and nonatomic
Record: I accidentally wrote a recursion next time
Design a key value cache to save the results of the most recent Web server queries
西安电子科技大学22学年上学期《信号与系统》试题及答案
String类
分支语句和循环语句
TYUT太原理工大学2022数据库大题之数据库操作
阿里云微服务(二) 分布式服务配置中心以及Nacos的使用场景及实现介绍
What are the advantages of using SQL in Excel VBA
TYUT太原理工大学2022软工导论考试题型大纲
Common method signatures and meanings of Iterable, collection and list
《软件测试》习题答案:第一章