Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 4 months ago.
Problems with websocket on FRDM-K64F
Hello,
With the release of a new version of Ethernet and related libraries, I have tried to connect my FRDM-K64F board to the mbed websocket server. I have written a program where I could send messages like "r0", "r1", "g0", "g1", "b0", "b1", so I could turn on and off the RGB LED on the board. This part worked nicely. However, when I tried to implement a "s" message to command the board to send back the status os the 3 LEDs, it failed. Below is my code:
#include "mbed.h"
#include "EthernetInterface.h"
#include "Websocket.h"
DigitalOut ledr(PTB22);
DigitalOut ledg(PTE26);
DigitalOut ledb(PTB21);
DigitalIn sw(PTA4);
int main() {
int res;
char buf[100];
char msg[100];
ledg = 1;
ledr = 1;
ledb = 1;
bool pb = 1;
printf("START\r\n");
EthernetInterface eth;
eth.init();
eth.connect();
printf("IP Address is %s\n\r", eth.getIPAddress());
wait(1.0);
Websocket ws("ws://sockets.mbed.org/ws/quevedo/rw");
ws.connect();
while (pb) {
if(!ws.read(buf)) {
if(buf[0] == 'r') {
if(buf[1] == '0') {
ledr = 0;
} else {
ledr = 1;
}
}
if(buf[0] == 'g') {
if(buf[1] == '0') {
ledg = 0;
} else {
ledg = 1;
}
}
if(buf[0] == 'b') {
if(buf[1] == '0') {
ledb = 0;
} else {
ledb = 1;
}
}
if(buf[0] == 's') {
msg[0] = ledr + 0x30;
msg[1] = ',';
msg[2] = ledg + 0x30;
msg[3] = ',';
msg[4] = ledb + 0x30;
msg[5] = ',';
msg[6] = 0;
res = ws.send("Status");
if(res) printf("Message sent\r\n");
}
}
pb = sw;
}
ws.close();
eth.disconnect();
ledg = 1;
ledr = 1;
ledb = 1;
while(1) {
}
}
when I send the "s" message, I can see the "Message sent" answer at the serial terminal, which indicates that the ws.send(Status) command is being issued correctly. Thus, the message is being sent but I cannot see it at the websocket page. Note that I still have not sent status itself, only a single fixed string.
Also, I have tried the original "Websocket_Etnernet_HelloWorld" program:
https://mbed.org/users/samux/code/Websocket_Ethernet_HelloWorld/
This one works correctly, sending one message every second.
What can be going wrong? Anything with the "read/write mode"?
Cheers