Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Can't post a float with AIO REST library on ESP8266
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Can't post a float with AIO REST library on ESP8266

by stevesmith on Tue Jan 12, 2016 1:15 pm

Hi. Using all the setup from the ESP8266 example in the Adafruit IO Arduino library, I can post an interger to a feed, but posting a float doesn't work.

This works:
Code: Select all | TOGGLE FULL SIZE
void loop() {
  if (testFeed.send(12)) {
    Serial.println(F("Wrote value to feed"));
  }
  else {
    Serial.println(F("Error writing value to feed!"));
  }
  delay(10000);
}


But if you change "testFeed.send(12)" to "testFeed.send(12.1)" it throws the error. I'm guessing it's something to do with this in Adafruit_IO_Arduino.cpp (perhaps not working on the ESP8266, where the int version does?):
Code: Select all | TOGGLE FULL SIZE
bool Adafruit_IO_Feed::send(float value) {
    // Convert float to string using scientific notation, then send the value
    // (being careful not to quote it).
    memset(_converted, 0, sizeof(_converted));
    #if defined(ARDUINO_ARCH_AVR)
        // Use avrlibc dtostre function on AVR platforms.
        dtostre(value, _converted, 10, 0);
    #else
        // Otherwise fall back to snprintf on other platforms.
        snprintf(_converted, sizeof(_converted)-1, "%f", value);
    #endif
    return _adapter->send(_name, _converted, _key, false);
}


Does anyone have anything that's not an ESP8266 that they can test this on? I don't have any other wifi modules. Thanks!

stevesmith
 
Posts: 8
Joined: Sat Nov 15, 2014 5:22 pm

Re: Can't post a float with AIO REST library on ESP8266

by uniontownlabs on Tue Jan 12, 2016 1:20 pm

Which version of the ESP8266 board package are you using? v2.0 from the board manager might fix the issue you are seeing. Check out this GitHub issue for more info: https://github.com/adafruit/io-issues/issues/100

uniontownlabs
 
Posts: 112
Joined: Wed Dec 17, 2014 10:56 pm

Re: Can't post a float with AIO REST library on ESP8266

by stevesmith on Tue Jan 12, 2016 1:51 pm

Thanks for replying so quickly Todd! I'm using v2.0 from the boards manager. I've just looked at the link you gave me, and so tried it as a generic ESP module instead of a NodeMCU, but that still gives "Error writing value to feed!".

stevesmith
 
Posts: 8
Joined: Sat Nov 15, 2014 5:22 pm

Re: Can't post a float with AIO REST library on ESP8266

by stevesmith on Tue Jan 12, 2016 3:15 pm

I've found a workaround. Using dtostrf on it and posting the string works :).

stevesmith
 
Posts: 8
Joined: Sat Nov 15, 2014 5:22 pm

Re: Can't post a float with AIO REST library on ESP8266

by markwal on Thu Jan 14, 2016 2:17 am

I've got the 2.0.0 version of the ESP8266 board package. snprintf(_converted, sizeof(_converted), "%f", value) gives "%f" as the result. And _adapter->send fails.

I'll give the dtostrf workaround a try.

markwal
 
Posts: 11
Joined: Tue Apr 14, 2015 6:16 pm

Re: Can't post a float with AIO REST library on ESP8266

by markwal on Thu Jan 14, 2016 2:22 am

Looks like several other people have hit this already. There is an issue and a pull request on the Adafruit IO library: https://github.com/adafruit/Adafruit_IO_Arduino/pull/2

markwal
 
Posts: 11
Joined: Tue Apr 14, 2015 6:16 pm

Re: Can't post a float with AIO REST library on ESP8266

by stevesmith on Thu Jan 14, 2016 1:15 pm

Great, thanks Mark. I'll patch my library with that fix in the meantime.

stevesmith
 
Posts: 8
Joined: Sat Nov 15, 2014 5:22 pm

Re: Can't post a float with AIO REST library on ESP8266

by Karl33to on Fri Jan 15, 2016 2:17 pm

That patch has been working nicely for me. No more notchy charts, thanks!

Karl33to
 
Posts: 2
Joined: Mon Jan 11, 2016 3:37 pm

Re: Can't post a float with AIO REST library on ESP8266

by huguescmoi on Wed Feb 03, 2016 3:28 pm

Where is the patch you are talking about ? Still no joy for posting floats...

huguescmoi
 
Posts: 13
Joined: Sat Jan 23, 2016 12:29 pm

Re: Can't post a float with AIO REST library on ESP8266

by clemens on Wed Feb 03, 2016 4:38 pm

This patch https://github.com/exbarboss/Adafruit_I ... 216dcbabbc

or this workaround viewtopic.php?f=56&t=87611&p=441930#p441189
I've found a workaround. Using dtostrf on it and posting the string works :).

clemens
 
Posts: 41
Joined: Fri Jan 06, 2012 12:21 am

Please be positive and constructive with your questions and comments.