The mission on this page is to control the three motor drivers on the Stepper Pi Hat using a web browser. It is evident that this requires various items:
- A server to pass the web page to the browser
- Some way of exchanging commands and responses between the browser and the stepper process (see Stepper Pi for the stepper executable).
For the web page I had the idea I would be able produce beautiful designs if I used the Bootstrap framework. In addition this means web pages should adapt to mobile devices.
Joining the WebSockets to the FIFO pipes sounds trivial. I struggled for a while. The obvious idea is when one gets a connection from the browser open the FIFO pipes with node.js fs streams and set them up so that when data arrives it is sent to the socket that has just connected. I found I lost data. What was happening was that the browser had opened a new connection with new streams created but the old streams were still open and passing data to non-existent sockets. I worked out that I should destroy the old streams on disconnect events, but that is not as simple as it should be and although I got it to work a lot better it was not perfect. I eventually realised that a stepper motor, like a man, can only have one master and whilst most people using Socket.IO have multiple browser sessions, what is required here is a crude single connection implementation with global variables.
The download will unpack to a folder called 'test' which you can put anywhere - typically in Documents.
Open a terminal in the stepper folder, issue the command:
sudo ./stepper pipe debug
Open a terminal in the 'test' folder which contains the node.js app, issue the command:
Both these terminal sessions will not return immediately and should be left open. You can Ctrl+C stop them. They will print information about commands being passed.
Finally in a browser enter the URL:
and the web page interface will appear. Commands can be entered and buttons clicked.
I also enabled WiFi on the Pi following this page:
USING YOUR NEW RASPBERRY PI 3 AS A WIFI ACCESS POINT WITH HOSTAPD
I ignored all the dhcp stuff and used a fixed ip address for the Pi on the WiFi network of 10.0.1.1 which meant I could connect from my tablet using the URL:
This proved powerful magic since Chrome on the tablet managed to upgrade itself from the internet via the Pi.
- ARDUINO & WEBSOCKETS A LOVE STORY