a
Dependencies: EthernetInterface HTTPClient MFRC522 MbedJSONValue TextLCD mbed-rtos mbed
Fork of HEINEKEN_FRDM_K64F by
Revision 1:91f852e8c07f, committed 2016-03-02
- Comitter:
- mslovic
- Date:
- Wed Mar 02 19:30:09 2016 +0000
- Parent:
- 0:27d98e126a4f
- Child:
- 2:c8618b0777d3
- Commit message:
- Heineken_skoro_FINISH
Changed in this revision
MbedJSONValue.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MbedJSONValue.lib Wed Mar 02 19:30:09 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/samux/code/MbedJSONValue/#10a99cdf7846
--- a/main.cpp Wed Mar 02 18:19:38 2016 +0000 +++ b/main.cpp Wed Mar 02 19:30:09 2016 +0000 @@ -2,6 +2,8 @@ #include "MFRC522.h" #include "TextLCD.h" #include "EthernetInterface.h" +#include <string> +#include "MbedJSONValue.h" #define MF_RESET PTD0 @@ -27,55 +29,56 @@ { lcd.cls(); - lcd.printf(" HEINEKEN\n\n\r"); + lcd.printf(" HEINEKEN\n\n"); - lcd.printf(" Set your bracelet\n\r"); + lcd.printf(" Set your bracelet\n"); lcd.printf(" against the reader"); } -void ScreenNATOCI() +void ScreenNATOCI(int left) { lcd.cls(); - lcd.printf("Trenutni saldo\n\r"); - lcd.printf("= %d piva\n\r",1); - lcd.printf("Natoci svoje pivo!"); + lcd.printf("Left %d beers.\n\n",left); + lcd.printf("Pour your beer!"); + wait(2); + ScreenSTART(); } void ScreenNEMA() { lcd.cls(); - lcd.printf("Trenutni saldo\n\r"); - lcd.printf("= 0 piva\n\r"); - lcd.printf("Nemate vise piva!"); + lcd.printf("Sorry no beear for you!"); wait(2); ScreenSTART(); } void ScreenTNX() { lcd.cls(); - lcd.printf("\n\rHvala na konzumaciji!"); + lcd.printf("\nThank you for consumption!"); wait(2); ScreenSTART(); } void WrongID() { lcd.cls(); - lcd.printf("\n\r Nemate ispravnu\n\r narukvicu!"); + lcd.printf("\n You do not have\n the correct bracelet!"); wait(2); ScreenSTART(); } int main(void) { + //ventil = 0; - pc.printf("\rStarting..\n\r"); + lcd.printf("Starting..\n"); + pc.printf("Starting..\n"); EthernetInterface eth; eth.init("10.10.0.2","255.255.255.0","10.10.0.1"); //Use DHCP eth.connect(); pc.printf("IP Address is %s\n\r", eth.getIPAddress()); TCPSocketConnection sock; - + RfChip.PCD_Init(); @@ -83,9 +86,10 @@ Count = 0; ScreenSTART(); - pc.printf("\rReady\n\r"); + lcd.printf("Ready\n"); + pc.printf("Ready\n"); while(1) { - + LedGreen = 0; Count = 0; @@ -107,9 +111,9 @@ } char http_cmd[1024]; - sprintf(http_cmd,"POST /rest/bracelet/%s HTTP/1.0\n\n",cID); - pc.printf("\n\r%s\n\r",http_cmd); - + sprintf(http_cmd,"POST /rest/tap/%s HTTP/1.0\n\n",cID); + //pc.printf("\n\r%s\n\r",http_cmd); + sock.connect("10.10.0.1", 8080); sock.send_all(http_cmd, sizeof(http_cmd)-1); @@ -120,13 +124,36 @@ if (ret <= 0) break; buffer[ret] = '\0'; - printf("\n\r%s\n\r", buffer); - break; + //pc.printf("\n\r%s\n\r", buffer); + } sock.close(); - - - + + string responseFULL(buffer); + int start = responseFULL.find("{",0); + int end = responseFULL.find("}",start); + + string response = responseFULL.substr(start, end-start+1); + //pc.printf("%s",response); + + MbedJSONValue responseJSON; + parse(responseJSON, response.c_str()); + + bool tap = responseJSON["tap"].get<bool>(); + int left = responseJSON["left"].get<int>(); + + pc.printf("tociti ili ne? %d",tap); + pc.printf("preostalo piva %d",left); + + if(tap!=1){ + ventil = 0; + ScreenNEMA(); + } + if(tap==1){ + ventil = 1; + ScreenNATOCI(left); + } + }