当前位置:网站首页>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);
}
}```
边栏推荐
- RuntimeError: cuDNN error: CUDNN_ STATUS_ NOT_ INITIALIZED
- Raspberry pie tap switch button to use
- Comparaison des solutions pour la plate - forme mobile Qualcomm & MTK & Kirin USB 3.0
- 机器学习--决策树(sklearn)
- C语言,log打印文件名、函数名、行号、日期时间
- IOT system framework learning
- Kconfig Kbuild
- 2019 Tencent summer intern formal written examination
- Missing value filling in data analysis (focus on multiple interpolation method, miseforest)
- gcc 编译选项
猜你喜欢
I2C bus timing explanation
E-commerce data analysis -- User Behavior Analysis
5G工作原理详解(解释&图解)
Fashion-Gen: The Generative Fashion Dataset and Challenge 论文解读&数据集介绍
Kconfig Kbuild
MongoDB
ARM PC=PC+8 最便于理解的阐述
Machine learning -- linear regression (sklearn)
Kaggle competition two Sigma connect: rental listing inquiries (xgboost)
C语言回调函数【C语言】
随机推荐
C语言回调函数【C语言】
C语言函数之可变参数原理:va_start、va_arg及va_end
Unit test - unittest framework
分布式事务的实现方案
ES6语法总结--上篇(基础篇)
Detailed explanation of nodejs
Pytoch implements simple linear regression demo
STM32型号与Contex m对应关系
MySQL realizes read-write separation
锂电池基础知识
vim命令行笔记
机器学习--决策树(sklearn)
JS array + array method reconstruction
AMBA、AHB、APB、AXI的理解
Redis interview questions
Dependency in dependencymanagement cannot be downloaded and red is reported
5G工作原理详解(解释&图解)
Mysql database interview questions
gcc 编译选项
OSPF message details - LSA overview