Howdy Makers,
Just finished some programming for the Pico W and thought I’d share so you can start playing with your new piece of kit
What the code do
- Update the sensor data on the webpage without having to refresh
- Use some neato HTML5 elements on the page to control something
- Make all of the above as accessible as possible (Still working on getting everything broken down into easy to use functions and HTML blocks)
- And above all make things convenient - stuff like: optionally show the IP address on an OLED etc
- Much like Jim’s project, not relying on other services (a router is still required though)
As always if you have any questions or suggestions lemme know
Mentioning some bits I think are neat/helpful
<p id="colour">{colour}</p>
using string formatting to build the webpage, would allow for a highly customisable interface
setInterval(function() {
getSensors();
}, 500);
The endpoint constantly asking for live sensor data
elif cmd_rq[1] == '/sensors':
Breaking down the different requests - Pythonic languages sure make this easier
try:
display = create_PiicoDev_SSD1306()
except:
print('OLED not plugged in')
def showIP(ipStr):
try:
display.text(ipStr, 0,0, 1)
display.show()
except:
print('OLED not plugged in')
Optionally showing the IP on the OLED when the server starts up - I’ve only had a quick look-in at the moment but if anyone knows how to efficiently de-initalise a Micropython library I’d love to hear!