Simple web app controls LEDs connected to an RPI

I want a user to browse to a website, move one radio button and one slider, and a Raspberry Pi which is listening to that website will control a few LED strips connected to it depending on the user’s choices (the whole set up includes a video camera as well and some other minor details). This is not meant to be used by tons of users, or even multiple users. I’m pretty sure there would be just one user at a time.

I have the RPI (version 4) connected via an ethernet cable to the web, so it’s always online. I know how to control the LED strips from the RPI itself (mainly using Python’s adafruit-circuitpython-dotstar). I kind of know how to use Interact.jl and Blink.jl. What I don’t know is how to build that website, nor how to host and listen to that website from the RPI.

I assume that the easiest thing to do is for the RPI itself to host that website – I mean, unless the RPI is on the LED strips won’t be on and there will be no point for a user to fiddle with the widgets on that website, so RPI on -> website on -> controlling the LEDs becomes possible.

Here are my concrete questions:

  1. How do I code a website like that (I literally need one radio button and one slider) and
  2. how do I serve this website from the RPI (unless there is an even simpler way to server it)?
  3. How does the RPI fetch the choices of the user, preferably, as s/he moves the sliders etc?

Much thanks! And keep in mind that I am not a web developer, so the more details the better…

1 Like

I started SmartHomy for that purpose:


I render a UI with JSServe:

The webserver:


The rendering:

It’s maybe a bit not trivial how to see how to do this, if you’re not familiar with JSServe :smiley:
Maybe these example help:

4 Likes

The Jetson Nano has the same connector for hats as the Raspberry PI - so you can use the same GPIO and Sense hats.
I tried this on my Nano but did not have much success. I note that there are changes within the last two months - so it is still nder development, which is good!

1 Like

Looks promising, but will this only work on the local network, or can you access it from outside? I’m on a uni network, so while the IP addresses are almost persistent (or as persistent as I care), I don’t have access to the router and stuff like that…

You can use https://ngrok.com maybe.

2 Likes

This looks like a vital part in the puzzle. I’ll check it out! What’s the name of the package that can serve websites (the thing I’ll have on the RPI), and what’s the name of the one that can listen on (the thing I’ll have on the client side)?

Looks promising, but will this only work on the local network, or can you access it from outside? I’m on a uni network, so while the IP addresses are almost persistent (or as persistent as I care), I don’t have access to the router and stuff like that…

As @kristoffer.carlsson suggests, ngrok may work… Only other option is likely, to speak with your unis network admin… You should probably anyways, if you plan to open up uni servers to the public. It might also well be, that they already have infrastructure for this in place :wink:

I’ll try my luck with ngrok… OK, I’ll try and use JSServe to make this happen!

@sdanisch @kristoffer.carlsson !!! IT WORKED!!!
This is huge! Using ngrok and your markdown.jl example I could play with that plot on my phone off of the local network! Boom!
Thanks a ton! I’m really looking forward to implementing this for my system!
OK, I’ll calm down now.

6 Likes

More overly excited news:
The markdown example works from the RPI!!! This means that among other miracles, WGLMakie does work on ARM7 32 bits! So sick! (ok, the fonts are not displaying yet, but everything else just works)

Side note: irritating I can’t forward the resulting (random) address ngrok generates to an email or something…

2 Likes

another update: I found out that I can wget the local address on the RPI and use JSON(3) to fish out the address ngrok is using. Email that to the users, and done! Feels like I’m cheating ngrok out of their income a bit but but…

Next irritating point: Julia doesn’t have an email package like Python’s smtplib

Have you tried SMTPClient.jl as repleacement for smtplib?

1 Like

Nope! Will try on Monday! Thanks!

1 Like

This does look promising. I would however need to implement a package to control the DotStar LED strip, basically what adafruit-circuitpython-dotstar is doing. It is tempting cause I’m only using basic stuff from that library and what with SMTPClient.jl I could remove all python dependencies… so… but I’ll look into that once I have a functioning finished version.

2 Likes

Noob question: How do I access the web app?
I put this code in a .jl file and then hit include in the REPL. 127.0.0.1 in the browser does nothing.

Sorry for the slow reply, try http://127.0.0.1:8081/

1 Like