Shanel Wu

They/them. PhD student: smart textiles, weaving, computational craft, hardware hacking.

View My GitHub Profile

28 October 2019

Websockets in Python and Node.JS

by Shanel

Screenshot of temperature/humidity GUI accessed via HTML

Installation Sources

This project was built on top of the first class project, described in this previous post, so these installations were in addition to the ones listed there.

Server (Raspberry Pi)

Client (another machine)

  1. Python WebSockets with Tornado Reference
  2. Basic WebSockets Python Server/HTML Client Example
  3. Connecting Node.js to MySQL, 1 2 3
  4. JQuery Reference
  5. ws (Node.js Websockets) Reference

Issues

The biggest issue that we ran into during the project (and up through the demo) was handling the data connection and transportation over the WebSockets. With the Python Websocket server, we were able to establish the server/client connection, but weren’t able to properly transmit different data payloads. The Python QT code from the previous project was already fairly long, so there were some places were we didn’t insert the WebSocket code or break it out into a separate file correctly. For the Node.js WebSocket, we realized that we needed to carefully format the JSON with the MySQL data in order to have a parse-able string on the client side.