Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8b5852c012 | |||
| 7dbabc902b | |||
| 2b4faca80d | |||
| d28ff065f5 |
@@ -1,5 +1,7 @@
|
|||||||
# pico-thermo
|
# pico-thermo
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
MicroPython app to read data from BME280 sensor and send it to Home Assistant
|
MicroPython app to read data from BME280 sensor and send it to Home Assistant
|
||||||
|
|
||||||
## Running
|
## Running
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ def register_ha_discovery(mqtt):
|
|||||||
|
|
||||||
|
|
||||||
# -------------------------------------------------------------
|
# -------------------------------------------------------------
|
||||||
# Main Execution Loop
|
# Instantiate Wi-Fi connection
|
||||||
# -------------------------------------------------------------
|
# -------------------------------------------------------------
|
||||||
def connect_wifi():
|
def connect_wifi():
|
||||||
wlan = network.WLAN(network.STA_IF)
|
wlan = network.WLAN(network.STA_IF)
|
||||||
@@ -277,6 +277,22 @@ def connect_wifi():
|
|||||||
print(f"Wi-Fi connected. IP: {wlan.ifconfig()[0]}")
|
print(f"Wi-Fi connected. IP: {wlan.ifconfig()[0]}")
|
||||||
|
|
||||||
|
|
||||||
|
# -------------------------------------------------------------
|
||||||
|
# Panic when the sensor isn't ready
|
||||||
|
# -------------------------------------------------------------
|
||||||
|
def panic(err=None):
|
||||||
|
"""Signals a fatal fault by blinking the onboard LED continuously."""
|
||||||
|
if err:
|
||||||
|
print(f"Fatal error: {err}")
|
||||||
|
led = Pin("LED", Pin.OUT)
|
||||||
|
while True:
|
||||||
|
led.toggle()
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
|
# -------------------------------------------------------------
|
||||||
|
# Main Execution Loop
|
||||||
|
# -------------------------------------------------------------
|
||||||
def main():
|
def main():
|
||||||
# Adjust SDA/SCL pins according to your wiring
|
# Adjust SDA/SCL pins according to your wiring
|
||||||
i2c = SoftI2C(sda=Pin(16), scl=Pin(17), freq=100000)
|
i2c = SoftI2C(sda=Pin(16), scl=Pin(17), freq=100000)
|
||||||
@@ -322,4 +338,13 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
# Allow 3.3V power rails and I2C registers to settle on cold boot
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
# Indicate startup has begun
|
||||||
|
Pin("LED", Pin.OUT).on()
|
||||||
|
|
||||||
|
try:
|
||||||
main()
|
main()
|
||||||
|
except Exception as e:
|
||||||
|
panic(e)
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "pico-thermo"
|
name = "pico-thermo"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
description = "MicroPython MQTT app to read BME280 sensor into Home Assistant"
|
description = "MicroPython MQTT app to read BME280 sensor into Home Assistant"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.9"
|
requires-python = ">=3.9"
|
||||||
|
|||||||
Reference in New Issue
Block a user