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.
7 years, 2 months ago.
K64F - Ethernet server - please help me..
Hello, I have got problems with making server on my FRDM K64F. Can any body help me? Or.. probably work on it with me? Thanks for every answer Ondra (ofko) :-)
1 Answer
7 years, 1 month ago.
Ofko,
I hope that developing your server on a FRDM K64F goes well.
Here are a few links that might help your development:
- Filesystem: https://docs.mbed.com/docs/mbed-os-api-reference/en/latest/APIs/storage/filesystem/
- HTTPS: https://os.mbed.com/teams/sandbox/code/http-example/
- MQTT: https://os.mbed.com/teams/mqtt/code/HelloMQTT/
- Websockets: https://os.mbed.com/cookbook/Websockets-Server
Thanks :)
Now.. i have the server running as well, but its only simple html page... and... I want to print some values(variables) on it but definitely i don't know how to do it... so if you can help me... I would be happy...
posted by 26 Oct 2017To get data from the device to the HTML page, you should use websockets. Your device acts as a websocket server, and the webpage that you display runs some javascript that acts like a websocket client.
When you read data from a sensor or file on the K64F, you can then emit the data via websockets to any connected client (aka your webpage). The webpage then renders the data in anyway that you format it.
For example, take a look at this tutorial: https://www.w3schools.com/nodejs/nodejs_raspberrypi_webserver_websocket.asp
Note that that tutorial connects a Raspberry PI to a webpage via websockets, but the same concept applies. The link I posted in my original response to the mbed version of websockets should be very helpful.
posted by 26 Oct 2017Ohh thanks... I have some code... I made it with my friend... baut it is still not working.. can u help me please? Where I have mistakes? Can u solve that please? Im helpless, please help me... Im only 15 years old... so I have not much experiences with that... Below is my code... Some part is from example which I find on the internet...
Thank You Very Much ofko
example
#if !FEATURE_IPV4 #error [NOT_SUPPORTED] IPV4 not supported for this target #endif #include "mbed.h" #include "EthernetInterface.h" #include "TCPServer.h" #include "TCPSocket.h" #define HTTP_STATUS_LINE "HTTP/1.0 200 OK" #define HTTP_HEADER_FIELDS "Content-Type: text/html; charset=utf-8" #define HTTP_MESSAGE_BODY "" \ "<html>" "\r\n" \ " <body style=\"display:flex;text-align:center\">" "\r\n" \ " <div style=\"margin:auto\">" "\r\n" \ " <h1>MY SERVER</h1>" "\r\n" \ " <h3>Variable: %d,"value"</h3>" "\r\n" \ " </div>" "\r\n" \ " </body>" "\r\n" \ "</html>" "\r\n" \ int value = 10; // Variable to print #define HTTP_RESPONSE HTTP_STATUS_LINE "\r\n" \ HTTP_HEADER_FIELDS "\r\n" \ "\r\n" \ HTTP_MESSAGE_BODY "\r\n" int main() { printf("Basic HTTP server example\n"); EthernetInterface eth; eth.connect(); printf("The target IP address is '%s'\n", eth.get_ip_address()); TCPServer srv; TCPSocket clt_sock; //SocketAddress clt_addr; /* Open the server on ethernet stack */ srv.open(ð); /* Bind the HTTP port (TCP 80) to the server */ srv.bind(eth.get_ip_address(), 80); /* Can handle 5 simultaneous connections */ srv.listen(5); while (true) { // Will be possible in releaseb 126 //srv.accept(&clt_sock, &clt_addr); //printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port()); srv.accept(&clt_sock); printf("new client accepted\n"); //clt_sock.send(HTTP_RESPONSE, strlen(HTTP_RESPONSE)); } }