Is it working Ben?
Dependencies: EthernetInterface WebSocketClient mbed-rtos mbed ID12RFID XBeeLib
Revision 3:030d126dabab, committed 2017-04-12
- Comitter:
- bellavanceo
- Date:
- Wed Apr 12 17:53:31 2017 +0000
- Parent:
- 2:28d134cf84f8
- Commit message:
- Final
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 28d134cf84f8 -r 030d126dabab main.cpp --- a/main.cpp Mon Apr 10 21:07:48 2017 +0000 +++ b/main.cpp Wed Apr 12 17:53:31 2017 +0000 @@ -15,10 +15,9 @@ //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 static char* WEBSOCKET_URL = "ws://192.168.0.20:3000/"; // Adresse Serveur M-A -bool IsReponseRecu; -char* Reponse = ""; -bool frameIsOk = true; -int ID; +DigitalOut sw(p20); +void keep_alive(); +Thread thread_alive(keep_alive); ID12RFID rfid(p10); // uart rx @@ -29,37 +28,43 @@ { const uint64_t remote_addr64 = remote.get_addr64(); - //pc.printf("\r\nGot a %s RX packet [%08x:%08x|%04x], len %d\r\nData: ", broadcast ? "BROADCAST" : "UNICAST", UINT64_HI32(remote_addr64), UINT64_LO32(remote_addr64), remote.get_addr16(), len); - for (int i = 0; i < len; i++) pc.printf("%02x ", data[i]); - int x ; - ((char*)&x)[2] = (char)data[1]; - ((char*)&x)[1] = (char)data[2]; - ((char*)&x)[0] = (char)data[3]; - pc.printf("%d ", x); + sw = (bool)data[0]; + uint32_t x ; //Construire le ID avec les 3 char recu + x = data[1]; + x= (x<<8)|data[2]; + x= (x<<8)|data[3]; + + pc.printf("%d %02x %02x %02x", x, data[1], data[2], data[3]); + char message[64]; sprintf(message,"1,%d,%d",x,data[0]) ; - ws.send(message); //envoie de message de chute + + if(ws.send(message)==-1) { + ws.close(); + ws.connect(); + ws.send(message); + } //envoie de message de chute + + pc.printf("\r\n"); } -void ReadConfig() + +void keep_alive() { - char key[10]; - int panID; - FILE * f = fopen("/local/coor.cfg", "r"); - fscanf(f,"%s %x", key, &panID); - //fscanf(f,"%s %x", key, &ID); //lecture du panid - //fscanf(f,"%s %d",key, &ID); //lecture du panid - - fclose(f); + Thread::signal_wait(0x1); //signal keep alive pouvant être utilisé plus tard pour vérifier que les poste fixe sont fonctionnel + ws.send("2"); +} +void sendSignal() +{ + thread_alive.signal_set(0x1); } int main() { - //ReadConfig(); - + // Setup du port ethernet EthernetInterface eth; eth.init(); //Use DHCP @@ -67,20 +72,19 @@ eth.connect(); //printf("IP Address is %s\n\r", eth.getIPAddress()); - IsReponseRecu = false; XBeeZB xbee = XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600); /* Register callbacks */ xbee.register_receive_cb(&receive_cb); - + Ticker ticker_num; RadioStatus const radioStatus = xbee.init(); - //ws = new Websocket(WEBSOCKET_URL, ð); + if(ws.connect()) { pc.printf("ok"); } else { pc.printf("bad"); } - + ticker_num.attach(&sendSignal, 15); //tick a chaque 50ms pour la thread numerique myled = false; while (1) { @@ -91,18 +95,15 @@ printf("RFID Tag number : %d\n", i); char message[64]; sprintf(message,"0,%d,1",i) ; - //sprintf(message,"0,%d,%d",i,ID) ; - ws.send(message); //envoie de commande rfid + + if(ws.send(message)==-1) { + ws.close(); + ws.connect(); + ws.send(message); + } //envoie de commande rfid + + } - wait_ms(100); - // 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; -// } -// } + wait_ms(100); } }