arduino怎样在PubSubClient库里回调函数中读取json字符 [
本帖最后由 sunboy25 于 2023-3-13 14:05 编辑我想问一下如果arduino的PubSubClient库的回调函数中的参数payload里面字符的编码用的是json,我在callback函数里怎样使用ArduinoJson库函数修改下面的代码才能正确提取json字符?
void callback(char *topic, byte *payload, unsigned int length)
{ Serial.print("Message arrived in topic: ");
Serial.println(topic);
Serial.print("Message:");
String message;
for (int i = 0; i < length; i++)
{
message = message + (char) payload;// convert *byte to string
}
Serial.print(message);
if (message == "on") { digitalWrite(LED, LOW); } // LED on
if (message == "off") { digitalWrite(LED, HIGH); } // LED off
Serial.println();
Serial.println("-----------------------");
}
页:
[1]