# Balcony Weather Station A DIY weather station project on my balcony. The data is sent to [Home Assistant](https://www.home-assistant.io/) to be used as part of home automation projects. The source code started as [CircuitPython](https://circuitpython.org/) following many of the patterns I learned in creating an [aquarium controller project](https://git.sr.ht/~travisshears/sewa-reef-controller). I have since switch to using C for better performance and control. ## Capabilities - Send data to Home Assistant via MQTT - ✅ read tempature - ✅ read humidity - ✅ read atmospheric pressure - read partical matter PM1, PM2.5, and PM10 - read noise levels - read wind speed - read wind direction - read rain fall - read light level ## Hardware ### Node1 Sensors: - [BME280](https://shop.pimoroni.com/products/bme280-breakout?variant=29420960677971) - reads tempature, humidity, and atmospheric pressure - [PMS5003](https://shop.pimoroni.com/products/pms5003-particulate-matter-sensor-with-cable) - reads partical matter PM1, PM2.5, and PM10 MC: [Raspberry Pi Pico W](https://www.raspberrypi.com/products/raspberry-pi-pico/) Weatherproof Enclosure: [weatherproof-cover-for-outdoor-sensors](https://shop.pimoroni.com/products/weatherproof-cover-for-outdoor-sensors?variant=40047884468307) _Note: I would not recommend buying from pimoroni from EU as shipping tax is huge!_ ## Helpful links - [pico mqtt Example](https://github.com/raspberrypi/pico-examples/blob/master/pico_w/wifi/mqtt/README) - [pico pinout](https://pico.pinout.xyz/) - [home assistant mqtt guide](https://www.home-assistant.io/integrations/mqtt/#testing-your-setup) - [home assistant device classes](https://www.home-assistant.io/integrations/sensor/#device-class) ## Dev ### Env Setup From build folder run: ```shell $ cmake -DPICO_BOARD=pico_w .. ``` This creates the needed makefiles ### Build This turns the test.c file in the root dir into .elf and .uf2 files: ```shell $ make node1 ``` ### Flash Once you have the .uf2 file you can transfer it to the pico by putting the pico in bootsel mode (hold button and plug it into pc) or you can flash the .elf file to the pico using `openocd`: ```shell openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "program node1.elf verify reset exit" ``` *note: after flashing with openocd the program will be paused. To unpause connect and run "continue"* ### Shell You screen ```shell $ fd tty.usb /dev /dev/tty.usbmodem102 $ screen /dev/tty.usbmodem102 115200 ``` Exit shell Ctrl+A Ctrl+| ### Open debug connection ```shell $ openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" ``` then in another window ```shell $ lldb ./test.elf ``` Once in lldb you can do a bunch of stuff, see https://web.navan.dev/posts/2024-08-08-openocd-macos-lldb.html. ```shell (lldb) platform select remote-gdb-server ... (lldb) process connect connect://localhost:3333 ``` Set breakpoint: ```shell (lldb) breakpoint set --hardware --name main (lldb) continue # Continue execution (lldb) step # Step in (lldb) next # Step over (lldb) finish # Step out ``` Check vars: ```shell (lldb) frame variable (lldb) print variable_name ``` Restarting the program: ```shell (lldb) process plugin packet monitor reset run ``` ### Home assistant debugging #### Subscribe to a topic ```shell $ TOPIC=zigbee2mqtt/0xa4c13848a46ea1cf; mosquitto_sub -h 192.168.1.11 -t $TOPIC -u homeassistant -P xxx ``` #### Send message Config example: ```shell $ mosquitto_pub -h 192.168.1.11 -P xxxxxxxx \ -u homeassistant -t homeassistant/device/bws/node1_001/config \ -f node1.json -r ``` Payload example: ```shell $ mosquitto_pub -h 192.168.1.11 -P xxxxxxxx \ -u homeassistant -t bws/node1/state \ -f node1_payload_example.json ```