当前位置:网站首页>Single bus temperature sensor 18B20 data on cloud (Alibaba cloud)
Single bus temperature sensor 18B20 data on cloud (Alibaba cloud)
2022-06-12 13:53:00 【TMS320VC5257H】
Abstract : adopt d1 Module collects single bus temperature sensor 18B20 data , interval 1.5 Send the latest temperature data to the Alibaba cloud Internet of things platform every second .
Ying netizen “ A drop in the bucket ” Please , Help achieve 18B20 Sensor data on the cloud . The source code has been “ A drop in the bucket ” Agree to publish in this article .
1. Hardware and software environment
Software :win7x64,arduino ide 1.8.13
Hardware :d1,18b20
2. Hardware wiring
As shown in the figure below , Single bus power supply is used 5V,GND And D1 Of GND Connected to a .
The signal line is connected to D1 The pin of D4.
3. Source code
If you don't understand the basic knowledge of data cloud , Please refer to the article series
If your ide If the board and library have not been configured , Please also refer to the series of articles , take ide The required board support package and library file are loaded , Otherwise, various missing components will be prompted .
from arduino The board begins to achieve Alibaba cloud app control --WeMos D1 or ESP8266 Connect the Alibaba cloud article collection and source code
/*
* Program name :aliyun002
* author : A drop in the bucket
* Last revision : peanut ,2021 year 8 month 22 Japan 09:58:39
* Program function : Read 18B20 Single bus temperature sensor data , Send it to Alibaba cloud Internet of things platform
* Hardware connection :VCC---5V,GND---GND,DQ---D4. On the left is the sensor pin , The right side is D1 Module pin
* Cloud configuration : The product name “ Blowers ”, Equipment name arduino18b20001, There are two properties , They are the second temperature temperature002, Floating point type ; Blower temperature gufengjiwendu,int32 type
* Running effect : Burn this procedure to D1 modular , Relevant information can be observed through the serial port . First, it will connect to WIFI, Then connect to alicloud , At this time, you can log in to the Alibaba cloud Internet of things platform through the browser , Observe that the device is online .
* Then use online debugging tools , towards gufengjiwendu Set the number 1, Will be displayed on the serial port “ The temperature is set to 1”, This data flows from the cloud to the device .
* Equipment per 1.5 Submit to the cloud once every second 18B20 Temperature of , The data is in the form of XX.YY, Retain 2 Is a decimal . If you hold the sensor with your fingers , You will find that the temperature will change constantly .
*
* Use this program , You can master a basic skill of data collection on the cloud .
*/
// introduce wifi modular , And instantiate , Different chips may have different dependencies here
#include <ESP8266WiFi.h>
static WiFiClient espClient;
// Introducing Alibaba cloud IoT SDK
#include <AliyunIoTSDK.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS D4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// Set product and device information , Check from alicloud device information
#define PRODUCT_KEY "a1JXXXXae7Sv"
#define DEVICE_NAME "arduino18b20001"
#define DEVICE_SECRET "f06c15XXXXXXc65b8721af4d"
#define REGION_ID "cn-shanghai"
// Set up wifi Information
//#define WIFI_SSID "XXXXXXi"
//#define WIFI_PASSWD "1XXXXXX678"
void setup()
{
Serial.begin(115200);
sensors.begin();// initialization 18b20
// initialization wifi
wifiInit(WIFI_SSID, WIFI_PASSWD);
// initialization iot, Need to transfer in wifi Of client, And device product information
AliyunIoTSDK::begin(espClient, PRODUCT_KEY, DEVICE_NAME, DEVICE_SECRET, REGION_ID);
// Bind a device property callback , When this property is modified remotely , Will trigger powerCallback
// PowerSwitch It refers to the Internet of things model defined in the device product id
AliyunIoTSDK::bindData("gufengjiwendu", powerCallback);// This binding callback , Cannot bind Chinese characters , What should be bound is the function identifier , This identifier cannot use Chinese characters
}
void loop()
{
AliyunIoTSDK::loop();// This is alicloud SDK The main loop inside , In this cycle, the device and cloud will be waiting all the time MQTT news , Whether it's up or down , It is it that responds .
//
//-------------------------------------------------------------------//
// The following code reproduces a drop in the ocean to read the temperature program . The purpose is to observe the temperature through the serial port .
Serial.print(" Requesting temperatures...");
sensors.requestTemperatures();
Serial.println("DONE");
Serial.print("Temperature for Device 1 is: ");
Serial.print(sensors.getTempCByIndex(0));
AliyunIoTSDK::send("temperature002",sensors.getTempCByIndex(0));
delay(1500);
//------------------------------------------------------------------//
}
// initialization wifi Connect
void wifiInit(const char *ssid, const char *passphrase)
{
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, passphrase);
while (WiFi.status() != WL_CONNECTED)
{
delay(1000);
Serial.println("WiFi not Connect");
}
Serial.println("Connected to AP");// What can be printed by serial port is : state is connected ah ? Why print state is connected Well ? Because the program is running , Alibaba cloud has been running SDK, This SDK Inside , Will constantly shake hands with Alibaba cloud , If you maintain a connection with Alibaba cloud , So the hint is stateis connected.
}
// Callback function for power attribute modification , analysis json The identifier of the data cannot be Chinese characters . What is the data distributed in the cloud , This will respond to something . For example, the cloud sends numbers 1, Then the string will be sent through the serial port .
// If it is other data , Because there is no response code in the callback function , There will be no reaction .
void powerCallback(JsonVariant p)
{
int PowerSwitch = p["gufengjiwendu"];
if (PowerSwitch == 1)
{
// Boot device
Serial.println(" The temperature is set to 1");
}
}
4. Realization effect
* Running effect : Burn this procedure to D1 modular , Relevant information can be observed through the serial port . First, it will connect to WIFI, Then connect to alicloud , At this time, you can log in to the Alibaba cloud Internet of things platform through the browser , Observe that the device is online .
* Then use online debugging tools , towards gufengjiwendu Set the number 1, Will be displayed on the serial port “ The temperature is set to 1”, This data flows from the cloud to the device .
* Equipment per 1.5 Submit to the cloud once every second 18B20 Temperature of , The data is in the form of XX.YY, Retain 2 Is a decimal . If you hold the sensor with your fingers , You will find that the temperature will change constantly .
The above content requires a certain knowledge of Alibaba cloud Internet of things platform , Interested students can praise and pay attention to .
For a very detailed introduction, please refer to the collection of articles
from arduino The board begins to achieve Alibaba cloud app control --WeMos D1 or ESP8266 Connect the Alibaba cloud article collection and source code
边栏推荐
- Install RPM package offline using yum
- Code debugging - print log output to file
- Xcode debugging OpenGLES
- 颜色编码格式介绍
- [WUSTCTF2020]颜值成绩查询-1
- 【mysql进阶】索引分类及索引优化方案(五)
- 【SemiDrive源码分析】【X9芯片启动流程】26 - R5 SafetyOS 之 LK_INIT_LEVEL_TARGET 阶段代码流程分析(TP Drvier、Audio Server初始化)
- go-zero 微服务实战系列(二、服务拆分)
- 通过loganalyzer展示数据库中的日志
- Seekg, tellg related file operations
猜你喜欢
Acwing: topology sequence
Go zero micro Service Practice Series (II. Service splitting)
一种快速创建测试窗口的方法
阿里云开发板HaaS510响应UART串口指令
Record some settings for visual studio 2019
Web3.0,「激发创造」的时代
[MySQL advanced] index classification and index optimization scheme (V)
简述CGI与FASTCGI区别
Greed issues - Egypt scores
618 entered the second half of the period, apple occupied the high-end market, and the domestic mobile phones finally undercut the price competition
随机推荐
Possible solutions to problems after CodeBlocks installation
Mold and remainder
拆改广告机---业余解压
[WUSTCTF2020]颜值成绩查询-1
1004: character triangle
CUDA error: CUBLAS_ STATUS_ NOT_ INITIALIZED when calling `cublasCreate(handle)`
Codeforces 1629 F2. Game on sum (hard version) - Yang Hui's triangle, violence, finding rules
Introduction to color coding format
Display logs in the database through loganalyzer
Codeforces 1637 E. best pair - Thinking
编译安装基于fastcgi模式的多虚拟主机的wordpress和discuz的LAMP架构
AWLive 结构体的使用
one × Convolution kernel of 1
通过loganalyzer展示数据库中的日志
2065: [example 2.2] sum of integers
Implementation of Ackermann function with simulated recursion
Alibaba cloud development board haas510 parses serial port JSON data and sends attributes
C language implementation of string and memory library functions
1005: estimation of the earth's population carrying capacity
阿裏雲開發板HaaS510報送設備屬性