David Pilling |
Main »
Stepper Pi NodeThe 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:
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. For the server I used node.js with Express. The stepper process communicates via two FIFO local file system pipes - textual commands and responses flow in and out through these. WebSockets allow javascript running on the browser to connect to these two pipes. I use the Socket.IO library for node.js to implement the WebSockets. 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. Installation
The download will unpack to a folder called 'test' which you can put anywhere - typically in Documents. Use 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: This proved powerful magic since Chrome on the tablet managed to upgrade itself from the internet via the Pi.
|
David Pilling's Wiki Set view |
Page last modified on March 12, 2019, at 12:42 AM - Powered by PmWiki pmwiki-2.3.31 (pmwiki-2.3.31) |