0

我正在尝试在PubNub.publish(channel, msg)命令中将 char 数组变量作为“msg”传递。命令中的“msg”参数需要采用 JSON 数组格式,但我的“输入”变量是 char 数组。代码是粒子光子的固件

这有效:

    char msg[64] = "{\"Device\":\"on\"}";
    PubNub.publish(channel, msg);

但这不起作用

    char msg[64] = "{\"DeviceID\": input}"; //'input' is my char variable for storing serial data 
    PubNub.publish(channel, msg);

@craig Conover 下面是“输入”变量的代码,其中有数据。它正确发布到particle.io,但不发布到 PubNub:

   if(Serial1.available()){ 
    Particle.publish("Tagged", "Tag Detected"); 
    count = 0; 
    while(Serial1.available() && count < 12) // Read 12 characters and store   them in input array 
    { 
     input[count] = Serial1.read(); 
     count++; 
     delay(5);
    }
    Particle.publish("tagnumber", input, PRIVATE);   
    char msg[64] = "{\"DeviceID\": input}";    //'input' is my char variable for storing serial data 
    PubNub.publish(channel, msg);
4

0 回答 0