当前位置:网站首页>Esp8266 uses Arduino to connect Alibaba cloud Internet of things
Esp8266 uses Arduino to connect Alibaba cloud Internet of things
2022-07-06 12:05:00 【A geek is as deep as the sea】
Use here AliyunIoTSDK Library for fast access
Need to make preliminary preparations
install
The library files 【AliyunIoTSDK】
-【ArduinoJson】
-【Crypto】
-【PubSubClient】 This is mqtt The support package What is shown in the picture 1 and 2 Fine , Choose one of them . I have installed it here because of some other projects . It will not affect the later development
Alibaba cloud device creation ( The explanation of pictures is too troublesome , Go directly to the video ) Video link
// introduce wifi modular , And instantiate ,
#include <ESP8266WiFi.h>
static WiFiClient espClient;
// Introducing Alibaba cloud IoT SDK
#include <AliyunIoTSDK.h>
// Set product and device information , Check from alicloud device information
#define PRODUCT_KEY "a1rCF0cxG0w"
#define DEVICE_NAME "ceshi"
#define DEVICE_SECRET "32f735fc37b68a86b6eed749f1ba2bf8"
#define REGION_ID "cn-shanghai"
// Set up wifi Information
#define WIFI_SSID "xxxx"
#define WIFI_PASSWD "12345678"
#define led D4
void setup()
{
Serial.begin(115200);
// 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("PowerSwitch_1", powerCallback);
}
void loop()
{
AliyunIoTSDK::send("CurrentTemperature", ((float)random(1000,9999))/100);
AliyunIoTSDK::send("CurrentHumidity", (int)random(0,100));
AliyunIoTSDK::send("PowerSwitch_1", !(int)digitalRead(led));
delay(2000);
AliyunIoTSDK::loop();
}
// 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");
pinMode(led,OUTPUT);
}
// Callback function for power attribute modification
void powerCallback(JsonVariant p)
{
int PowerSwitch = p["PowerSwitch_1"];
if (PowerSwitch == 1)
{
digitalWrite(led,0);
}
if (PowerSwitch == 0)
{
digitalWrite(led,1);
}
}```
边栏推荐
- sklearn之feature_extraction.text.CountVectorizer / TfidVectorizer
- Encodermappreduce notes
- 荣耀Magic 3Pro 充电架构分析
- 冒泡排序【C语言】
- OSPF message details - LSA overview
- Implementation scheme of distributed transaction
- open-mmlab labelImg mmdetection
- Contiki source code + principle + function + programming + transplantation + drive + network (turn)
- Feature of sklearn_ extraction. text. CountVectorizer / TfidVectorizer
- 物联网系统框架学习
猜你喜欢
open-mmlab labelImg mmdetection
Vert. x: A simple login access demo (simple use of router)
Basic use of pytest
Detailed explanation of 5g working principle (explanation & illustration)
电商数据分析--用户行为分析
ESP学习问题记录
Oppo vooc fast charging circuit and protocol
2019 Tencent summer intern formal written examination
电商数据分析--薪资预测(线性回归)
Redis interview questions
随机推荐
mysql实现读写分离
Cannot change version of project facet Dynamic Web Module to 2.3.
2019 Tencent summer intern formal written examination
VIM command line notes
Mall project -- day09 -- order module
Variable parameter principle of C language function: VA_ start、va_ Arg and VA_ end
Pytorch four commonly used optimizer tests
C language callback function [C language]
FreeRTOS 任务函数里面的死循环
MySQL主从复制的原理以及实现
选择法排序与冒泡法排序【C语言】
MongoDB
电商数据分析--薪资预测(线性回归)
Correspondence between STM32 model and contex M
arduino UNO R3的寄存器写法(1)-----引脚电平状态变化
XML文件详解:XML是什么、XML配置文件、XML数据文件、XML文件解析教程
E-commerce data analysis -- User Behavior Analysis
Hutool中那些常用的工具类和方法
RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED
Kaggle竞赛-Two Sigma Connect: Rental Listing Inquiries(XGBoost)