HomeStation - A Pico W powered webpage dashboard

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 :smiley:

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 :slight_smile:

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 :slight_smile:

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!

3 Likes

Can it be done with Raspberry pi 4 also?

2 Likes

Hi Tepalia,

Most likely - I imagine there would be quite a bit of porting required though.
For beginner Makers the Pico W has a much lower price point, far more available and is perfect for simple tasks like this!

1 Like

Howdy all,

Let's make a super easy-to-use webserver!!

The main goal was to strip away much of the technical code and expose sensors in a Pythonic fashion - like a dictionary!
Thats right, all of the code you see in the two examples is what we need

If we wanted to see the state of a potentiometer and button the code would look like the following:

import homestation
from machine import Pin,ADC

ssid = 'your wifi name'
password = 'your wifi password'

adc = ADC(Pin(26))
button = Pin(14, Pin.IN, Pin.PULL_DOWN)

def getPot():
    return (adc.read_u16()*3.3/(65536))

def getButton():
    return button.value()

sensorData = {
    "Button": getPot,
    "Potentiometer :": getButton,
}

homestation.homestation_Run(ssid,password,sensorData)

image



And say if we wanted the temperature, pressure, humidity and light values?

*Here's a cool bit!*
# HomeStation - Liam Howell - https://github.com/LiamHowell/HomeStation
import homestation

from PiicoDev_Unified import sleep_ms

from PiicoDev_BME280 import PiicoDev_BME280
from PiicoDev_VEML6030 import PiicoDev_VEML6030

# Create PiicoDev sensor objects
atmo = PiicoDev_BME280()
lght = PiicoDev_VEML6030()

import secrets 
# Configure your WiFi SSID and password
ssid = secrets.ssid_s
password = secrets.password_s

def atmoList():
    tempC, presPa, humRH = atmo.values()
    return tempC, presPa/100, humRH #[degC,hPa,RH]

sensorData = {
    ".Atmo": atmoList,
    "Temperature :": ['Atmo',0],
    "Pressure: ": ['Atmo',1],
    "Humidity: ": ['Atmo',2],
    "Light: ": lght.read,
}

homestation.homestation_Run(ssid,password,sensorData)

If a single function returns a few values we can ‘pack’ them inside the dictionary, just add a dot to the front of the name of the actual sensor, instead of the function name use a list with the name of the sensor and which position it is passed from

image

Any questions, suggestions or feedback please let me know!

The homestation.py library can be found on GitHub: https://github.com/LiamHowell/HomeStation

3 Likes