当前位置:网站首页>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);
}
}```
边栏推荐
- Missing value filling in data analysis (focus on multiple interpolation method, miseforest)
- [esp32 learning-2] esp32 address mapping
- Mall project -- day09 -- order module
- ES6语法总结--上篇(基础篇)
- Understanding of AMBA, AHB, APB and Axi
- Small L's test paper
- 荣耀Magic 3Pro 充电架构分析
- [esp32 learning-1] construction of Arduino esp32 development environment
- Encodermappreduce notes
- Basic use of pytest
猜你喜欢
Cannot change version of project facet Dynamic Web Module to 2.3.
RT thread API reference manual
Basic use of pytest
AMBA、AHB、APB、AXI的理解
Kconfig Kbuild
Kaggle竞赛-Two Sigma Connect: Rental Listing Inquiries
Variable star user module
[esp32 learning-2] esp32 address mapping
Machine learning -- decision tree (sklearn)
Reno7 60W super flash charging architecture
随机推荐
Hutool中那些常用的工具类和方法
优先级反转与死锁
Comparaison des solutions pour la plate - forme mobile Qualcomm & MTK & Kirin USB 3.0
Those commonly used tool classes and methods in hutool
Matlab learning and actual combat notes
共用体(union)详解【C语言】
5G工作原理详解(解释&图解)
open-mmlab labelImg mmdetection
JS object and event learning notes
Time slice polling scheduling of RT thread threads
Linux yum安装MySQL
gcc 编译选项
[template] KMP string matching
Yarn installation and use
Funny cartoon: Programmer's logic
Detailed explanation of Union [C language]
vim命令行笔记
ESP8266通过Arduino IDE连接Onenet云平台(MQTT)
Oppo vooc fast charging circuit and protocol
RT-Thread 线程的时间片轮询调度