I have a Duemilanove type board with a W5100 Ethernet Shield. I am reading data from a DHT11 Temperature-Humidity sensor. Running 1.02 IDE.

I have it successfully sending integer data to https://cosm.com/feeds/96820

BUT I really want to be sending floating point data.

Does anyone have a working example of doing this??

I have looked through lots of stuff about using separate Float-to-String code, using a C++ library, and advice that says "Don't Use Strings, even if they are in the Arduino IDE distribution".. I THOUGHT "It can't be that hard!".. but after 4 or 5 hours of floundering and crashing I'd like your advice!

If you are doing binary transfer, remember that the Arduino 'double' is actually the same as 'float' on other systems, and the AVR is little endian.

From your question however, I assume you are trying to write out the value as a sequence of characters, transmit them via the network, and then the program on the other side will do scanf or similar function to convert the number back to the internal representation used on that system. You can't use the *printf functions by default, since the AVR printf is compiled without floating point support (to save a lot of code space). It looks like the IDE has alternate forms of printf/scanf that include the floating point support, but I don't know how to get those libraries included.

Rob, you know more about DHT11/DHT22 than anyone I think. I guess I have been looking at the examples that do Serial.print with (float) of the values. Hmmm..They do conversions to Fahrenheit and Dew Point using Float.

How about DHT22?? I have one and might use that also.

I am trying to write a good clear example of using Pachube to send sensor data to the web and graph it, for a workshop I'll be doing. Probably will be better after it's Clear to ME !!

Other: I also plan to use DS18B20 sensors, that will return Float data. Rob, the pointer you gave uses DS18B20 and I need to dig into that. It uses a library that hides the details of building the HTTP PUT format characters. Maybe that's good. I was hoping to understand the gritty details..

Michael, I tried dtostrf but backed off when it (my code anyway) crashed after one loop. Took it out and OK.. Memory Leaks? String overlays? hard to debug. It uses a char buffer; Would I have to manually assure the data is zero/nul terminated?

HazardsMind, that's an interesting site.. not Pachube but they do send float data.

OK, back to the fray. Many thanks for the pointers and I will post back what I learn and I will be putting an example up with lots of How-To embedded.

Rob, the pointer you gave uses DS18B20 and I need to dig into that. It uses a library that hides the details of building the HTTP PUT format characters. Maybe that's good. I was hoping to understand the gritty details..

The solution seems to be in this "new" cosm lib - https://github.com/blawson/PachubeArduino -

I got it working well with the Cosm-Arduino library. (Links in the code example below). It makes it easy to change the number of variables(streams) and if they are int or float. I have it running on https://cosm.com/feeds/96891

Tomorrow I will work on integrating DHT11 and DS18B20 sensors in an example. For now it just sends phoney changing int and float data.

Many thanks to all.. This is a community I am very happy to be part of!

OK, let's see if I know how to do the Code Thing...

OH: Please nitpick my format and comments in this code etc.. I want this to be as clear as I wished it was at 1AM last night. Think of very inexperienced Arduino enthusiasts reading this, not BitHeads like Rob :-) There will be a WIKI page of How-to and explanation to go with this code.

Technically, these sensors do not return float data, but scaled integers. The DS18B20 returns an integer whose LS bit is 2-4 °C (1/16 °C), so it can be considered °C times 16. The DHT22 returns an integer that is °C times ten, but it also has a non-standard way to represent negative numbers; the MS bit is an independent sign bit and the remainder of the data is an absolute value.

Of course if there is a library involved to read the sensor it could well return a float after converting the data from the sensor.

I read the DS18B20 using the OneWire.h library, which just handles the details of the communication and returns the data directly from the sensor. I use integer arithmetic to convert it to °F times ten. To send it to Cosm, I use the value/10 and value%10, along with itoa() and strcat() to build the required CSV representation including the decimal point.

@Jack, You are correct in that these sensors are not natively Floating Point. But I feel I need to be able to manipulate their result as Float, do conversions and derive new data like differentials etc. That was the motivation for handling Float as Float. You methods are more flexible (and probably more computationally efficient) but I am trying to support relative beginners in the Arduino world. Thanks for the perspective.

@Rob ..Hmmm... Maybe my position on Net Neutrality will change. With about 3E9 heartbeats so far I want to maximize my number as far as possible.