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@4:00b8d595aa33, 2016-06-23 (annotated)
- Committer:
- coolnik
- Date:
- Thu Jun 23 21:07:49 2016 +0000
- Revision:
- 4:00b8d595aa33
- Parent:
- 3:e91a03086c72
- Child:
- 5:a837161f959a
clean up
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:64d0faaa4e6e | 4 | |
coolnik | 3:e91a03086c72 | 5 | DigitalOut R(LED_RED); |
coolnik | 3:e91a03086c72 | 6 | DigitalOut G(LED_GREEN); |
coolnik | 3:e91a03086c72 | 7 | DigitalOut B(LED_BLUE); |
coolnik | 1:5f0df6a77d62 | 8 | |
coolnik | 1:5f0df6a77d62 | 9 | Serial serial(USBTX, USBRX); // tx, rx |
coolnik | 0:64d0faaa4e6e | 10 | EthernetInterface eth; |
coolnik | 0:64d0faaa4e6e | 11 | HTTPClient http; |
coolnik | 3:e91a03086c72 | 12 | char str[32000]; |
coolnik | 3:e91a03086c72 | 13 | char str2[32000]; |
coolnik | 0:64d0faaa4e6e | 14 | |
coolnik | 0:64d0faaa4e6e | 15 | int main() { |
coolnik | 0:64d0faaa4e6e | 16 | setbuf(stdout, NULL); |
coolnik | 4:00b8d595aa33 | 17 | eth.init(); |
coolnik | 0:64d0faaa4e6e | 18 | eth.connect(); |
coolnik | 3:e91a03086c72 | 19 | R=!R;G=!G;B=!B; |
coolnik | 3:e91a03086c72 | 20 | wait(1); |
coolnik | 1:5f0df6a77d62 | 21 | |
coolnik | 1:5f0df6a77d62 | 22 | while(1){ |
coolnik | 1:5f0df6a77d62 | 23 | // Wait for Token on Serial and read to str |
coolnik | 3:e91a03086c72 | 24 | // Light Blue |
coolnik | 3:e91a03086c72 | 25 | B=!B; |
coolnik | 1:5f0df6a77d62 | 26 | while(1){ |
coolnik | 1:5f0df6a77d62 | 27 | if(serial.readable()){ |
coolnik | 1:5f0df6a77d62 | 28 | serial.scanf("%s",&str); |
coolnik | 1:5f0df6a77d62 | 29 | break; |
coolnik | 1:5f0df6a77d62 | 30 | } |
coolnik | 1:5f0df6a77d62 | 31 | } |
coolnik | 3:e91a03086c72 | 32 | // Token Read, light Yellow |
coolnik | 3:e91a03086c72 | 33 | R=!R;G=!G;B=!B; |
coolnik | 4:00b8d595aa33 | 34 | //printf(str); |
coolnik | 1:5f0df6a77d62 | 35 | |
coolnik | 1:5f0df6a77d62 | 36 | // Send token to Server |
coolnik | 2:1ffd9e2ce7df | 37 | HTTPMap map; |
coolnik | 3:e91a03086c72 | 38 | HTTPText inText(str2, 32000); |
coolnik | 3:e91a03086c72 | 39 | map.put("client_id", "a1b2c3"); |
coolnik | 3:e91a03086c72 | 40 | map.put("client_secret", "drickyoughurt"); |
coolnik | 4:00b8d595aa33 | 41 | map.put("token_type_hint", "pop_token"); |
coolnik | 3:e91a03086c72 | 42 | map.put("token", str); |
coolnik | 3:e91a03086c72 | 43 | |
coolnik | 3:e91a03086c72 | 44 | int ret = http.post("https://kongsugar.de/introspection", map, &inText); |
coolnik | 1:5f0df6a77d62 | 45 | if (!ret) |
coolnik | 1:5f0df6a77d62 | 46 | { |
coolnik | 3:e91a03086c72 | 47 | // Unlock, Light Green 5s |
coolnik | 3:e91a03086c72 | 48 | R=!R;wait(5);G=!G; |
coolnik | 1:5f0df6a77d62 | 49 | } |
coolnik | 1:5f0df6a77d62 | 50 | else |
coolnik | 1:5f0df6a77d62 | 51 | { |
coolnik | 3:e91a03086c72 | 52 | // Light Red 5s |
coolnik | 3:e91a03086c72 | 53 | G=!G;wait(5);R=!R; |
coolnik | 1:5f0df6a77d62 | 54 | } |
coolnik | 0:64d0faaa4e6e | 55 | } |
coolnik | 0:64d0faaa4e6e | 56 | } |