# Rui Santos & Sara Santos - Random Nerd Tutorials # Complete project details at https://RandomNerdTutorials.com/raspberry-pi-pico-w-bluetooth-low-energy-micropython/ from micropython import const import asyncio import aioble import bluetooth import struct import machine import bme280_float as bme280 import ssd1306 import config i2c = machine.I2C(0, sda=machine.Pin(0), scl=machine.Pin(1)) bme = bme280.BME280(i2c=i2c) oled = ssd1306.SSD1306_I2C(128, 64, i2c) temperature = 0 pressure = 0 humidity = 0 #org.bluetooth.service.environmental_sensing _ENV_SENSE_UUID = bluetooth.UUID(0x181A) # org.bluetooth.characteristic.temperature _ENV_SENSE_TEMP_UUID = bluetooth.UUID(0x2A6E) # org.bluetooth.characteristic.pressure _ENV_SENSE_PRESSURE_UUID = bluetooth.UUID(0x2A6D) # org.bluetooth.characteristic.humidity _ENV_SENSE_HUMIDITY_UUID = bluetooth.UUID(0x2A6F) # org.bluetooth.characteristic.gap.appearance.xml _ADV_APPEARANCE_GENERIC_THERMOMETER = const(768) # How frequently to send advertising beacons. _ADV_INTERVAL_MS = 250_000 # Register GATT server. envsense_service = aioble.Service(_ENV_SENSE_UUID) temp_characteristic = aioble.Characteristic( envsense_service, _ENV_SENSE_TEMP_UUID, read=True, notify=True) pressure_characteristic = aioble.Characteristic( envsense_service, _ENV_SENSE_PRESSURE_UUID, read=True, notify=True) humidity_characteristic = aioble.Characteristic( envsense_service, _ENV_SENSE_HUMIDITY_UUID, read=True, notify=True) aioble.register_services(envsense_service) # Helper to encode the characteristic encoding # (sint16, hundredths). def _encode_value(value): #print(int(value * 100)) return struct.pack(f"