Albin76 / Home_assistant_MQTT

Sensors and control via MQTT
0 stars 0 forks source link

Change convert to string in from serial #27

Open Albin76 opened 3 years ago

Albin76 commented 3 years ago

Use this instead in Gateway to set decimals: dtostrf(floatvar, StringLengthIncDecimalPoint, numVarsAfterDecimal, charbuf);

Where floatvar float variable StringLengthIncDecimalPoint This is the length of the string that will be created numVarsAfterDecimal The number of digits after the deimal point to print charbuf the array to store the results

static float f_val = 123.6794; static char outstr[15]; dtostrf(f_val,7, 3, outstr); Serial.begin(9600); Serial.println(outstr);

ref: https://www.hobbytronics.co.uk/arduino-float-vars