当前位置:网站首页>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);
}
}```
边栏推荐
- Some concepts often asked in database interview
- [template] KMP string matching
- inline详细讲解【C语言】
- RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED
- RT-Thread 线程的时间片轮询调度
- Arm pc=pc+8 is the most understandable explanation
- 程序员老鸟都会搞错的问题 C语言基础 指针和数组
- 分布式事务的实现方案
- 【ESP32学习-1】Arduino ESP32开发环境搭建
- 荣耀Magic 3Pro 充电架构分析
猜你喜欢
Togglebutton realizes the effect of switching lights
小天才电话手表 Z3工作原理
E-commerce data analysis -- salary prediction (linear regression)
Variable star user module
Understanding of AMBA, AHB, APB and Axi
ES6语法总结--下篇(进阶篇 ES6~ES11)
[template] KMP string matching
数据分析之缺失值填充(重点讲解多重插值法Miceforest)
电商数据分析--用户行为分析
MP3mini播放模块arduino<DFRobotDFPlayerMini.h>函数详解
随机推荐
Analysis of charging architecture of glory magic 3pro
vim命令行笔记
优先级反转与死锁
共用体(union)详解【C语言】
.elf .map .list .hex文件
arduino获取数组的长度
JS object and event learning notes
Contiki源码+原理+功能+编程+移植+驱动+网络(转)
Pytorch-温度预测
Pytorch实现简单线性回归Demo
Cannot change version of project facet Dynamic Web Module to 2.3.
Keyword inline (inline function) usage analysis [C language]
RuntimeError: cuDNN error: CUDNN_ STATUS_ NOT_ INITIALIZED
Selective sorting and bubble sorting [C language]
Kaggle竞赛-Two Sigma Connect: Rental Listing Inquiries
Implementation scheme of distributed transaction
电商数据分析--用户行为分析
Contiki source code + principle + function + programming + transplantation + drive + network (turn)
Pytorch four commonly used optimizer tests
MySQL主从复制的原理以及实现