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 HTTP_POST by
Diff: main.cpp
- Revision:
- 8:2ecceb32e68b
- Parent:
- 7:4972e81b4b17
- Child:
- 11:4822e060bf3d
--- a/main.cpp Mon Jun 08 12:38:20 2015 +0000
+++ b/main.cpp Mon Jun 08 13:40:14 2015 +0000
@@ -1,9 +1,10 @@
-/** HTTP POST Beispiel
+/** 7.4 Sensordaten schreiben via HTTP POST
*/
#include "mbed.h"
#include "HTTPClient.h"
#include "HTTPText.h"
#include "EthernetInterface.h"
+#include "TMP175.h"
EthernetInterface eth;
// HTTPClient Hilfsklasse
@@ -11,13 +12,36 @@
// I/O Buffer
char str[512];
+// Sensoren
+AnalogIn poti ( A0 );
+AnalogIn light ( A1 );
+AnalogIn hall ( A2 );
+TMP175 temp ( D14, D15 );
+// Separater Buffer um die Sensorwerte als String abzustellen
+char fa[4] [12];
+
DigitalOut myled(LED1);
+/** Float nach String wandeln
+ * @param pos Position in I/O Buffer
+ * @param value Wert
+ * @return Pointer auf I/O Buffer
+ */
+char* ftoa( int pos, float value )
+{
+ sprintf( fa[pos], "%4.4f", value );
+ return ( fa[pos] );
+}
+
int main()
{
printf("HTTP Client - POST\n");
eth.init();
eth.connect();
+
+ temp.vSetConfigurationTMP175( SHUTDOWN_MODE_OFF | COMPARATOR_MODE | POLARITY_0 |FAULT_QUEUE_6 | RESOLUTION_12, 0x48 );
+ temp.vSetTemperatureLowTMP175( 0.0 );
+ temp.vSetTemperatureHighTMP175( 60.0 );
while(1)
{
@@ -28,12 +52,13 @@
// MAP (Argument=Wert)
HTTPMap map;
- map.put("DigitalOut", "LED1");
- map.put("write", "1");
+ map.put( "poti", ftoa( 1, poti.read() ) );
+ map.put( "light", ftoa( 2, light.read() ) );
+ map.put( "hall", ftoa( 3, hall.read() ) );
+ map.put( "temp", ftoa( 4, temp.fReadTemperatureTMP175() ) );
- int ret = http.post("http://httpbin.org/post", map, &inText);
// 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("http://raspi2x/cgi-bin/rest", map, &inText);
if ( ! ret )
{
printf("Executed POST successfully - read %d characters\n", strlen(str));
