I have recently been experimenting with the mbed websocket and managed to send some text to the server. Next I would like to display a real time graph of a analog input. The code below is my attempt to this.
include the mbed library with this snippet
#include "mbed.h"
#include "EthernetInterface.h"
#include "Websocket.h"
AnalogIn ain(p20);
int main()
{
char json_str[100];
int fecg;
EthernetInterface eth;
eth.init();
eth.connect();
printf("IP Address is %s\n\r", eth.getIPAddress());
Websocket ws("ws://sockets.mbed.org:443/ws/ecg/wo");
ws.connect();
while (1)
{
fecg = ain/50;
sprintf (json_str, "{\"id\":\"ECG\",\"ecg\":%d\"}", (int)fecg);
ws.send(json_str);
}
}
As I understand it, I should be able to send data to the server, http://sockets.mbed.org/ecg, in json and it would display a graph automatically with me having to code anything for the server. Is this correct and so did I make a mistake in the code above or am I completely wrong and have to program the server using eclipse since I am on windows?
Thanks
Hi,
I have recently been experimenting with the mbed websocket and managed to send some text to the server. Next I would like to display a real time graph of a analog input. The code below is my attempt to this.
<<code title=include the mbed library with this snippet>>
#include "mbed.h"
#include "EthernetInterface.h"
#include "Websocket.h"
AnalogIn ain(p20);
int main()
{
char json_str[100];
int fecg;
EthernetInterface eth;
eth.init();
eth.connect();
printf("IP Address is %s\n\r", eth.getIPAddress());
Websocket ws("ws://sockets.mbed.org:443/ws/ecg/wo");
ws.connect();
while (1)
{
fecg = ain/50;
sprintf (json_str, "{\"id\":\"ECG\",\"ecg\":%d\"}", (int)fecg);
ws.send(json_str);
}
}
<</code>>
As I understand it, I should be able to send data to the server, http://sockets.mbed.org/ecg, in json and it would display a graph automatically with me having to code anything for the server. Is this correct and so did I make a mistake in the code above or am I completely wrong and have to program the server using eclipse since I am on windows?
Thanks
I want to do something similar as well.
I have the real time plot looking nice, but I haven't started the JSON part yet.
Have you looked at Jchart2D?
I want to do something similar as well.
I have the real time plot looking nice, but I haven't started the JSON part yet.
Important Information for this Arm website
This site uses cookies to store information on your computer.
By continuing to use our site, you consent to our cookies.
If you are not happy with the use of these cookies, please review our
Cookie Policy
to learn how they can be disabled.
By disabling cookies, some features of the site will not work.
Access Warning
You do not have the correct permissions to perform this operation.
Hi,
I have recently been experimenting with the mbed websocket and managed to send some text to the server. Next I would like to display a real time graph of a analog input. The code below is my attempt to this.
include the mbed library with this snippet
As I understand it, I should be able to send data to the server, http://sockets.mbed.org/ecg, in json and it would display a graph automatically with me having to code anything for the server. Is this correct and so did I make a mistake in the code above or am I completely wrong and have to program the server using eclipse since I am on windows?
Thanks