This project uses MicroPython on a Raspberry Pi Pico to advertise a BME280 Environment sensor BLE service. It includes logic to monitor BLE activity and automatically restart the BLE service if no activity is detected for 30 seconds. Instead of rebooting the device, the script reinitializes the BLE logic to maintain continuous operation.
It handles a lack of connections by restartin the service periodically. This ensures that if connection is closed the ble service will restart.
- Flash MicroPython firmware to your Raspberry Pi Pico.
- Connect to the Pico using Thonny or another MicroPython IDE.
- Upload and run getBTMac.py and record the MAC for use on the Linux code. (Or figure out how to get advertising name working and log a PR)
- Upload the BLE service script to the Pico as
main.py. - Upload PiicoDev_BME280.py and PiicoDev_Unified.py to the Pico
You can run the file manually however as this is main.py once powered on, the Pico will begin advertising a BLE service named 'PicoBLE'. If a central device connects, the connection is tracked and activity is monitored. If no connections or BLE activity are detected for 30 seconds, the BLE service is restarted automatically.
Use the LinuxClientDemo.py from the repo. You will need the BT Mac because I couldn't get adevertising name working. It should return the environmental values.
- • Modify the
_RESTART_TIMEOUT_MSconstant to change the inactivity timeout duration. - • Change the advertised name by editing the
namevariable in_start_advertising().