|
使用免费版的设备不能配置实体键一键配网嘛,那个char type[] = "Your Device Type"; 怎么获取?
谁帮忙完善一下,代码:
[md]#define BLINKER_ALIGENIE_OUTLET
#define BLINKER_WIFI
#define BLINKER_ESP_SMARTCONFIG
#include <Blinker.h>
char type[] = "Your Device Type";
char auth[] = "Your Device Secret Key";
/*设置按键*/
#define BUTTON_1 "btn-01"
#define BUTTON_2 "btn-02"
BlinkerButton Button1(BUTTON_1);
BlinkerButton Button2(BUTTON_2);
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_ON) {
//digitalWrite(5, HIGH);
digitalWrite(5, LOW);
digitalWrite(16, LOW);
BLINKER_LOG("Toggle on!");
//Button1.icon("icon_1");
Button1.color("#0000FF");
Button1.text("打开");
// Button1.text("Your button name", "describe");
Button1.print("on");
}
else if (state == BLINKER_CMD_OFF) {
//digitalWrite(5, LOW);
digitalWrite(5, HIGH);
digitalWrite(16, HIGH);
BLINKER_LOG("Toggle off!");
//Button1.icon("icon_1");
Button1.color("#363636");
Button1.text("关闭");
// Button1.text("Your button name", "describe");
Button1.print("off");
}
}
void button2_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_ON) {
//digitalWrite(5, HIGH);
digitalWrite(2, LOW);
BLINKER_LOG("Toggle on!");
//Button2.icon("icon_1");
Button2.color("#0000FF");
Button2.text("开灯");
// Button2.text("Your button name", "describe");
Button2.print("on");
}
else if (state == BLINKER_CMD_OFF) {
//digitalWrite(5, LOW);
digitalWrite(2, HIGH);
BLINKER_LOG("Toggle off!");
//Button2.icon("icon_1");
Button2.color("#363636");
Button2.text("关灯");
// Button2.text("Your button name", "describe");
Button2.print("off");
}
}
/*....结束....*/
bool oState = false;
void aligeniePowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);
if (state == BLINKER_CMD_ON) {
digitalWrite(5, LOW);
digitalWrite(16, LOW);
BlinkerAliGenie.powerState("on");
BlinkerAliGenie.print();
oState = true;
}
else if (state == BLINKER_CMD_OFF) {
digitalWrite(5, HIGH);
digitalWrite(16, HIGH);
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("millis", BlinkerTime);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(5, OUTPUT);
digitalWrite(5, LOW);
pinMode(16, OUTPUT);
digitalWrite(16, LOW);
pinMode(2, OUTPUT);
digitalWrite(2, LOW);
Blinker.begin(auth, type);
Blinker.attachData(dataRead);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
BlinkerAliGenie.attachPowerState(aligeniePowerState);
BlinkerAliGenie.attachQuery(aligenieQuery);
}
void loop()
{
Blinker.run();
}[/md] |
|