I am not sure if I should be posting this here or on Stackoverflow, but since this audience likely has the most experience with Arduino, I figured this would be the best place.
I just bought an Ethernet shield, and as a first project with it, I'm trying to publish a TMP36 temperature reading to Pachube. While Pachube accepts multiple formats for your data, I'm trying to post this stuff in JSON, because I like JSON. However, I'm running into trouble getting my temperature value, which is a float, into the JSON string. I'm a Python/PHP developer, and relatively new to C, so I've googled a lot but haven't discovered the right way to do this yet. Here is my code:
float temperature = 85.4; // Or whatever
String jsonData = sprintf("{'version':'1.0.0', 'datastreams':[{'id':'%s', 'current_value':'%f'}]}\n", datastream1, temperature);
I keep getting the following error from the Arduino IDE (version 1.0): "Cannot convert 'String' to 'const char' for argument '2' to 'int sprintf(char, const char*, ...)'"
I found out I am calling sprintf() with the wrong number of arguments/arguments in the wrong order, since it does not return the formatted string. However, I'm not even sure sprintf() is the best function to use to accomplish the goal of getting the sensor's floating point value into a string. Is there a better way to do this