Publish data not included in webhook json

I send GPS coordinates from the device, but it doesn’t get included in the webhook json.

Device type: Photon
Firmware version: 0.7.0-rc3
Firmware flashed from: Build/OTA

Relevant bits of code and status messages along the way:

String lat = "1";
String lon = "1";
float alt = 1;

Insert GPS data:

lat = gga.latitude; 
lon = gga.longitude;
alt = gga.altitude;

Package up the event:

String data = String::format(
"{ \"lat\":%s, \"lon\":%s, \"alt\":%f, \"UVindex\":%f }", lat.c_str(), lon.c_str(), alt, UVindex);
  Particle.publish("Burst", data, PRIVATE);

In the event log I can see that all the data is there, so the publish() call should be correctly formed (?):

"name": "Burst",
"data": "{ \"lat\":5922.5274, \"lon\":01805.2055, \"alt\":30.600000, \"UVindex\":0.000000 }",
"ttl": 60,
"published_at": "2017-09-07T06:18:26.889Z",
"coreid": "330043000c47XXXXXXXXXXXXX"

In the “raw body” from it just doesn’t show up (same in production environment):


The fields are just empty, and oddly enough altcontains the value it was initialised with (in setup()). Not sure what to try next?

Set up CLI (install nodejs etc) and flash with a previous version of the firmware? Thought I could easily change back to an earlier version in Build as I think I’ve done that previously (?) but not possible (?) now. Looks like an error in the json building process though…

Happy to provide more info as needed

As mentioned in the other thread, you should wrap your values in double quotes in the outgoing JSON string for the webhook process to pick them up correctly.

Thank you for taking the time to look at this.

I tried it with one of the values and it didn’t change anything, will try with all of the values at the same time to see if it makes a difference.

Another thing is you once have lon and another time long - which is the correct one?
Can you also show your webhook definition?

1 Like

Sorry about the delayed response, had to put this away for a while.

Not sure what you mean, I’m just using long as the label; the key of the key-value pair in the json. This is as specified by the target API.

Just got it to work now. Short story; converted the string values from the Particle GPS lib into floats.

For reference, here is the webhook definition;

"daddress": "{{PARTICLE_DEVICE_ID}}",
"dmodel": "Electron",
"dtype": "Particle",
"apitoken": "ffeecef0-3d01-457c-a801-XXXXXXXXXXXX",
"alt": "1",
"lat": "{{lat}}",
"long": "{{lon}}",
"metrics": [
  "metric": "UVindex",
  "value": "{{UVindex}}"

OK, I now tried some code that seems to do what I’d expect- even with String variables (which I always advise not to use) - after getting all the above input.

void setup()   
   pinMode(D7, OUTPUT);

void loop() 
  static uint32_t ms = 0;
  if (millis() - ms < 5000) return;
  ms = millis();
  String lat("123.45");
  String lon("543.21");
  float  alt = 987.65;
  float  UVindex = 0.789;
  char data[128];
  snprintf(data, sizeof(data), "{ \"lat\":\"%s\", \"lon\":\"%s\", \"alt\":\"%.2f\", \"UVindex\":\"%.2f\" }", lat.c_str(), lon.c_str(), alt, UVindex);
  // works just the same
  //snprintf(data, sizeof(data), "{ \"lat\":%s, \"lon\":%s, \"alt\":%.2f, \"UVindex\":%.2f }", lat.c_str(), lon.c_str(), alt, UVindex);

  Particle.publish("Burst", data, PRIVATE);

  digitalWrite(D7, !digitalRead(D7));

produces this in

{"data":"{ \"lat\":\"123.45\", \"lon\":\"543.21\", \"alt\":\"987.65\", \"UVindex\":\"0.79\" }","ttl":60,"published_at":"2017-09-11T07:44:26.901Z","coreid":"xxxxxxxxxxxxxxxxxxxxxxx","name":"Burst"}

and this in

              User-Agent: ParticleBot/1.1 (
              Cf-Ray: 39c90078afa80f03-IAD
              Content-Length: 405
              Via: 1.1 vegur
              Cf-Visitor: {"scheme":"https"}
              Accept: application/json
              X-Request-Id: b435ca4d-084d-4657-a849-fd6a0fef9675
              Content-Type: application/json
              Connection: close
              Connect-Time: 1
              Total-Route-Time: 0
              Cf-Ipcountry: US
              Accept-Encoding: gzip

{"event":"Burst","data":"{ \"lat\":\"123.45\", \"lon\":\"543.21\", \"alt\":\"987.65\", \"UVindex\":\"0.79\" }","published_at":"2017-09-11T07:44:26.901Z","coreid":"xxxxxxxxxxxxxxxxxxxxxxx","metrics":[{"value":"0.79","metric":"UVindex"}],"long":"543.21","lat":"123.45","alt":"1","apitoken":"ffeecef0-3d01-457c-a801-XXXXXXXXXXXX","dtype":"Particle","dmodel":"Electron","daddress":"xxxxxxxxxxxxxxxxxxxxxxx"}

The only “unexpected” value is "alt":"1" but that is due to the hardcoded “1” in the webhook definition :wink: