The Ethernet-Board

Dependencies:   EthernetInterface HTTPClient MODSERIAL mbed-dev mbed-rtos wolfSSL

Fork of sose2016_tr_oauth_pop by niko gillen

Committer:
coolnik
Date:
Sat Jun 25 11:38:01 2016 +0000
Revision:
5:a837161f959a
Parent:
4:00b8d595aa33
Child:
7:5d116f2e5587
Replaced serial with modserial; Increased SEND_BUF_SIZE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
coolnik 0:64d0faaa4e6e 1 #include "mbed.h"
coolnik 0:64d0faaa4e6e 2 #include "EthernetInterface.h"
coolnik 0:64d0faaa4e6e 3 #include "HTTPClient.h"
coolnik 5:a837161f959a 4 #include "MODSERIAL.h"
coolnik 5:a837161f959a 5
coolnik 5:a837161f959a 6 #define SEND_BUF_SIZE 4096
coolnik 0:64d0faaa4e6e 7
coolnik 3:e91a03086c72 8 DigitalOut R(LED_RED);
coolnik 3:e91a03086c72 9 DigitalOut G(LED_GREEN);
coolnik 3:e91a03086c72 10 DigitalOut B(LED_BLUE);
coolnik 1:5f0df6a77d62 11
coolnik 5:a837161f959a 12 MODSERIAL serial(USBTX, USBRX,4096); // tx, rx
coolnik 0:64d0faaa4e6e 13 EthernetInterface eth;
coolnik 0:64d0faaa4e6e 14 HTTPClient http;
coolnik 5:a837161f959a 15
coolnik 3:e91a03086c72 16 char str[32000];
coolnik 3:e91a03086c72 17 char str2[32000];
coolnik 0:64d0faaa4e6e 18
coolnik 0:64d0faaa4e6e 19 int main() {
coolnik 0:64d0faaa4e6e 20 setbuf(stdout, NULL);
coolnik 4:00b8d595aa33 21 eth.init();
coolnik 0:64d0faaa4e6e 22 eth.connect();
coolnik 3:e91a03086c72 23 R=!R;G=!G;B=!B;
coolnik 3:e91a03086c72 24 wait(1);
coolnik 1:5f0df6a77d62 25
coolnik 1:5f0df6a77d62 26 while(1){
coolnik 1:5f0df6a77d62 27 // Wait for Token on Serial and read to str
coolnik 3:e91a03086c72 28 // Light Blue
coolnik 3:e91a03086c72 29 B=!B;
coolnik 1:5f0df6a77d62 30 while(1){
coolnik 1:5f0df6a77d62 31 if(serial.readable()){
coolnik 1:5f0df6a77d62 32 serial.scanf("%s",&str);
coolnik 1:5f0df6a77d62 33 break;
coolnik 1:5f0df6a77d62 34 }
coolnik 1:5f0df6a77d62 35 }
coolnik 3:e91a03086c72 36 // Token Read, light Yellow
coolnik 3:e91a03086c72 37 R=!R;G=!G;B=!B;
coolnik 4:00b8d595aa33 38 //printf(str);
coolnik 1:5f0df6a77d62 39
coolnik 1:5f0df6a77d62 40 // Send token to Server
coolnik 2:1ffd9e2ce7df 41 HTTPMap map;
coolnik 3:e91a03086c72 42 HTTPText inText(str2, 32000);
coolnik 3:e91a03086c72 43 map.put("client_id", "a1b2c3");
coolnik 3:e91a03086c72 44 map.put("client_secret", "drickyoughurt");
coolnik 4:00b8d595aa33 45 map.put("token_type_hint", "pop_token");
coolnik 3:e91a03086c72 46 map.put("token", str);
coolnik 3:e91a03086c72 47
coolnik 3:e91a03086c72 48 int ret = http.post("https://kongsugar.de/introspection", map, &inText);
coolnik 1:5f0df6a77d62 49 if (!ret)
coolnik 1:5f0df6a77d62 50 {
coolnik 3:e91a03086c72 51 // Unlock, Light Green 5s
coolnik 3:e91a03086c72 52 R=!R;wait(5);G=!G;
coolnik 1:5f0df6a77d62 53 }
coolnik 1:5f0df6a77d62 54 else
coolnik 1:5f0df6a77d62 55 {
coolnik 3:e91a03086c72 56 // Light Red 5s
coolnik 3:e91a03086c72 57 G=!G;wait(5);R=!R;
coolnik 1:5f0df6a77d62 58 }
coolnik 5:a837161f959a 59
coolnik 5:a837161f959a 60 // Bugfix, nervous user send token multiple times!
coolnik 5:a837161f959a 61 memset(&str[0], 0, sizeof(str));
coolnik 5:a837161f959a 62 memset(&str2[0], 0, sizeof(str2));
coolnik 5:a837161f959a 63 serial.rxBufferFlush();
coolnik 0:64d0faaa4e6e 64 }
coolnik 0:64d0faaa4e6e 65 }