Is it working Ben?

Dependencies:   EthernetInterface WebSocketClient mbed-rtos mbed ID12RFID XBeeLib

main.cpp

Committer:
JoeyDionne
Date:
2017-03-31
Revision:
0:634fbc4f9bc7
Child:
1:30d760c7478e

File content as of revision 0:634fbc4f9bc7:

#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;
            }
        }
    }
}