Problems with integration to firebase

Hello, I am having problems with the integration of webhook to send data to fireBase, I am making a node for monitoring the air quality and the weather the first part that was sending the weather sensors to particle was done correctly this was the template to do that right

and if I made the insertion of data in firebase
image
after that we started adding the data from our air quality sensors to our particle.
in this case I am doing it this way
where msg is a char array of size [512] and my string looks like this

snprintf(msg, sizeof(msg) , //imprimimos la cadena 

"{\"UT\": %u, \"VV\": %.1f , \"Precip\": %.1f , \"DV\": %.1f , \"Temp\": %.1f ,\"Hum\": %u  ,\"mVB\": %u , \"O3\": %.6f ,\"CO\": %.6f ,\"NO2\": %.6f ,\"SO2\": %.6f ,\"VGASO3\": %.14f ,\"VGASCO\": %.14f ,\"VGASNO2\": %.14f ,\"VGASSO2\": %.14f ,\"PM1\": %u ,\"PM2.5\": %u ,\"PM10\": %u ,,\"O3N\": %.6f,\"CO2N\": %.6f,\"NO2N\": %.6f,\"SO2N\": %.6f}" , 
UT,
VV, 
Precip, 
DV ,
Temp, 
Hum,  
mVB,
Sensor_O3,
Sensor_CO,
Sensor_NO,
Sensor_SO2,
av0,//voltajes de o3
av1,
av2,
av3,
PM1_0,
PM2_5,
PM10,
prom_conc_o3,
prom_conc_co,
prom_conc_no2,
prom_conc_so2
);

 Particle.publish("sensors", msg, PRIVATE);

now if I leave the following in my webhook json
image ,

when doing the test I get like

image

but in my database I do not see any data from my sensors only the “ts” arrives

image

and then I try to add the other sensors to my JSON and what appears to me is this


image

Does anyone have any idea why previously I sent the data to firebase and now it is no longer sent? I would appreciate your help. Thank you very much in advance!

You show how you construct your JSON, but have you also looked at the msg created by that code?

You may want to run that string through a JSON validator to see whether your constructed data actually is parsable.

For instance you have a double comma between PM10 and O3N

With that corrected this should render a valid (and readable) JSON

  snprintf(msg
          , sizeof(msg) 
          , "{ \"UT\":%u\r\n"
		    ", \"VV\":%.1f\r\n"
			", \"Precip\":%.1f\r\n"
			", \"DV\":%.1f\r\n"
			", \"Temp\":%.1f\r\n"
            ", \"Hum\":%u\r\n"
			", \"mVB\":%u\r\n"
			", \"O3\":%.6f\r\n"
			", \"CO\":%.6f\r\n"
			", \"NO2\":%.6f\r\n"
			", \"SO2\":%.6f\r\n"
            ", \"VGASO3\":%.14f\r\n"
			", \"VGASCO\":%.14f\r\n"
			", \"VGASNO2\":%.14f\r\n"
			", \"VGASSO2\":%.14f\r\n"
            ", \"PM1\":%u\r\n"
			", \"PM25\":%u\r\n"
			", \"PM10\":%u\r\n"
			", \"O3N\":%.6f\r\n"
			", \"CO2N\":%.6f\r\n"
			", \"NO2N\":%.6f\r\n"
			", \"SO2N\":%.6f\r\n" 
			"}" 
          , UT
          , VV 
          , Precip 
          , DV 
          , Temp 
          , Hum  
          , mVB
          , Sensor_O3
          , Sensor_CO
          , Sensor_NO
          , Sensor_SO2
          , av0//voltajes de o3
          , av1
          , av2
          , av3
          , PM1_0
          , PM2_5
          , PM10
          , prom_conc_o3
          , prom_conc_co
          , prom_conc_no2
          , prom_conc_so2
          );          

(the slightly odd format with leading commas makes adding/removing lines much easier, as each line is self contained and doesn’t require any changes to the previous or following lines - also correlating format placeholders with their repsective variables is easier)

hello and thanks change the snprintf for the one you provided me and the JSON pass it through a JSON validator and it tells me that it is ok


but I keep getting the same error

I didn’t ask for your webhook JSON template to be validated but the msg string you were passing to the webhook from your device and I’m pretty sure that was not valid.

I got confused, but it seems quite strange to me that if it worked for me less than a month ago with the weather data and now that I add more data it no longer, I think that perhaps the problem could be the integration because the chain that you already passed me it’s okay

That may be all well and good back then, but is the code that now plays up really 100% the same as it was back then?
That extra comma may have gotten into the code by accident recently when adjusting/adding/removing something else.

That’s also an argument for my way of formatting the snprintf() parameters when dealing with non-trivial strings. Adding/deleting an entire line of code is typically less prone to such errors than manipulating a few characters in an already unwieldy, hardly readable format string. A forgotten separator or stray character is easily obfuscated in such a jumble of characters.

I’d hope so, but have you also tried it against your webhook?
Since your previous string was not valid it’s no surprise that the webhook didn’t like it, but how about a now proven valid JSON?

Look, I created the webhook again and the weather data already appeared but the air quality data does not appear except for the PM10, it may be that in the JSON the q goes in quotes and the one between the braces have to be called the same ?


el JSON quedo asi:

{
  "UT": "{{UT}}",
  "VV": "{{VV}}",
  "Precip": "{{Precip}}",
  "DV": "{{DV}}",
  "Temp": "{{Temp}}",
  "Hum": "{{Hum}}",
  "mVB": "{{mVB}}",
  "O3": "{{Sensor_O3}}",
  "CO": "{{Sensor_CO}}",
  "NO2": "{{Sensor_NO2}}",
  "SO2": "{{Sensor_SO2}}",
  "VGASO3": "{{av0}}",
  "VGASCO": "{{av1}}",
  "VGASNO2": "{{av2}}",
  "VGASSO2": "{{av3}}",
  "PM1": "{{PM1_0}}",
  "PM25": "{{PM2.5}}",
  "PM10": "{{PM10}}",
  "O3N": "{{prom_conc_o3}}",
  "CO2N": "{{prom_conc_co}}",
  "NO2N": "{{prom_conc_no2}}",
  "SO2N": "{{prom_conc_so2}}",
  "ts": "{{PARTICLE_PUBLISHED_AT}}"
}

as you can see the names of each data are seen but they do not send anything …

You need to use the names you used for the JSON keys in your outgoing event not the variable names in your code - these are unknown to the webhook and hence cannot be substituted correctly.

e.g. Sensor_O3 is not found in the outgoing JSON but O3 is.

The dot in PM2.5 should also be removed.

2 Likes