The Ethernet-Board
Dependencies: EthernetInterface HTTPClient MODSERIAL mbed-dev mbed-rtos wolfSSL
Fork of sose2016_tr_oauth_pop by
Diff: main.cpp
- Revision:
- 3:e91a03086c72
- Parent:
- 2:1ffd9e2ce7df
- Child:
- 4:00b8d595aa33
--- a/main.cpp Sat Jun 18 11:55:54 2016 +0000 +++ b/main.cpp Thu Jun 23 20:58:07 2016 +0000 @@ -2,52 +2,63 @@ #include "EthernetInterface.h" #include "HTTPClient.h" -DigitalOut R(PTB22); // PTB22 = Red pin -DigitalOut G(PTE26); // PTE26 = Green pin -DigitalOut B(PTB21); // PTB21 = Blue pin +DigitalOut R(LED_RED); +DigitalOut G(LED_GREEN); +DigitalOut B(LED_BLUE); Serial serial(USBTX, USBRX); // tx, rx EthernetInterface eth; HTTPClient http; -char str[8192]; +char str[32000]; +char str2[32000]; int main() { setbuf(stdout, NULL); eth.init(); //Use DHCP eth.connect(); http.dumpResHeader(true); + R=!R;G=!G;B=!B; + wait(1); while(1){ // Wait for Token on Serial and read to str + // Light Blue + B=!B; + printf("Erwarte Eingabe: "); while(1){ if(serial.readable()){ serial.scanf("%s",&str); break; } } + // Token Read, light Yellow + R=!R;G=!G;B=!B; 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"); + printf("\nTrying to post data...\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); + HTTPText inText(str2, 32000); + map.put("client_id", "a1b2c3"); + map.put("client_secret", "drickyoughurt"); + map.put("token_type_hint", "pop_token"); //Sptäer durch pop ersetzen!! + map.put("token", str); + + //int ret = http.post("http://requestb.in/14qajp81", map, &inText); + int ret = http.post("https://kongsugar.de/introspection", 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; + printf("Page fetched successfully - read %d characters\n", strlen(str2)); + printf("Result: %s\n", str2); + // Unlock, Light Green 5s + R=!R;wait(5);G=!G; } else { printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); + // Light Red 5s + G=!G;wait(5);R=!R; } }