传递一个char数组变量

时间:2017-02-12 19:34:52

标签: json pubnub particle.io particle-photon

我正在尝试传递一个char数组变量作为' msg'在 PubNub.publish(channel,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);

0 个答案:

没有答案