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:
- Make a function that returns your value, check out Tim’s Python Workshop for some pointers
https://core-electronics.com.au/courses/python-workshop/
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)
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
Any questions, suggestions or feedback please let me know!
The homestation.py
library can be found on GitHub: https://github.com/LiamHowell/HomeStation