Post by diverseg on Jun 4, 2015 15:39:35 GMT
The Gateway 2.2 Decimal/Real number input precision
Maybe someone has thoughts on this
we are currently limited to 2 decimal places in the construction of the MQTT message
In the gateway file
RFM_MQTT_GW_22.ino
mes.fltVal is of type float
in the function
void processPacket()
.
.
.
if (RealMess) { // send decimal value
dtostrf(mes.fltVal, 10,2, buff_mess); //<---------'10' minimum string width/digits including '-' negative, decimal and white space. '2' decimal places
while (buff_mess[0] == 32) { // remove any leading spaces
for (int i =0; i<strlen(buff_mess); i++) {
buff_mess = buff_mess[i+1];
}
}
}
.
.
.
I increased the decimal places to 4 and my plots/charts of sensitive(precision) data have smoothed up considerably
dtostrf(mes.fltVal, 10,4, buff_mess); //<---------'10' minimum string width/digits including '-' negative, decimal and white space. '4' decimal places
I understand the precision required varies depending on the value being measured.
I just wanted to get others thoughts on this as to what are the consequences/limitations
As far as I know in the typical arduino micro controller a float is only good to 6 decimal places.
Note:I believe the dtostrf internal buffer is limited to 20 characters as seen below
/* As of early June 2013, dtostrf is not implemented in the Arduino IDE 1.5 libraries -
but it will be implemented in the future. Use this function in the meantime
See forum.arduino.cc/index.php?topic=170564.0. */
char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {
char fmt[20];
sprintf(fmt, "%%%d.%df", width, prec);
sprintf(sout, fmt, val);
return sout;
}
Maybe someone has thoughts on this
we are currently limited to 2 decimal places in the construction of the MQTT message
In the gateway file
RFM_MQTT_GW_22.ino
mes.fltVal is of type float
in the function
void processPacket()
.
.
.
if (RealMess) { // send decimal value
dtostrf(mes.fltVal, 10,2, buff_mess); //<---------'10' minimum string width/digits including '-' negative, decimal and white space. '2' decimal places
while (buff_mess[0] == 32) { // remove any leading spaces
for (int i =0; i<strlen(buff_mess); i++) {
buff_mess = buff_mess[i+1];
}
}
}
.
.
.
I increased the decimal places to 4 and my plots/charts of sensitive(precision) data have smoothed up considerably
dtostrf(mes.fltVal, 10,4, buff_mess); //<---------'10' minimum string width/digits including '-' negative, decimal and white space. '4' decimal places
I understand the precision required varies depending on the value being measured.
I just wanted to get others thoughts on this as to what are the consequences/limitations
As far as I know in the typical arduino micro controller a float is only good to 6 decimal places.
Note:I believe the dtostrf internal buffer is limited to 20 characters as seen below
/* As of early June 2013, dtostrf is not implemented in the Arduino IDE 1.5 libraries -
but it will be implemented in the future. Use this function in the meantime
See forum.arduino.cc/index.php?topic=170564.0. */
char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {
char fmt[20];
sprintf(fmt, "%%%d.%df", width, prec);
sprintf(sout, fmt, val);
return sout;
}