dencodeFromMqtt method
dynamic
dencodeFromMqtt(
- String mqttMsg
)
Implementation
dencodeFromMqtt(String mqttMsg) {
try {
// String replacedString = mqttMsg.replaceAll('\\', '');
dynamic msgMap = jsonDecode(mqttMsg);
if (_myReceiveCallback != null) {
_myReceiveCallback!(mqttMsg, msgMap);
}
} catch (e) {
print('mqtt消息解析错误,不是json数据:$mqttMsg');
if (_myReceiveCallback != null) {
_myReceiveCallback!(mqttMsg, {});
}
if (mqttMsg.contains('connect successfully! zygMqtt')) {
print('connect successfully! wxx');
if (myConnectStateCallback != null) {
myConnectStateCallback!(ZygConnectState.connected);
}
} else if (mqttMsg.contains('mqtt已断开连接 zygMqtt')) {
if (myConnectStateCallback != null) {
myConnectStateCallback!(ZygConnectState.disconnect);
}
}
}
}