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.
Locked
User avatar
stevesmith
 
Posts: 8
Joined: Sat Nov 15, 2014 5:22 pm

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

Post by stevesmith »

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

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

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 BANNED 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!

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

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

Post by uniontownlabs »

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

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

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

Post by stevesmith »

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!".

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

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

Post by stevesmith »

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

User avatar
markwal
 
Posts: 12
Joined: Tue Apr 14, 2015 6:16 pm

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

Post by markwal »

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.

User avatar
markwal
 
Posts: 12
Joined: Tue Apr 14, 2015 6:16 pm

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

Post by markwal »

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

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

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

Post by stevesmith »

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

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

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

Post by Karl33to »

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

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

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

Post by huguescmoi »

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

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

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

Post by clemens »

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 :).

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”