The Ethernet-Board

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

Fork of sose2016_tr_oauth_pop by niko gillen

main.cpp

Committer:
coolnik
Date:
2016-06-23
Revision:
4:00b8d595aa33
Parent:
3:e91a03086c72
Child:
5:a837161f959a

File content as of revision 4:00b8d595aa33:

#include "mbed.h"
#include "EthernetInterface.h"
#include "HTTPClient.h"

DigitalOut R(LED_RED);
DigitalOut G(LED_GREEN);
DigitalOut B(LED_BLUE);

Serial serial(USBTX, USBRX); // tx, rx
EthernetInterface eth;
HTTPClient http;
char str[32000];
char str2[32000];

int main() {
    setbuf(stdout, NULL);
    eth.init();
    eth.connect();
    R=!R;G=!G;B=!B;
    wait(1);

    while(1){
        // Wait for Token on Serial and read to str
        // Light Blue
        B=!B;
        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
        HTTPMap map;
        HTTPText inText(str2, 32000);
        map.put("client_id", "a1b2c3");
        map.put("client_secret", "drickyoughurt");
        map.put("token_type_hint", "pop_token");
        map.put("token", str);
        
        int ret = http.post("https://kongsugar.de/introspection", map, &inText); 
        if (!ret)
        {
          // Unlock, Light Green 5s
          R=!R;wait(5);G=!G;
        }
        else
        {
          // Light Red 5s
          G=!G;wait(5);R=!R;
        }
    }
}