Programm erwartet auf der seriellen Schnittstelle eine Eingabe, die es an den IntrospectionEP des Servers schickt und bei erfolgreicher Überprüfung (Status=200) das Schloss öffnet.
Dependencies: EthernetInterface HTTPClient mbed-dev mbed-rtos wolfSSL MODSERIAL
main.cpp
- Committer:
- coolnik
- Date:
- 2016-06-18
- Revision:
- 2:1ffd9e2ce7df
- Parent:
- 1:5f0df6a77d62
- Child:
- 3:e91a03086c72
File content as of revision 2:1ffd9e2ce7df:
#include "mbed.h" #include "EthernetInterface.h" #include "HTTPClient.h" DigitalOut R(PTB22); // PTB22 = Red pin DigitalOut G(PTE26); // PTE26 = Green pin DigitalOut B(PTB21); // PTB21 = Blue pin Serial serial(USBTX, USBRX); // tx, rx EthernetInterface eth; HTTPClient http; char str[8192]; int main() { setbuf(stdout, NULL); eth.init(); //Use DHCP eth.connect(); http.dumpResHeader(true); while(1){ // Wait for Token on Serial and read to str while(1){ if(serial.readable()){ serial.scanf("%s",&str); break; } } printf(str); // Send token to Server // POST date, more examples on https://developer.mbed.org/users/donatien/code/HTTPClient_HelloWorld/file/270e2d0bb85a/main.cpp printf("\nTrying to fetch page...\n"); HTTPMap map; HTTPText inText(str, 512); map.put("Hello", "World"); map.put("test", "1234"); printf("\nTrying to post data...\n"); int ret = http.post("http://httpbin.org/post", map, &inText); if (!ret) { printf("Page fetched successfully - read %d characters\n", strlen(str)); printf("Result: %s\n", str); // Unlock R=!R; wait(1); R=!R; } else { printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); } } eth.disconnect(); }