Particle.publish -> sprintf -> Hard fault

Hey there, I am trying to particle.publish a string for my first project using a DHT22

here is an excerpt of my code:

//Particle.publish("VS",publishString); // I commented the publish for debug reasons

This sprintf creates a string with comma separated values of lightAmbient,sensorValue,lightDelta,stand
As soon as I add more %.2f I get a red SOS error code No1: Hard fault
I also tried %.1f %.0f and %.u

Temperatur,Luftfeuchtigkeit,Taupunkt come from a DHT22:

Luftfeuchtigkeit = dht.getHumidity();                           
Temperatur = dht.getTempCelcius(); 
Taupunkt = dht.getDewPoint();

I used Adafruit DHT library since it was the most downloaded
#include <Adafruit_DHT.h>

lightAmbient,sensorValue,lightDelta are float
Adafruit DHT seems to use float too

Any help would be very much appreciated :blush:

I don’t think floats are implement in printf

by the way, you should use the (safer) snprintf

sprintf() does support floats for ages already.
Withouth any info about the definition of publishString I’d put my money on that as the reason tho’ - probably too short buffer or just a char* without actually allocated memory :wink:

For seven comma seperated floats with two decimal places the buffer needs to be at least 42 bytes long
(7 x -#.##,) plus any extra places for more than one leading digits.

1 Like

Thanks ScruffR that seemed to do the trick