Network Accessible Mote Kit


#1

Say I wanted to set up a simple web interface to control my Mote sticks from the LAN, are there any go-to pieces of software for setting this sort of thing up?

I’m imagining a webpage that just offers a color picker for each attached Mote stick, or a setting to change all sticks to a preset (like rainbow mode).

This looks promising but I’m open to ideas: http://mattrichardson.com/Raspberry-Pi-Flask/


Best way to run scripts remotely?
#2

I wrote this ages ago for PiGlow: https://github.com/Gadgetoid/PiGlow-Web-Remote based on Flask, and using a procedurally generated vector colour wheel.

I revived it recently and had it working with Blinkt!..


#3

Thanks for that, I’ll take a look!


#4

Had a pretty successful few hours on Friday afternoon and managed to hook up a jQuery widget I found to some Flask code:

moteserver

It would probably be sufficient to just have a Hue picker, but for now it works (albeit only one channel)! Next step is to tidy the Flask side up and get the other channels working!


#5

Ooo, a full colour picker UI! Nice.

You could probably set it up so that you can paint custom patterns/fades/swipes and all sorts of cool stuff on the fly :D


#6

Can’t take any credit for that, just grabbed the first one I found online.

The plan is to have several modes. Alongside ‘manual’ which just gives you four colour pickers, I’m thinking of ‘rainbow’ and ‘cheerlights’. Maybe a ‘disco’ mode that reacts to music?


#7

Here’re the installed Mote sticks:

And some photos of the installation (I’ve since tidied the cables and applied liberal amounts of double-sided tape):


#8

I’ve dropped the code in: https://github.com/Tom-Archer/mote-server

Here’s how the UI currently looks:


#9

I’ve done some more tweaks for those interested, including a music reactive mode!

http://www.tomarcher.co.uk/2017/12/08/network-accessible-bookshelf-lighting-update/


#10

Where do the files go, is this correct?

I’ve put all the .py files into /home/pi/FlaskApp
I’ve put everything from the static folder into /home/pi/FlaskApp/app/static
I’ve put everything from the templates folder into /home/pi/FlaskApp/app/templates

How do I then launch moteserver/ ?

(Flask works, I’ve had a basic date & time page running for a while.)

Thanks.


#11

Keep the directory structure as per the github. You should be able to start the server with:

sudo python3 mote_server.py

The website with be live at whatever IP your Pi is at - can’t remember at the moment how I got it working at /moteserver


#12

Got it!

  1. download .zip from github
  2. extract zip file
  3. create /home/pi/FlaskApp/mote
  4. FTP extracted zip files to /home/pi/FlaskApp/mote
  5. cd /home/pi/FlaskApp/mote
  6. sudo python3 mote_server.py
  7. Go to [Pi IP] in browser

Works a treat, thanks!

I’ll have to disable disco mode though, as my tunes run through a network streamer, not via the PC.


#13

Cool, hopefully the code is intuitive enough for you to remove and add functionality. If you add any new modes I’d love to see them!


#14

I shall do, yes!

Be good to have the disco mode, could it work perhaps from a microphone?
I wouldn’t know where to begin… :(


#15

If I recall the library that I incorporated did have an option to work using a microphone.


#16

I’ve made a simple .py, which sets all four mote strips to white.
(Perhaps handy if you’re looking for something on the shelf?)

This works OK standalone, and I’ve added a link to home.html, which does nothing.

Getting the link and the .py combined is an unknown science :-|


#17

There’s a few things you need to do.

  1. Add a handler to mote_server.py e.g.
@app.route("/simple")
def simple():
    # run your code
  1. Add the appropriate strings to mode_nice_names (in the same file as above)
  2. Update templates/home.html to add a new radio button which has the following onclick
onclick="setMode('simple');"

Once you’ve done the above you should be able to activate the code by going to: ip_address/simple or clicking the button.


#18

That’s pretty much where I’ve got to.
I’ve kept the name to ‘white’ all the way through for simplicity sakes.

MoteServer is currently on and in xxxxxxxxxx mode!
doesn’t change either.

home.html

    <label class="container">white
  <input id="white" type="radio" name="radio" onclick="setMode('white');">
  <span class="checkmark"></span>
</label>

mote_server.py

mode_nice_names = {
"manual"  : "Manual",
"rainbow" : "Rainbow",
"cheer"   : "CheerLights",
"disco"   : "Disco",
"white"   : "white",    
"fairy"   : "Fairy Lights",
}

.
.

@app.route("/white")
def white():
    return jsonify(message = get_status(run_animation(white(mote))))    

white_thread.py

import time
from mote_thread import MoteThread
from mote import Mote
from colorsys import hsv_to_rgb

class white(MoteThread):
def __init__(self, mote):
    self.mote = mote
    MoteThread.__init__(self, name="white")

mote = Mote()

mote.configure_channel(1, 16, False)
mote.configure_channel(2, 16, False)
mote.configure_channel(3, 16, False)
mote.configure_channel(4, 16, False)

mote.clear()
for channel in range(1, 5):
for pixel in range(16):
    mote.set_pixel(channel, pixel, 255, 255, 255)
mote.show()

#19

If you navigate to to the URL manually do you get any hint of what’s going on?

Have you imported your python file at the top of mote_server.py?

I’ll try and take a closer look later when I’m not constrained to multiple tabs on my phone 🙂


#20

IP_ADDR/white_thread.py = not found

IP_ADDR/white = Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

IP_ADDR/fairy, rainbow - work OK.