Giter VIP home page Giter VIP logo

ws's Introduction

WebSegments

WebSegments, or ws, is a small project to serve a webpage where users can interactively draw on a four-digit seven-segment display and update a real-time TM1637 display connected to the server. It uses Zig for the WebSocket server and HTML, CSS, and JavaScript for the front end.

Acknowledgements

This project would not be possible without the tm1637-gpio-driver to interface the TM1637 display. Furthermore, the front end was deeply inspired by Jason Cox's 7-Segment LED Display Animator Tool. Lastly, thanks to the wsServer for simply working flawlessly as I was developing the prototype.

Deployment

To deploy the server, you need the Zig toolchain to build the WebSocket server. Clone and enter the repository locally, and follow these instructions:

Host Front-End (Optional)

You can host the front-end at ./web/ yourself; e.g.:

cd web
python -m http.server
cd ..

Visit http://localhost:8000/ to access the front-end. I am also hosting it on https://marsh.digitya.com/segments.

GPIO

Connect a TM1637 display to GPIO, with clock and data pins connected to GPIO pins 24 and 11, respectively. Ensure your user has permission to access the GPIO interface; e.g.:

sudo usermod -aG gpio ${USER}

Compile WebSocket Server

Since the web server is written in Zig, it must be compiled. After installing Zig (version 0.11.0), build the server:

cd server
zig build -Doptimize=ReleaseFast
cd ..

Run WebSocket Server

Finally, you can run the server:

./server/zig-out/bin/ws 0.0.0.0 8080

This should expose a WebSocket listening at 0.0.0.0:8080. To connect to this local instance, connect to ws://localhost:8080 from the front-end. If there are no errors in the web console, you can press each segment in each digit to toggle them and see them change in real-time on the TM1637 display! You can even copy each segment's array of hex values to the clipboard and clear the display.

Secure Layers

Out of the box, the WebSocket server does not support TLS or SSL. However, you can run a reverse proxy like Caddy to enforce better security. Here is an example Caddyfile entry:

ws.example.com {
    root * /path/to/ws/web
    reverse_proxy /ws/* :8080
}

The WebSocket instance would be exposed at wss://ws.example.com/ws/ and the front-end at https://ws.example.com/. Do note that a front-end hosted by a static server through HTTPS can only connect to a WebSocket instance with SSL or TLS.

ws's People

Contributors

monomycelium avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.