I am using the STEM account. I have one device with 5 variables sending data every 10 seconds via MQTT. So that should be within the limits. But nothing seems to be arriving. If I comment out any 3 of the 5 variables, it works… in any combination… but not if I try to submit 3 or more variables. This is the payload I would like to send:
{ “airtemperature”: {“value”: 2.00 }, “airhumidity”: {“value”: 6.00 }, “airpressure”: {“value”: 0.04 }, “rateofrain”: {“value”: 5.00 }, “waterlevel”: {“value”: 6.00 } }
Code below…
Any help to this newbee would be much appreciated…
Best regards,
zeGerman
float airTemperature = random(0, 9);
float airPressure = random(0, 9);
float airHumidity = random(0, 9);
rateofrain = random(0, 9);
lastsmoothwaterlevel = random(0, 9);
/* 4 is mininum width, 2 is precision; float value is copied onto str_temp*/
dtostrf(airTemperature, 4, 2, str_temp);
dtostrf(airPressure/100, 4, 2, str_pres);
dtostrf(airHumidity, 4, 2, str_hum);
dtostrf(lastsmoothwaterlevel, 4, 2, str_waterlevel);
dtostrf(rateofrain, 4, 2, str_rateofrain);
sprintf(topic, "%s", ""); // Cleans the topic content
sprintf(topic, "%s%s", "/v1.6/devices/", DEVICE_WELL);
sprintf(payload, "{%s", ""); // opening braket
sprintf(payload, "%s \"%s\":", payload, VARIABLE_TEMP); // Adds the variable label
sprintf(payload, "%s {\"value\": %s", payload, str_temp); // Adds the value
//sprintf(payload, "%s, \"context\":{\"lat\": %s, \"lng\": %s}", payload, str_lat, str_lng); // Adds context
sprintf(payload, "%s }", payload); // closes variable
sprintf(payload, "%s, ", payload); // next variable
sprintf(payload, "%s \"%s\":", payload, VARIABLE_HUM); // Adds the variable label
sprintf(payload, "%s {\"value\": %s", payload, str_hum); // Adds the value
sprintf(payload, "%s }", payload); // closes variable
sprintf(payload, "%s, ", payload); // next variable
sprintf(payload, "%s \"%s\":", payload, VARIABLE_PRES); // Adds the variable label
sprintf(payload, "%s {\"value\": %s", payload, str_pres); // Adds the value
sprintf(payload, "%s }", payload); // closes variable
sprintf(payload, "%s, ", payload); // next variable
sprintf(payload, "%s \"%s\":", payload, VARIABLE_RATEOFRAIN); // Adds the variable label
sprintf(payload, "%s {\"value\": %s", payload, str_rateofrain); // Adds the value
sprintf(payload, "%s }", payload); // closes variable
sprintf(payload, "%s, ", payload); // next variable
sprintf(payload, "%s \"%s\":", payload, VARIABLE_WATERLEVEL); // Adds the variable label
sprintf(payload, "%s {\"value\": %s", payload, str_waterlevel); // Adds the value
sprintf(payload, "%s }", payload);
sprintf(payload, "%s }", payload); // Closes the dictionary brackets
mqttclient.publish(topic, payload);
mqttclient.loop();