Git Product home page Git Product logo

ngws's Introduction

Overview

Some experimentation with combining nicegui (https://nicegui.io/), a Python web frontend with the javascript webserial API. UI elements defined in nicegui are hooked to javascript functions that access the webserial API.

This example interfaces with a PyBadge board (https://learn.adafruit.com/adafruit-pybadge/overview). Light sensor readings are made at a rate of 5 Hz (adjustable) and read from the serial port, triggering a custom asyncrhonous event, and updating the live plot. The NeoPixel LEDs at the bottom of the board can be toggled on or off, demonstrating writing data to the serial port.

image

image

Files

main.py -> Python nicegui code. This is the file to run.

script.js -> JavaScript code lives here.

sketch.ino -> Wiring sketch (C code with Adafruit libraries) for target MCU.

Why Is This Interesting?

Great, you wrote/read to a serial port and threw a web UI on top, big deal. Well...normally, the external hardware would be accessible only through locally-running code. For example, you might have a bunch of clients connecting to a remote server, controlling a remote webcam. In this arrangement the server has a local (physical) connection to the webcam, permitting Python to access it. With webserial, we can invert this relationship. Webserial allows for in-browser access of the local (client) machine's usb/serial ports. This enables the Python backend (running on the remove server) to break throgh the frontend and tunnel out of the browser to the clients' serial port(s). This has a bunch of neat implications for production automation and deployment. For example, we could have local equipment (e.g., test equipment) whose control interface is a web app (instead of a traditionl desktop app or script). Here, there is no need to deploy any local code beyond that of a modern updated browser. Duplicating test stations requires no local Python installation. Code updates can be singularly pushed to the server - no need to update all the clients.

ngws's People

Contributors

blankadventure avatar

Stargazers

Rodja Trappe avatar

Watchers

 avatar

Forkers

lapnd

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.