本文主要是介绍ESP8266接入天猫精灵-(使用Blinker),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.下载天猫精灵app
2. 下载blinker-2.1.5.apk,注册Blinker账户
https://blinker.app/
3.新建设备,复制key
4. Arduino IDE需安装好esp8266扩展
务必使用 2.5.0 及以上版本的 ESP8266/Arduino package 常规安装方法
中国大陆安装方法(windows)
中国大陆安装方法(mac os)
5.天猫精灵接入文档
https://doc.blinker.app/?file=007-%E8%AF%AD%E9%9F%B3%E5%8A%A9%E6%89%8B%E6%8E%A5%E5%85%A5/01-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5
6.下载示例代码到ESP8266板(设备密钥,wifi_uid,wifi_password)
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#define BLINKER_ALIGENIE_OUTLET#include <Blinker.h>char auth[] = "Your Device Secret Key";
char ssid[] = "Your WiFi network SSID or name";
char pswd[] = "Your WiFi network WPA password or WEP key";bool oState = false;void aligeniePowerState(const String & state)
{BLINKER_LOG("need set power state: ", state);if (state == BLINKER_CMD_ON) {digitalWrite(LED_BUILTIN, HIGH);BlinkerAliGenie.powerState("on");BlinkerAliGenie.print();oState = true;}else if (state == BLINKER_CMD_OFF) {digitalWrite(LED_BUILTIN, LOW);BlinkerAliGenie.powerState("off");BlinkerAliGenie.print();oState = false;}
}void aligenieQuery(int32_t queryCode)
{BLINKER_LOG("AliGenie Query codes: ", queryCode);switch (queryCode){case BLINKER_CMD_QUERY_ALL_NUMBER :BLINKER_LOG("AliGenie Query All");BlinkerAliGenie.powerState(oState ? "on" : "off");BlinkerAliGenie.print();break;case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :BLINKER_LOG("AliGenie Query Power State");BlinkerAliGenie.powerState(oState ? "on" : "off");BlinkerAliGenie.print();break;default :BlinkerAliGenie.powerState(oState ? "on" : "off");BlinkerAliGenie.print();break;}
}void dataRead(const String & data)
{BLINKER_LOG("Blinker readString: ", data);Blinker.vibrate();uint32_t BlinkerTime = millis();Blinker.print(BlinkerTime);Blinker.print("millis", BlinkerTime);
}void setup()
{Serial.begin(115200);#if defined(BLINKER_PRINT)BLINKER_DEBUG.stream(BLINKER_PRINT);#endifpinMode(LED_BUILTIN, OUTPUT);digitalWrite(LED_BUILTIN, LOW);Blinker.begin(auth, ssid, pswd);Blinker.attachData(dataRead);BlinkerAliGenie.attachPowerState(aligeniePowerState);BlinkerAliGenie.attachQuery(aligenieQuery);
}void loop()
{Blinker.run();
}
下载过程如果遇到这个错误,删除C:\Users\Administrator\AppData\Local\Temp\arduino_cache_611790,core文件夹
运行成功,串口显示
7.天猫精灵绑定blinker账号(新建的设备或key更改,可以先解绑再重新绑定)
添加成功后,天猫精灵设备列表显示 blinker上线的设备
更改设备别名
对天猫精灵说: 打开客厅的插座
这篇关于ESP8266接入天猫精灵-(使用Blinker)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!