本帖最后由 祁老师 于 2020-6-22 00:30 编辑
- 硬件:ESP8266 01s
- 接入方式: WIFI
- package版本: esp8266-arduino-2.7.0dev|esp32-1.0.1-rc3
- blinker库版本: arduino 0.3.4
- 开发环境: Arduino
- 操作系统: Windows
- IDE 中的设置
- Module: Nodemcu1.0
- Flash Mode: ?
- Flash Size: 4MB(FS:2MB OTA:~1019KB)
- lwip Variant: v2 Lower Memory
- Reset Method: ?
- Flash Frequency: ?
- CPU Frequency: 80Mhz
- Upload Using: ?
- Upload Speed: 115200
- 手机信息及APP信息
- 小米MIX2s
- Android10 MIUI11稳定版
- blinker App版本 2.4.7
- 问题描述使用设备共享功能时,将配置好的esp8266用主设备共享给对方的子设备,主设备一切正常可以对8266进行控制,子设备则显示离线,无法对8266进行控制。8266上也收不到任何来自子设备的信息。
- 代码[mw_shl_code=arduino,true]#define BLINKER_WIFI
#define BLINKER_MIOT_OUTLET
#include <Blinker.h>
char auth[] = "206a531db6ab";
char ssid[] = "*******";
char pswd[] = "*****************";
bool oState = false, mark = 0;
//新建组件对象
BlinkerButton Button1("btn-abc");
//按下按钮后执行
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
digitalWrite(0,!digitalRead(0));
if (digitalRead(0) == 0)
{
Button1.print("off");
}
if (digitalRead(0) == 1)
{
Button1.print("on");
}
}
//小爱同学唤醒执行
void miotPowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);
if (state == BLINKER_CMD_ON) {
digitalWrite(0, 1);
BlinkerMIOT.powerState("on");
BlinkerMIOT.print();
oState = true;
}
else if (state == BLINKER_CMD_OFF) {
digitalWrite(0, 0);
BlinkerMIOT.powerState("off");
BlinkerMIOT.print();
oState = false;
}
}
//小爱查询电源状态
void miotQuery(int32_t queryCode)
{
BLINKER_LOG("MIOT Query codes: ", queryCode);
switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER :
BLINKER_LOG("MIOT Query All");
BlinkerMIOT.powerState(oState ? "on" : "off");
BlinkerMIOT.print();
break;
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
BLINKER_LOG("MIOT Query Power State");
BlinkerMIOT.powerState(oState ? "on" : "off");
BlinkerMIOT.print();
break;
default :
BlinkerMIOT.powerState(oState ? "on" : "off");
BlinkerMIOT.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(2, INPUT_PULLUP);
pinMode(0, OUTPUT);
digitalWrite(0,0);
//初始化blinker
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
//注册回调函数
BlinkerMIOT.attachPowerState(miotPowerState);
BlinkerMIOT.attachQuery(miotQuery);
Button1.attach(button1_callback);
}
void loop()
{
if (digitalRead(2) == 0 && mark == 0)
{
digitalWrite(0, !digitalRead(0));
oState = digitalRead(0);
mark = 1;
}
if (digitalRead(2) == 1 && mark == 1)
{
mark = 0;
}
Blinker.run();
}[/mw_shl_code]
跪求有大佬来救救孩子啊
|