Hurdle 1
Now where to find a program? a working example would be nice right? In the right top corner there is a button 'Support' that will go to 'Tutorials'.
Under 'Tutorials' you will find:
"Using an Arduino + Ethernet Shield to Update a ThingSpeak Channel"
Sounds great, so you download that program into your IDE, add the API -key and then compile it.
Darn.... it doesnt compile, you try to fix it (and that is certainly possible) until you come to a point you have no idea what is required.
Apparently the program still expects everybody to use the 022 or 023 IDE.
There is a link to a Github page but that will give u a program to tweet and that is not what you want, at least not for now.
Solution
You ill find a better program to start from right here:
https://github.com/iobridge/ThingSpeak-Arduino-Exa...
That program takes a reading from the A0 port and sends that to "Field1" in your datastream
Ok so you try that, you hang a variable resistor like an LDR or NTC on port A0, add your API in the program and run it.
That works fine, but I didnt only want to read a value from an Analog port, I had a DHT11 Moisture&Temperature sensor as well as a BMP180 Pressure & temperature sensor. I figured it shouldnt be too hard.
Hurdle 2
I added the necessary libraries to the Thingspeak, added the objects and read the sensors into a variable.
The sensors however have floats as outcome and Thingspeak wants you to send strings.
With most variables it is rather easy to turn them into a string with the simple 'string' function, but it isnt that easy for floats. With floats you have to use the "dtostrf" command (which I guess stands for 'double-to-string-function'
Trying to find info on that function on internet quickly led me to endless discussions on 'how stupid' it was and people asking questions were often told "why would you need that, Serial.print will do that for you" Yeah, true, but I don't want to print, I need it because Thingspeak wants it.
Solution
To use the dtostrf command you need to set up a buffer space where the string will be stored. It works like this:
char t_buffer[10];
t=(ReadSensor);
String temp=dtostrf(t,0,5,t_buffer);
That bufferspace is important. I had it working with '7' or even '5', but when I added a second sensor that needs this function, my datastream would crash and or I got the weirdest results. I also figured that I could use the same bufferspace alternating for each sensor, but that also didnt really work, so now i have a bufferspace for each sensor.
Now I am no crack in C, so maybe there is a better way to do this, if so i would love to hear it, but this worked for me.
Hurdle3
Once I had the string conversions, I could add the data to the datastream.
The Thingspeak example program shows that for one field only, but it becomes clear pretty fast that you have to add the strings and throw in the right amount of plussesand ampersands.
Solution
So for say 4 different fields it becomes like this:
updateThingSpeak("field1="+temp+"&field2="+humid+"&field3="+pres+"&field4="+temp2);