状态不能同步了?-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1361|回复: 3

[已解答] 状态不能同步了?

[复制链接]
发表于 2020-6-22 20:07 | 显示全部楼层 |阅读模式
app和小爱控制都正常,就是app的按钮不显示开关状态,请各位大佬帮忙看看什么原因?

[md]#define BLINKER_WIFI
#define BLINKER_MIOT_LIGHT//支持小爱同学
#include <Blinker.h>

char auth[] = "*********";//app中获取到的Secret Key(密钥)
char ssid[] = "****";
char pswd[] = "********";

unsigned long Timers[3] = {0};

int GPIO = 0; //定义继电器输入引脚为GPIO/0

int switch_button = 2;
int temp = 0;

// 新建组件对象
BlinkerButton Button1("btn-abc");//注意:要和APP组件’数据键名’一致

// 按下BlinkerAPP按键即会执行该函数
void button1_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
digitalWrite(GPIO, !digitalRead(GPIO));
Blinker.vibrate();
}
bool oState = false;
//小爱电源类操作的回调函数:
//当小爱同学向设备发起控制, 设备端需要有对应控制处理函数
void miotPowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);
if (state == BLINKER_CMD_ON) {
digitalWrite(GPIO, LOW);
BlinkerMIOT.powerState("on");
BlinkerMIOT.print();
oState = true;
}
else if (state == BLINKER_CMD_OFF) {
digitalWrite(GPIO, HIGH);
BlinkerMIOT.powerState("off");
BlinkerMIOT.print();
oState = false;
}
}

void setup() {
// 初始化串口,并开启调试信息,调试用可以删除
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
// 初始化IO
pinMode(GPIO, OUTPUT);
digitalWrite(GPIO, HIGH);

// 初始化blinker
Blinker.begin(auth, ssid, pswd);
Button1.attach(button1_callback);

//小爱同学务必在回调函数中反馈该控制状态
BlinkerMIOT.attachPowerState(miotPowerState);//注册回调函数
}
void loop() {
Blinker.run();

temp = digitalRead(switch_button);
if (temp == LOW) {
   digitalWrite(GPIO, !digitalRead(GPIO));
   pinMode(switch_button, INPUT_PULLUP);
   delay(300);
  }
}[/md]



发表于 2020-6-22 20:20 | 显示全部楼层
 楼主| 发表于 2020-6-22 21:26 | 显示全部楼层
奈何col 发表于 2020-6-22 20:20
https://www.arduino.cn/thread-84332-1-1.html

下面是我在app点击按钮之后的信息,劳烦帮忙看下,安装的状态一直是关闭。。。

21:25:24.448 -> [121598] num: 0, get Text: {"btn-abc":"on"}, length: 16
21:25:24.482 -> [121618] parse data: {"btn-abc":"on"}
21:25:24.482 -> [121618] defined BLINKER_ARDUINOJSON
21:25:24.482 -> [121620] autoManager begin: 0 0
21:25:24.482 -> [121620] checkNum count: 1
21:25:24.482 -> [121620] strWidgetsParse isParsed
21:25:24.482 -> [121622] strWidgetsParse: btn-abc
21:25:24.482 -> [121625] get button state: on
21:25:24.482 -> [121629] autoFormatData key: vibrate, json: "vibrate":200
21:25:24.517 -> [121633] new.
21:25:24.517 -> [121635] isParsed
21:25:24.589 -> [121739] print: {"vibrate":200}
21:25:24.589 -> [121739] Proto print...
21:25:24.589 -> [121739] Freeheap: 7760
21:25:24.589 -> [121740] WS response:
21:25:24.624 -> [121740] {"vibrate":200}
21:25:24.624 -> [121740] Success...
21:25:24.624 -> [121746] Freeheap: 8120
21:25:27.110 -> [124265] num: 0, get Text: {"btn-abc":"on"}, length: 16
21:25:27.147 -> [124286] parse data: {"btn-abc":"on"}
21:25:27.147 -> [124286] defined BLINKER_ARDUINOJSON
21:25:27.147 -> [124287] autoManager begin: 0 0
21:25:27.147 -> [124288] checkNum count: 1
21:25:27.147 -> [124288] strWidgetsParse isParsed
21:25:27.147 -> [124290] strWidgetsParse: btn-abc
21:25:27.147 -> [124293] get button state: on
21:25:27.147 -> [124296] autoFormatData key: vibrate, json: "vibrate":200
21:25:27.182 -> [124301] new.
21:25:27.182 -> [124302] isParsed
21:25:27.252 -> [124407] print: {"vibrate":200}
21:25:27.252 -> [124407] Proto print...
21:25:27.252 -> [124407] Freeheap: 7760
21:25:27.287 -> [124407] WS response:
21:25:27.287 -> [124407] {"vibrate":200}
21:25:27.287 -> [124407] Success...
21:25:27.287 -> [124414] Freeheap: 8120
21:25:28.994 -> [126134] MQTT Ping!
21:25:28.994 -> [126134] Freeheap: 8984
发表于 2020-6-22 22:13 | 显示全部楼层
请把入门教程先看一遍
https://www.arduino.cn/thread-83176-1-1.html
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 09:42 , Processed in 0.103659 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表