0

I have a server that can communicate (Python) with its serial port. However, I want that anybody accessing this server from a web socket receives a website based on data from the server's serial port. So a (http?) request from the client should cause the server to get data from the serial port (I know how to communicate in python with the serial port) and then respond to the client based on that data.

I have implemented a basicpython socket that can get requests by a server and then get the data from its serial port. But how do I send to the Webbrowser client a response (that must be HTML, right?) based on that data? So hardcoding a whole Webserver would be too much, right? What's the best way to to this in python?

black
  • 1,151
  • 3
  • 18
  • 46
  • You can use a WS client library in js to communicate with the server. The data you send can be html, be also json er plaintext. See [this library](https://github.com/websockets/ws) – Pieter-Jan Beeckman Jun 07 '17 at 09:06
  • @Pieter-JanBeeckman But then I can't access it from a simple webbrowser, right? – black Jun 07 '17 at 09:18
  • Yes you are right, sorry I missed that. The browser does have a native implementation for WS, see [this link](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) – Pieter-Jan Beeckman Jun 07 '17 at 09:31

0 Answers0