I got my ESP32 dev board in, so I started working on getting it up and running. I started with this tutorial to get microPython flashed onto the board and set up a very simple web server. It wasn’t part of my original plan to have a website to control the OpenLitter, but it’s basically already done by following this tutorial, so I might as well include it.

A lightly modified landing page based on the above tutorial

This is running on the ESP32, it allows a single user to go to the website (currently the ESP32 IP address) and interact with the ESP32. Right now all it does is turns the built in LED on and off, the “Last Rotated” is a stand-in for now, but I think I’ll include something that shows when the OpenLitter last cleaned itself. Also, the Rotate and Cancel buttons actually turn the LED on and off, I was mostly just playing around to see how it could look.

One of the features I wanted to include was an easy way to setup the OpenLitter on WiFi. To do this, I’m making use of the microPython framework called WifiManager. I ended up merging the default code from the first tutorial with the main.py and wifimgr.py files from this library, it was pretty painless and is a really nice solution to giving the ability to change WiFi information on the fly. I’ll need to add a way to reset the WiFi, but it’s good enough for now. One thing to note, when configuring the WiFi information for the first time, the ESP32 needs to be restarted manually after the credentials are put into the web GUI. It shouldn’t be hard to make it restart automatically, but I haven’t put that much effort into it yet.

The last part I wanted to add to the skeleton files before actually adding features that interact with the LitterRobot was pretty unnecessary, but it was bothering me and not a lot of work, so I went ahead with it. When the ESP32 running microPython connects to your WiFi, it defaults to the hostname of “Expressif”. This isn;t a big deal when there is only one ESP32 on your network, but it could get confusing if you have multiples. Turns out it only takes 1 extra line of code to define a new hostname, see here for more information.

    # Search WiFis in range
    wlan_sta.active(True)
    wlan_sta.config(dhcp_hostname="OpenLitter")
    networks = wlan_sta.scan()

I added the 3rd line shown above to the wifimgr.py file, and that’s it. Pretty simple, but it adds a nice touch to what will hopefully be a nice polished project… eventually 🙂

For the code described in this post, check out the Software/Python folder in commit “0f61f1e5c77f81c50cbee0f1ff2c47c5cce5f2be”.




Leave a comment

Your email address will not be published. Required fields are marked *