Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface TMP175 mbed-rtos mbed
Fork of 2-07-04-Uebung by
Diff: main.cpp
- Revision:
- 12:61e1c14db87f
- Parent:
- 11:4822e060bf3d
--- a/main.cpp Thu Jun 18 06:23:06 2015 +0000 +++ b/main.cpp Mon Nov 30 08:15:32 2015 +0000 @@ -1,4 +1,4 @@ -/** 7.4 Sensordaten schreiben via HTTP POST +/** Schreiben von Sensoredaten auf die IoT Data Plattform ThinkSpeak */ #include "mbed.h" #include "HTTPClient.h" @@ -12,6 +12,10 @@ // I/O Buffer char str[512]; +/** ThingSpeak URL und API Key ggf. anpassen */ +char host[] = "http://iot:32600/update"; +char key[] = "FIJRKLFLZIYV72MD"; + // Sensoren AnalogIn poti ( A0 ); AnalogIn light ( A1 ); @@ -52,13 +56,14 @@ // MAP (Argument=Wert) HTTPMap map; - map.put( "poti", ftoa( 0, poti.read() ) ); - map.put( "light", ftoa(1, light.read() ) ); - map.put( "hall", ftoa( 2, hall.read() ) ); - map.put( "temp", ftoa( 3, temp.fReadTemperatureTMP175() ) ); + map.put( "key", key ); + map.put( "field1", ftoa( 0, poti.read() ) ); + map.put( "field2", ftoa(1, light.read() ) ); + map.put( "field3", ftoa( 2, hall.read() ) ); + map.put( "field4", ftoa( 3, temp.fReadTemperatureTMP175() ) ); // lokale Variante mit CGI-Script auf Raspberry Pi. Wenn nicht Funktioniert: raspi2x durch IP-Adresse ersetzen - int ret = http.post("http://raspi2x/cgi-bin/rest", map, &inText); + int ret = http.post( host, map, &inText ); if ( ! ret ) { printf("Executed POST successfully - read %d characters\n", strlen(str));