我的代码哪里错了,为什么我只能用天猫精灵控制1个继电器
#define BLINKER_WIFI#define BLINKER_ALIGENIE_MULTI_OUTLET
#include <Blinker.h>
BlinkerButton Button1("btn-km");
BlinkerButton Button2("btn-kckm");
BlinkerButton Button3("btn-gckm");
BlinkerText Text1("text_1");
char auth[] = "";
char ssid[] = "wei.";
char pswd[] = "";
char i;
bool oState = { false };
void aligeniePowerState(const String & state, uint8_t num)
{
BLINKER_LOG("need set outlet: ", num, ", power state: ", state);
if(num==1){
i=D1; //指定每一路开关对应在开发板上的通道接口
}else if(num==2){
i=D2;
}else if(num==3){
i=D5;
}
if (state == BLINKER_CMD_ON) {
digitalWrite(i, HIGH);
BlinkerAliGenie.powerState("on", num);
BlinkerAliGenie.print();
oState = true;
}
else if (state == BLINKER_CMD_OFF) {
digitalWrite(i, LOW);
BlinkerAliGenie.powerState("off", num);
BlinkerAliGenie.print();
oState = true;
if (num == 0)
{
for (uint8_t o_num = 0; o_num < 5; o_num++)
{
oState = false;
}
}
}
}
void aligenieQuery(int32_t queryCode, uint8_t num)
{
BLINKER_LOG("AliGenie Query outlet: ", num,", codes: ", queryCode);
switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER :
BLINKER_LOG("AliGenie Query All");
BlinkerAliGenie.powerState(oState ? "on" : "off", num);
BlinkerAliGenie.print();
break;
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
BLINKER_LOG("AliGenie Query Power State");
BlinkerAliGenie.powerState(oState ? "on" : "off", num);
BlinkerAliGenie.print();
break;
default :
BlinkerAliGenie.powerState(oState ? "on" : "off", num);
BlinkerAliGenie.print();
break;
}
}
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print("millis", BlinkerTime);
}
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
digitalWrite(D1, HIGH);
digitalWrite(D1, LOW);
Blinker.print("开灯命令已经处理");
Text1.print("shuju");
}
void button2_callback(const String & state)
BLINKER_LOG("get button state: ", state);
digitalWrite(D2, HIGH);
Blinker.print("开灯命令已经处理");
digitalWrite(D2, LOW);
}
void button3_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
digitalWrite(D5, HIGH);
digitalWrite(D5, LOW);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(D1, OUTPUT);
digitalWrite(D1, LOW);
pinMode(D2, OUTPUT);
digitalWrite(D2, LOW);
pinMode(D5, OUTPUT);
digitalWrite(D5, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
BlinkerAliGenie.attachPowerState(aligeniePowerState);
BlinkerAliGenie.attachQuery(aligenieQuery);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
}
void loop()
{
Blinker.run();
}
点灯科技的app那,一个按键都用不了
weiding 发表于 2020-2-20 12:31
点灯科技的app那,一个按键都用不了
建议看设备端调试信息
https://www.arduino.cn/thread-84332-1-1.html
void button2_callback(const String & state)
BLINKER_LOG("get button state: ", state);
digitalWrite(D2, HIGH);
Blinker.print("开灯命令已经处理");
digitalWrite(D2, LOW);
}
少了个{ 智定义科技 发表于 2020-2-20 21:20
void button2_callback(const String & state)
BLINKER_LOG("get button state: ", state);
di ...
我代码里有的
奈何col 发表于 2020-2-20 18:12
建议看设备端调试信息
https://www.arduino.cn/thread-84332-1-1.html
我的代码有错吗?
这貌似是抖音爆改主任的代码改成了天猫精灵
他原代码都通过不了编译
https://blog.csdn.net/qq_44343584/article/details/104294962?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522158714172419725247663816%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=158714172419725247663816&biz_id=0&utm_source=distribute.pc_search_result.none-task-blog-2~blog~first_rank_v2~rank_v25-18
请参考这个代码 兄弟 发现问题了 你 i 没有初始化 本帖最后由 shao1 于 2020-4-19 11:09 编辑
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#define BLINKER_ALIGENIE_MULTI_OUTLET
#include <Blinker.h>
BlinkerButton Button1("btn-lt1"); //设置blinkerapp内数据键名
BlinkerButton Button2("btn-lt2"); //
BlinkerButton Button3("btn-lt3");
BlinkerButton Button4("btn-lt4");
BlinkerText Text1("text_1");
char i;
char auth[] = "******1f074";//填上刚刚记下来的密钥
char ssid[] = "88****888";//填上你家WiFi名字
char pswd[] = "186*****721";//填上你家WiFi密码
bool oState = { false };
void aligeniePowerState(const String & state, uint8_t num)
{
BLINKER_LOG("need set outlet: ", num, ", power state: ", state);
if(num == 1){
i=0; //指定每一路开关对应在开发板上的通道接口
}else if(num == 2){
i=2;
}else if(num == 3){
i=4;
}else if(num == 4){
i=5;
}
if (state == BLINKER_CMD_ON) {
digitalWrite(i, LOW);
BlinkerAliGenie.powerState("on",num);
BlinkerAliGenie.print();
oState = true;
}
else if (state == BLINKER_CMD_OFF) {
digitalWrite(i, HIGH);
BlinkerAliGenie.powerState("off",num);
BlinkerAliGenie.print();
oState = false;
if (num == 0)
{
for (uint8_t o_num = 0; o_num < 5; o_num++)
{
oState = false;
}
}
}
}
void aligenieQuery(int32_t queryCode, uint8_t num)
{
BLINKER_LOG("AliGenie Query outlet: ", num,", codes: ", queryCode);
switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER :
BLINKER_LOG("AliGenie Query All");
BlinkerAliGenie.powerState(oState ? "on" : "off",num);
BlinkerAliGenie.print();
break;
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
BLINKER_LOG("AliGenie Query Power State");
BlinkerAliGenie.powerState(oState ? "on" : "off",num);
BlinkerAliGenie.print();
break;
default :
BlinkerAliGenie.powerState(oState ? "on" : "off",num);
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 button1_callback(const String & state) //点灯app内控制按键触发
{
BLINKER_LOG("get button state: ", state);
digitalWrite(0, !digitalRead(0));
}
void button2_callback(const String & state) //点灯app内控制按键触发
{
BLINKER_LOG("get button state: ", state);
digitalWrite(2, !digitalRead(2));
}
void button3_callback(const String & state) //点灯app内控制按键触发
{
BLINKER_LOG("get button state: ", state);
digitalWrite(4, !digitalRead(4));
}
void button4_callback(const String & state) //点灯app内控制按键触发
{
BLINKER_LOG("get button state: ", state);
digitalWrite(5, !digitalRead(5));
}
void setup()
{
Serial.begin(115200);
#if defined(BLINKER_PRINT)
BLINKER_DEBUG.stream(BLINKER_PRINT);
#endif
pinMode(0, OUTPUT);
digitalWrite(0, HIGH);
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
pinMode(5, OUTPUT);
digitalWrite(5, HIGH);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
BlinkerAliGenie.attachPowerState(aligeniePowerState);
BlinkerAliGenie.attachQuery(aligenieQuery);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
Button4.attach(button4_callback);
}
void loop()
{
Blinker.run();
}
4路天猫精灵控制 根据你的代码修改的拿去亲测在APP4路都可以控制 天猫精灵 也成功了
页:
[1]