Skip to content

flavio-fernandes/pyportal_station

Repository files navigation

pyportal_station

CircuitPython based project for Adafruit PyPortal to use MQTT and show weather

This repo provides icons and python files needed to display time and weather on a PyPortal. Circuit Python libraries can be installed via circup, as shown below.

PyPortal weather station

For more info on what this is doing, look at these 2 learning guides from Adafruit:

For a quick start on PyPortal, look at these awesome pages:

Lastly, check these links for a good reference on Circuit Python

Removing all files from CIRCUITPY drive

# NOTE: Do not do this before backing up all files!!!
>>> import storage ; storage.erase_filesystem()

Copying files from cloned repo to CIRCUITPY drive

# First, get to the REPL prompt so the board will not auto-restart as
# you copy files into it

# Assuming that PyPortal is mounted under /Volumes/CIRCUITPY
$  cd ${THIS_REPO_DIR}
$  [ -e ./code.py ] && \
   [ -d /Volumes/CIRCUITPY/ ] && \
   rm -rf /Volumes/CIRCUITPY/* && \
   (tar czf - *) | ( cd /Volumes/CIRCUITPY ; tar xzvf - ) && \
   echo ok || echo not_okay

Libraries

Use circup to install these libraries:

$ python3 -m venv .env && source ./.env/bin/activate && \
  pip install --upgrade pip

$ pip3 install circup

$ for LIB in \
    adafruit_adt7410 \
    adafruit_bitmap_font \
    adafruit_esp32spi \
    adafruit_logging \
    adafruit_pyportal \
    neopixel \
    ; do circup install $LIB ; done

Note: adafruit_minimqtt from latest library is not working, so we will be using an older revision, located under the lib directory in this repo. To be fixed...

    466.125: DEBUG - SUBSCRIBING to topic /pyportalkitchen/brightness with QoS 0
    466.168: DEBUG - Receiving PUBLISH
    Topic: /sensor/temperature_house
    Msg: bytearray(b'69')
    466.180: INFO - MMQT error: invalid message received as response to SUBSCRIBE: 0x31
    466.203: DEBUG - Reconnect timeout computed to 4.00
    466.205: DEBUG - adding jitter 0.91 to 4.00 seconds
    466.208: DEBUG - Attempting to connect to MQTT broker (attempt #2)
    466.209: DEBUG - Attempting to establish MQTT connection...
    466.211: DEBUG - Sleeping for 4.91 seconds due to connect back-off
    Traceback (most recent call last):
      File "code.py", line 301, in <module>
      File "/lib/adafruit_minimqtt/adafruit_minimqtt.py", line 502, in connect
      File "/lib/adafruit_minimqtt/adafruit_minimqtt.py", line 560, in _connect

This is what it should look like:

$ ls /Volumes/CIRCUITPY/
LICENSE         boot_out.txt    fonts           init_background.bmp openweather_graphics.py secrets.py.sample
README.md       code.py         icons           lib

$ ls /Volumes/CIRCUITPY/lib
adafruit_adt7410.mpy        adafruit_portalbase
adafruit_bitmap_font        adafruit_pyportal
adafruit_esp32spi       adafruit_register
adafruit_io         adafruit_touchscreen.mpy
adafruit_logging.mpy        neopixel.mpy
adafruit_minimqtt

$ circup freeze | sort
Found device at /Volumes/CIRCUITPY, running CircuitPython 8.2.7.

secrets.py

Make sure to create a file called secrets.py to include info on the wifi as well as the MQTT broker you will connect to. Use secrets.py.sample as reference.

At this point, all needed files should be in place, and all that is needed is to let code.py run. From the Circuit Python serial console:

>>  <CTRL-D>
soft reboot
...

Example MQTT commands

PREFIX='/pyportal'
MQTT=192.168.10.10

# Subscribing to status messages

mosquitto_sub -F '@Y-@m-@dT@H:@M:@S@z : %q : %t : %p' -h $MQTT  -t "${PREFIX}/#"

# Request general info
mosquitto_pub -h $MQTT -t "${PREFIX}/ping" -r -n

# Set screen brightness
mosquitto_pub -h $MQTT -t "${PREFIX}/brightness" -m on
mosquitto_pub -h $MQTT -t "${PREFIX}/brightness" -m 0.1
mosquitto_pub -h $MQTT -t "${PREFIX}/brightness" -m off

# Neopixel control
mosquitto_pub -h $MQTT -t "${PREFIX}/neopixel" -m 0        ; # off
mosquitto_pub -h $MQTT -t "${PREFIX}/neopixel" -m 0xff     ; # blue
mosquitto_pub -h $MQTT -t "${PREFIX}/neopixel" -m 0xff00   ; # green
mosquitto_pub -h $MQTT -t "${PREFIX}/neopixel" -m 0xff0000 ; # red

# On board led blink
mosquitto_pub -h $MQTT -t "${PREFIX}/blinkrate" -m on   ; # on
mosquitto_pub -h $MQTT -t "${PREFIX}/blinkrate" -m 0    ; # off
mosquitto_pub -h $MQTT -t "${PREFIX}/blinkrate" -m 0.1  ; # 100ms

About

Adafruit Pyportal station for weather display via mqtt

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages