[md]问题现象:json解析失败
android版本:9
手机型号:OPPO A51
开发板:esp8266 NodeMCU1.0
其他说明:
在使用小爱同学连续控制Key1 Key2 Key3时出现json解析失败
LOG信息如下
```
[52447] MQTT Ping!
[55431] APP button need set outlet: 0 set button state: off
[55535] ERROR: MQTT NOT ALIVE OR MSG LIMIT
[63805] MIOT Query codes: 0
[64115] need set outlet: 3, power state: on
[65618] APP button need set outlet: 3 set button state: on
[82542] MIOT Query codes: 0
[82870] need set outlet: 1, power state: on
[84391] APP button need set outlet: 1 set button state: on
[90724] MIOT Query codes: 0
[91031] need set outlet: 2, power state: on
[92531] APP button need set outlet: 2 set button state: on
[92635] ERROR: Print data is not Json! {"data":{"Key2":{"swi":"on"}},"fromDevice":"1EADFE10GN96GWXE44YXF11J","toDevice":"20580394bcdd11ea9a655254","deviceType":"OwnApp"}
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Exception (29):
epc1=0x4000e1b2 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
>>>stack>>>
ctx: cont
sp: 3ffff740 end: 3fffffc0 offset: 0190
3ffff8d0: 00000005 00000001 3ffef904 40201622
3ffff8e0: 00000001 3ffef904 3ffef904 4020e4a4
3ffff8f0: 3ffff910 3ffff91c 3ffe8a46 4021fd9e
3ffff900: 3ffe8ace 3ffef904 3ffe8a46 4020e53c
3ffff910: 74617473 00000065 85ff0350 3fff344c
3ffff920: 0010001f 09fe0022 3ffef904 402060a4
3ffff930: 3ffff9d0 3ffe8ace 3ffef904 4020e783
3ffff940: 80000000 3fff8f84 00000020 40100bbf
3ffff950: 00000000 3ffefbc9 3ffff9a4 00000000
3ffff960: 00000000 74617473 3fff0065 8521fb8d
3ffff970: 00007d0a 3ffff9b0 3ffef904 000000f4
3ffff980: 3ffe86ec 00000000 3ffef904 4020fe7d
3ffff990: 3fff0330 3fff8b7c 3fff8b86 3fff8f6c
3ffff9a0: 3fff8f7c 3fff8f6c 3fff8f6c 80000020
3ffff9b0: 00000000 00000000 80ff97d3 3ffff974
3ffff9c0: 3ffff964 00000400 00000000 000000ac
3ffff9d0: 3ffff9a4 3ffff994 4010047c 00000000
3ffff9e0: 3fff0330 3fff0334 3ffefdf8 4020e0bd
3ffff9f0: 02126369 00000000 3fff08b0 40215c4d
3ffffa00: 00000001 00000000 3ffefdf8 00000001
3ffffa10: 00000001 00000000 3ffefdf8 4020e1b2
3ffffa20: 3fff12b4 40219a40 3ffef904 00000001
3ffffa30: 00000001 3ffefb04 3ffef904 40210649
3ffffa40: 007a1200 89151303 40100400 0001cab6
3ffffa50: 00000000 00000000 00000001 40100384
3ffffa60: 021262e7 3ffffa8c 0000be95 3ffef904
3ffffa70: 0000c350 059668ec 0000be95 3ffef904
3ffffa80: 0000c350 059668ec 0000be95 4021089d
3ffffa90: 00016974 80000002 3ffffac0 4021fb8d
3ffffaa0: 80006e6f 3ffffac0 3ffef8d6 00000002
3ffffab0: 3ffe8dfd 3ffef904 3ffef8d6 40210a04
3ffffac0: 00006e00 00006574 80fffaf0 4021fb8d
3ffffad0: 000d000f 80ff003a 3ffef8d8 00000001
3ffffae0: 3ffffb80 3ffef8dc 3ffef8d8 40210b77
3ffffaf0: 00006e00 3ffffb80 80ff877b 40006e00
3ffffb00: 3ffe8823 80000002 3f006e00 4021fd68
3ffffb10: 80fe872c 00006e00 3ffffb80 8021ffc9
3ffffb20: 3ffe8dfd 40000000 3ffef904 00000001
3ffffb30: 3ffe872c 00000002 3ffefd04 4020dbf5
3ffffb40: 3fff9300 3fff8774 3fff8786 3fff8b54
3ffffb50: 3fff8b74 3fff8b64 3fff8b54 000000a0
3ffffb60: 0000000b 3fff836c 3fff8382 3fff873c
3ffffb70: 3fff876c 3fff875c 3fff875c 00000020
3ffffb80: 65006e6f 00000000 82fffbd0 3fff93c4
3ffffb90: 001b001f 00000000 3ffefdf8 00000001
3ffffba0: 00000001 00000023 3ffffb54 3ffffb44
3ffffbb0: 3ffffb74 3ffffb64 00000000 00000000
3ffffbc0: 00000001 3ffefb04 3ffef904 4021066c
3ffffbd0: 3fff938c 0023002f 00100400 00016390
3ffffbe0: 00000000 00000000 00000001 40100384
3ffffbf0: 019b1ee5 3ffffc1c 0000c211 3ffef904
3ffffc00: 0000c350 050c96da 0000c211 3ffef904
3ffffc10: 0000c350 050c96da 0000c211 4021089d
3ffffc20: 000149a8 80000002 3ffffc50 4021fb8d
3ffffc30: 80006e6f 3ffffc50 3ffef8d6 00000001
3ffffc40: 3ffe8dfd 3ffef904 3ffef8d6 40210a04
3ffffc50: 00006e00 00006574 80fffc80 4021fb8d
3ffffc60: 000d000f 80ff003a 3ffef8d7 00000001
3ffffc70: 3ffffd10 3ffef8dc 3ffef8d7 40210b77
3ffffc80: 00006e00 3ffffd10 80ff7f6b 40006e00
3ffffc90: 3ffe8823 80000002 3f006e00 4021fd68
3ffffca0: 80fe872c 00006e00 3ffffd10 8021ffc9
3ffffcb0: 3ffe8dfd 3f800000 3ffef904 00000001
3ffffcc0: 3ffe872c 00000001 3ffefd04 4020dbf5
3ffffcd0: 3fff9300 3fff7f64 3fff7f76 3fff8344
3ffffce0: 3fff8364 3fff8354 3fff8344 000000a0
3ffffcf0: 0000000b 3fffb8f4 3fffb90a 3fffbcc4
3ffffd00: 3fffbcf4 3fffbce4 3fffbce4 00000020
3ffffd10: 65006e6f 00000000 82fffd60 3fff9364
3ffffd20: 001b001f 00000000 3ffefdf8 00000001
3ffffd30: 00000001 00000023 3ffffce4 3ffffcd4
3ffffd40: 3ffffd04 3ffffcf4 00000000 00000000
3ffffd50: 00000001 3ffefb04 3ffef904 4021066c
3ffffd60: 3fff932c 0023002f 00100400 000143b0
3ffffd70: 00000000 00000000 00000001 40100384
3ffffd80: 017643ee 3ffffdac 0000c00e 3ffef904
3ffffd90: 0000c350 03f6008f 0000c00e 3ffef904
3ffffda0: 0000c350 03f6008f 0000c00e 4021089d
3ffffdb0: 00010053 80000002 3ffffde0 4021fb8d
3ffffdc0: 80006e6f 3ffffde0 3ffef8d6 00000003
3ffffdd0: 3ffe8dfd 3ffef904 3ffef8d6 40210a04
3ffffde0: 00006e00 00006574 80fffe10 4021fb8d
3ffffdf0: 000d000f 80ff003a 3ffef8d9 00000001
3ffffe00: 3ffffea0 3ffef8dc 3ffef8d9 40210b77
3ffffe10: 00006e00 3ffffea0 80ffb4f3 40006e00
3ffffe20: 3ffe8823 80000002 3f006e00 4021fd68
3ffffe30: 80fe872c 00006e00 3ffffea0 8021ffc9
3ffffe40: 3ffe8dfd 40400000 3ffef904 00000001
3ffffe50: 3ffe872c 00000003 3ffefd04 4020dbf5
3ffffe60: 3fff9300 3fffb4ec 3fffb4fe 3fffb8cc
3ffffe70: 3fffb8ec 3fffb8dc 3fffb8cc 000000a0
3ffffe80: 0000000b 3fff38a4 3fff38ba 3fff3c74
3ffffe90: 3fff3ca4 3fff3c94 3fff3c94 00000020
3ffffea0: 65006e6f 00000000 82fffef0 3fff9304
3ffffeb0: 001b001f 00000000 3ffefdf8 00000001
3ffffec0: 00000001 00000023 3ffffe74 3ffffe64
3ffffed0: 3ffffe94 3ffffe84 00000000 00000000
3ffffee0: 00000001 3ffefb04 3ffef904 4021066c
3ffffef0: 3fff92cc 0023002f 00100400 0000fa6c
3fffff00: 00000000 00000000 00000001 40100384
3fffff10: 01218cff 3fffff3c 0000c1b0 3ffef904
3fffff20: 0000c350 03542c41 0000c1b0 3ffef904
3fffff30: 0000c350 03542c41 0000c1b0 4021089d
3fffff40: 0000d888 80000003 3fffff70 4021fb8d
3fffff50: 80fe8700 3fffff70 3ffef8d6 00000000
3fffff60: 3ffe87aa 3ffef904 3ffef8d6 40210a04
3fffff70: 00666600 3fff3300 800b000f 80efeffe
3fffff80: 3fff3500 000c000f 80efeffe 3fff0ae8
3fffff90: 3fffdad0 00000000 3ffef904 40210bb5
3fffffa0: 3fffdad0 00000000 3fff0aa8 40220d98
3fffffb0: feefeffe feefeffe 3ffe85ac 40100e79
<<<stack<<<
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 3664, room 16
tail 0
chksum 0xee
csum 0xee
v39c79d9b
```
代码如下
```
#define BLINKER_PRINT Serial //用于打开串口
#define BLINKER_WIFI //用于指定设备接入方式 wifi 接入
#define BLINKER_MIOT_MULTI_OUTLET //用于定义多插座模式
//同步设备后可显示一个插座和四个插孔(名为插孔的插座设备)
#include <Blinker.h>
#define Socket1 16
#define Socket2 5
#define Socket3 4
#define Socket4 0
#define Socket5 2
char auth[] = "5121bddd997e";
char ssid[] = "TP-LINK_2A38";
char pswd[] = "13854359579";
unsigned char Port;
bool Feedback[5];
unsigned char num_k;
unsigned char All_key_flag;
bool flag = false;
//创建APP按键的组对像
BlinkerButton Button0("Key0"); //btn-abc 名称要和app新建组件一致 总开关
BlinkerButton Button1("Key1"); //btn-abc 名称要和app新建组件一致
BlinkerButton Button2("Key2"); //btn-abc 名称要和app新建组件一致
BlinkerButton Button3("Key3"); //btn-abc 名称要和app新建组件一致
BlinkerButton Button4("Key4"); //btn-abc 名称要和app新建组件一致
BlinkerButton Button5("Key5"); //btn-abc 名称要和app新建组件一致
//APP按键回调函数 APP端按下按键即会执行该函数 按键回调函数
//按键0 回调函数 总开关
void button0_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
if (state=="on") {
digitalWrite(Socket1, LOW);
digitalWrite(Socket2, LOW);
digitalWrite(Socket3, LOW);
digitalWrite(Socket4, LOW);
digitalWrite(Socket5, LOW);
// 反馈开关状态
Button0.print("on");
Button1.print("on");
Button2.print("on");
Button3.print("on");
Button4.print("on");
Button5.print("on");
//设置回调
for(u8_t i = 0;i<5;i++)
{
Feedback = 1;
}
} else if(state=="off"){
digitalWrite(Socket1, HIGH);
digitalWrite(Socket2, HIGH);
digitalWrite(Socket3, HIGH);
digitalWrite(Socket4, HIGH);
digitalWrite(Socket5, HIGH);
// 反馈开关状态
Button0.print("off");
Button1.print("off");
Button2.print("off");
Button3.print("off");
Button4.print("off");
Button5.print("off");
//设置回调
for(u8_t i = 0;i<5;i++)
{
Feedback = 0;
}
}
num_k = 5;
}
//按键1 回调函数
void button1_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
if (state=="on") {
digitalWrite(Socket1, LOW);
// 反馈开关状态
Button1.print("on");
Feedback[1] = 1;
} else if(state=="off"){
digitalWrite(Socket1, HIGH);
// 反馈开关状态
Button1.print("off");
Feedback[0] = 0;
}
num_k = 1;
if(Feedback[0]+Feedback[1]+Feedback[2]+Feedback[3]+Feedback[4]==5)
{
Button0.print("on");
}
else
{
Button0.print("off");
}
}
//按键2 回调函数
void button2_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state=="on") {
digitalWrite(Socket2, LOW);
// 反馈开关状态
Button2.print("on");
Feedback[2] = 1;
} else if(state=="off"){
digitalWrite(Socket2, HIGH);
// 反馈开关状态
Button2.print("off");
Feedback[2] = 0;
}
num_k = 2;
if(Feedback[0]+Feedback[1]+Feedback[2]+Feedback[3]+Feedback[4]==5)
{
Button0.print("on");
}
else
{
Button0.print("off");
}
}
//按键3 回调函数
void button3_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
if (state=="on") {
digitalWrite(Socket3, LOW);
// 反馈开关状态
Button3.print("on");
Feedback[3] = 1;
} else if(state=="off"){
digitalWrite(Socket3, HIGH);
// 反馈开关状态
Button3.print("off");
Feedback[3] = 0;
}
num_k = 3;
if(Feedback[0]+Feedback[1]+Feedback[2]+Feedback[3]+Feedback[4]==5)
{
Button0.print("on");
}
else
{
Button0.print("off");
}
}
//按键4 回调函数
void button4_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
if (state=="on") {
digitalWrite(Socket4, LOW);
// 反馈开关状态
Button4.print("on");
Feedback[4] = 1;
} else if(state=="off"){
digitalWrite(Socket4, HIGH);
// 反馈开关状态
Button4.print("off");
Feedback[4] = 0;
}
num_k = 4;
if(Feedback[0]+Feedback[1]+Feedback[2]+Feedback[3]+Feedback[4]==5)
{
Button0.print("on");
}
else
{
Button0.print("off");
}
}
//按键5 回调函数
void button5_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
if (state=="on") {
digitalWrite(Socket5, LOW);
// 反馈开关状态
Button5.print("on");
Feedback[0] = 1;
} else if(state=="off"){
digitalWrite(Socket5, HIGH);
// 反馈开关状态
Button5.print("off");
Feedback[0] = 0;
}
num_k = 0;
if(Feedback[0]+Feedback[1]+Feedback[2]+Feedback[3]+Feedback[4]==5)
{
Button0.print("on");
}
else
{
Button0.print("off");
}
}
//APP 内按键反馈
void button_callback()
{
BLINKER_LOG("APP button need set outlet: ", num_k," set button state: ",Feedback[num_k]?"on":"off");
switch (num_k)
{
case 1:
Button1.print(Feedback[num_k]?"on":"off");
break;
case 2:
Button2.print(Feedback[num_k]?"on":"off");
break;
case 3:
Button3.print(Feedback[num_k]?"on":"off");
break;
case 4:
Button4.print(Feedback[num_k]?"on":"off");
break;
case 0:
Button5.print(Feedback[num_k]?"on":"off");
break;
default:
break;
}
Blinker.delay(50000);
if(Feedback[0]+Feedback[1]+Feedback[2]+Feedback[3]+Feedback[4]==5)
{
Button0.print("on");
}
else
{
Button0.print("off");
}
Blinker.delay(1500);
}
//用户自定义电源类操作的回调函数: 小爱电源类回调
void miotPowerState(const String & state, uint8_t num)
{
BLINKER_LOG("need set outlet: ", num, ", power state: ", state);
num_k = num;
if (num == 1)
{
Port = Socket1; //指定每一路开关对应在开发板上的通道接口
}
else if (num == 2)
{
Port = Socket2;
}
else if (num == 3)
{
Port = Socket3;
}
else if (num == 4)
{
Port = Socket4;
}
else if(num==0)
{
Port = Socket5;
}
if (state == BLINKER_CMD_ON)
{
digitalWrite(Port, LOW);
Feedback[num] = 1;
BlinkerMIOT.powerState("on");
}
else if (state == BLINKER_CMD_OFF)
{
digitalWrite(Port, HIGH);
Feedback[num] = 0;
BlinkerMIOT.powerState("off");
}
Blinker.delay(1500);
button_callback();
BlinkerMIOT.print();
flag = true;
}
//用户自定义设备查询的回调函数:
void miotQuery(int32_t queryCode)
{
BLINKER_LOG("MIOT Query codes: ", queryCode);
switch (queryCode)
{
case 0: //查询所有设备的情况
switch (num_k) //APP 内按键反馈
{
case 1:
BlinkerMIOT.powerState(Feedback[num_k]?"on":"off",num_k);
break;
case 2:
BlinkerMIOT.powerState(Feedback[num_k]?"on":"off",num_k);
break;
case 3:
BlinkerMIOT.powerState(Feedback[num_k]?"on":"off",num_k);
break;
case 4:
BlinkerMIOT.powerState(Feedback[num_k]?"on":"off",num_k);
break;
case 0:
BlinkerMIOT.powerState(Feedback[num_k]?"on":"off",num_k);
break;
default:
break;
}
break;
case BLINKER_CMD_QUERY_PM25_NUMBER : /* 下面的这些用不到,供参考*/
BLINKER_LOG("MIOT Query PM25");
BlinkerMIOT.pm25(20);
BlinkerMIOT.print();
break;
default :
BlinkerMIOT.temp(20);
BlinkerMIOT.humi(20);
BlinkerMIOT.pm25(20);
BlinkerMIOT.co2(20);
BlinkerMIOT.print();
break;
}
BlinkerMIOT.print();
}
//智能配网函数
void smartConfig()
{
WiFi.mode(WIFI_STA);
WiFi.beginSmartConfig();
while (1)
{
//Serial.print(".");
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
if (WiFi.smartConfigDone())
{
Serial.println("OK!");
digitalWrite(LED_BUILTIN, LOW);
break;
}
}
WiFi.stopSmartConfig();
}
//WiFi初始化函数
void WiFi_setup()
{
unsigned char count = 0;
bool WIFI_Status = true;
while(WiFi.status()!=WL_CONNECTED)
{
if(WIFI_Status)
{
Serial.print(".");
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
count++;
if(count>=5)//5s
{
WIFI_Status = false;
//Serial.println("WiFi连接失败,请用手机进行配网");
}
}
else
{
smartConfig(); //微信智能配网
}
}
}
//初始化函数
void setup() {
//开启串口
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial); //串口打印调试信息
WiFi_setup();
Blinker.begin(auth, WiFi.SSID().c_str(), WiFi.psk().c_str());
//初始化LED引脚
pinMode(Socket1,OUTPUT);
pinMode(Socket2,OUTPUT);
pinMode(Socket3,OUTPUT);
pinMode(Socket4,OUTPUT);
pinMode(Socket5,OUTPUT);
//默认输出高电平 设备处于关闭状态
digitalWrite(Socket1,HIGH);
digitalWrite(Socket2,HIGH);
digitalWrite(Socket3,HIGH);
digitalWrite(Socket4,HIGH);
digitalWrite(Socket5,HIGH);
//注册APP按键回调函数
Button0.attach(button0_callback);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
Button4.attach(button4_callback);
Button5.attach(button5_callback);
//初始化按键 设置所有的按键处于关闭状态
Button0.print("off");
Button1.print("off");
Button2.print("off");
Button3.print("off");
Button4.print("off");
Button5.print("off");
//注册电源类回调函数 小爱
BlinkerMIOT.attachPowerState(miotPowerState);
//注册回调函数: 用户自定义设备查询
BlinkerMIOT.attachQuery(miotQuery);
}
void loop() {
Blinker.run(); /*每次运行都会将设备收到的数据进行一次解析。
在使用WiFi接入时,该语句也负责保持网络连接*/
Blinker.delay(50000);
button_callback();
Blinker.delay(1500);
}
```
2020年8月1日[/md] |