Using the same setup from the previous page, the sender code can be updated to include sensor data from the on-board BME280 temperature, humidity, pressure sensor on the Feather ESP32-S2 BME280.
Here's the updated sender code:
# ESP-NOW Sender w BME280
import time
import board
import wifi
import espnow
from adafruit_bme280 import basic as adafruit_bme280
i2c = board.I2C() # uses board.SCL and board.SDA
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
wifi.radio.start_ap(" ", "", channel=6, max_connections=0)
wifi.radio.stop_ap()
e = espnow.ESPNow()
# broadcast to everyone:
peer = espnow.Peer(mac=b'\xff\xff\xff\xff\xff\xff', channel=6)
e.peers.append(peer)
my_mac_str = ":".join([f"{b:02x}" for b in wifi.radio.mac_address])
print("Starting sender on MAC:", my_mac_str)
while True:
try:
# Convert temperature to string
sensor_msg = f"T:{bme280.temperature:.1f}C H:{bme280.relative_humidity:.1f}% P:{bme280.pressure:.1f}hPa"
e.send(sensor_msg, peer)
print("sent packet: ", sensor_msg)
except Exception as ex:
print("exception:", ex)
time.sleep(2)
# ESP-NOW Receiver
import time
import wifi
import espnow
wifi.radio.start_ap(" ", "", channel=6, max_connections=0)
wifi.radio.stop_ap()
e = espnow.ESPNow()
my_mac_str = ":".join([f"{b:02x}" for b in wifi.radio.mac_address])
print("Starting receiver on MAC:", my_mac_str)
while True:
if not e: # wait for a packet
continue
packet = e.read()
mac_str = ":".join([f"{b:02x}" for b in packet.mac])
# Decode bytes to string for clean output
decoded_message = packet.msg.decode('utf-8')
print("received message:", decoded_message)
print("from MAC:", mac_str)
print("full packet:", packet)
time.sleep(0.3)
Page last edited August 05, 2025
Text editor powered by tinymce.