Is it working Ben?
Dependencies: EthernetInterface WebSocketClient mbed-rtos mbed ID12RFID XBeeLib
Diff: main.cpp
- Revision:
- 0:634fbc4f9bc7
- Child:
- 1:30d760c7478e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Mar 31 02:01:35 2017 +0000 @@ -0,0 +1,56 @@ +#include "mbed.h" +#include "rtos.h" +#include "EthernetInterface.h" +#include "Websocket.h" + +//static const char* mbedIp = "192.168.1.2"; +//static const char* mbedMask = "255.255.255.0"; +//static const char* mbedGateway = "192.168.1.1"; +DigitalOut myled(LED1); +Serial pc(USBTX, USBRX); +//static char* WEBSOCKET_URL= "ws://braceletus.herokuapp.com:8080/"; // Adresse Serveur M-A +static char* WEBSOCKET_URL = "ws://24.203.139.78:8080/"; // Adresse Serveur M-A +bool IsReponseRecu; +char* Reponse = ""; +Thread ThreadLecture; + +void wsocket_message_recu() +{ + while (true) + { + ThreadLecture.signal_wait(1); + myled = !myled; + pc.printf("Message Recu :\n\r"); + pc.printf(Reponse); + pc.printf("\n\rFin Message\n\r"); + } +} + +int main() { + // Setup du port ethernet + EthernetInterface eth; + eth.init(); //Use DHCP + //eth.init(mbedIp, mbedMask, mbedGateway); //Use config + eth.connect(); + + IsReponseRecu = false; + Websocket ws(WEBSOCKET_URL); + ws.connect(); + + myled = false; + ThreadLecture.start(wsocket_message_recu); + + while (1) { + IsReponseRecu = false; + ws.send("WS Test"); + while(IsReponseRecu == false) + { + if(ws.read(Reponse)) + { + ThreadLecture.signal_set(1); + //printf("We Got Something : %v", Reponse); + IsReponseRecu = true; + } + } + } +}