0

I am trying to pass a char array variable as the 'msg' in the PubNub.publish(channel, msg) command. The 'msg' parameter in the command needs to be in JSON array format but my 'input' variable is a char array. The code is firmware for a Particle Photon

This works:

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

But this doesn't work

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

@craig Conover Below is the code for "input" variable and there is data in it. It publishes correctly to particle.io but not to 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);
suda
  • 2,604
  • 1
  • 27
  • 38
Alpha1
  • 1
  • 2
  • Just publish the JSON object, not a string, like this: `{"DeviceID": "on"}`. If you are using `input` as a variable, make sure it has a value prior to publishing (don't see your code for that above). – Craig Conover Feb 12 '17 at 21:03
  • What language is this? It is not JS. – Paul Feb 13 '17 at 13:22

0 Answers0