smd.iotkit2.ch / Mbed 2 deprecated 2-07-04-Uebung

Dependencies:   EthernetInterface TMP175 mbed-rtos mbed

Fork of HTTP_POST by smd.iotkit2.ch

main.cpp

Committer:
stefan1691
Date:
2015-06-07
Revision:
6:48a4698a3416
Parent:
5:13c63366d788
Child:
7:4972e81b4b17

File content as of revision 6:48a4698a3416:

/** HTTP POST Beispiel
*/
#include "mbed.h"
#include "HTTPClient.h"
#include "HTTPText.h"
#include "EthernetInterface.h"

EthernetInterface eth;
// HTTPClient Hilfsklasse
HTTPClient http;
// I/O Buffer
char str[512];

DigitalOut myled(LED1);

int main()
{
    printf("HTTP Client - POST\n");
    eth.init();
    eth.connect();

    while(1) 
    {
        myled = 1;

        // Hilfsklasse um die Response vom Server zu formatieren     
        HTTPText inText(str, 512);
        
        // MAP (Argument=Wert) 
        HTTPMap map;
        map.put("DigitalOut", "LED1");
        map.put("write", "1");
        
        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/action", map, &inText);
        if ( ! ret ) 
        {
            printf("Executed POST successfully - read %d characters\n", strlen(str));
            printf("Result: %s\n", str);
        } 
        else 
        {
            printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
        }
        
        myled = 0;

        wait(10);
    }
    //eth.disconnect();
}