|
本帖最后由 frankxu3698 于 2022-4-13 14:11 编辑
求助大神!
我在做语音控制led实验中,app,天猫精灵都能控制led亮灭,但是在app和语音混合控制时会出现,语音控制后app按键没有显示反馈状态的现象。
- 产生故障的操作:app打开-按键反馈正常,同时语音控制打-串口输出正常,app关闭--按键反馈正常同时语音控制关闭或者打开-led被正确开关但是会出现app按键状态不正常现象
异常串口打印:
- 100413] autoFormatData key: B1, json: "B1":{"swi":"on"}
- [100418] new.
- [100522] print: {"B1":{"swi":"on"}}
- [100522] Proto print...
- [100522] Freeheap: 35168
- [100522] isJson: {"data":{"B1":{"swi":"on"}},"fromDevice":"D105E068RT2LHX02GVPW73MN","toDevice":"7a8f785d0b1611eca9315254","deviceType":"OwnApp"}
- [100531] MQTT Publish...
- [100533] Freeheap: 35168
- [100535] ERROR: MQTT NOT ALIVE OR MSG LIMIT
复制代码
代码如下:
- //------------------------------------------
- #define BLINKER_ALIGENIE_LIGHT //天猫精灵
- #define BLINKER_WIFI
- #define BLINKER_APCONFIG
- #include <Blinker.h>
- // Download OneButton library here:
- // https://github.com/mathertel/OneButton
- #include "OneButton.h"
- #if defined(ESP32)
- #define BLINKER_BUTTON_PIN 4
- #else
- #define BLINKER_BUTTON_PIN 0
- #endif
- // button trigged when pin input level is LOW
- OneButton button(BLINKER_BUTTON_PIN, true);
- char auth[] = "d7a7c41cf639";
- void deviceReset()
- {
- // Reset device ,erase WiFi config.
- Blinker.reset();
- }
- void dataRead(const String & data)
- {
- BLINKER_LOG("Blinker readString: ", data);
- Blinker.vibrate();
-
- uint32_t BlinkerTime = millis();
-
- Blinker.print("millis", BlinkerTime);
- }
- //--------天猫精灵----------------------------------
- // #define BLINKER_ALIGENIE_LIGHT //天猫精灵
- #define Relay_Pin 16
- #define LED_BUILTIN 14
- // 新建组件对象
- BlinkerButton Button1("B1");
- BlinkerNumber Number1("num-abc");
- bool oState = false; //记录状态
- // 按下按键即会执行该函数
- void button1_callback(const String & state) {
- BLINKER_LOG("get button state: ", state);
- if (state=="on") {
- digitalWrite(LED_BUILTIN, HIGH);
- digitalWrite(Relay_Pin,HIGH);
- // 反馈开关状态
- Button1.print("on");//返回app设备状态
- //Button1.text("打开");
- oState=1;
- } else if(state=="off"){
- digitalWrite(LED_BUILTIN, LOW);
- digitalWrite(Relay_Pin, LOW);
- // 反馈开关状态
- Button1.print("off");
- //Button1.text("关闭");
- oState=0;
- }
- }
- void heartbeat() //心跳包
- {
- if (oState== true) {
- Button1.print("on");
- }
- else Button1.print("off");
- // Button1.icon("fas fa-lightbulb");
- // Button1.color("#fddb00");
- // Button1.text("关闭","打开");
- //Number1.print(WiFi.RSSI()); //信号强度
- }
- //天猫精灵
- void aligeniePowerState(const String & state)
- {
- BLINKER_LOG("need set power state: ", state);
- if (state == BLINKER_CMD_ON) {
- digitalWrite(LED_BUILTIN, HIGH);
- digitalWrite(Relay_Pin, HIGH);
- BlinkerAliGenie.powerState("on");
复制代码
|
|