LoRa, MQTT and Oled
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
from machine import Pin
|
||||
from shared import get_lora
|
||||
import time
|
||||
|
||||
vext = Pin(19, Pin.OUT)
|
||||
vext.value(0)
|
||||
time.sleep_ms(100)
|
||||
|
||||
lora = get_lora()
|
||||
lora.configure(freq=868.1, sf=7)
|
||||
|
||||
while True:
|
||||
print("\nESP32 : Envoi des mesures...")
|
||||
mesures = {"id": "ESP32_Salon", "temp": 22.4, "hum": 55.2}
|
||||
|
||||
# Envoi direct (le pilote s'occupe de mettre le groupe \x02)
|
||||
lora.send(b'\x02' + lora.send_json_bytes_helper if False else bytes([2]) + lora.send_helper if False else b'\x02' + __import__('ujson').dumps(mesures).encode('utf-8'))
|
||||
|
||||
# Réception propre
|
||||
paquet = lora.receive_packet(3000)
|
||||
if paquet:
|
||||
# paquet est un dict : {"group": 2, "data": {...}, "raw": False}
|
||||
print(f"ESP32 : Message reçu du groupe {paquet['group']}")
|
||||
print(f"ESP32 : Données utiles -> {paquet['data']}")
|
||||
else:
|
||||
print("ESP32 : Pas de réponse.")
|
||||
|
||||
time.sleep(5)
|
||||
@@ -0,0 +1,42 @@
|
||||
from machine import Pin, SoftI2C
|
||||
import framebuf
|
||||
import ssd1306
|
||||
import time
|
||||
|
||||
|
||||
image_cards_hearts_bits = bytearray(b'\x00\x00\x00\x0088||\xfe\xfe\xff\xfe\xff\xfe\xff\xfe\x7f\xfc?\xf8\x1f\xf0\x0f\xe0\x07\xc0\x03\x80\x01\x00\x00\x00')
|
||||
image_clock_solid_full_bits = bytearray(b'\x00\x1f\x00\x00\x00\xff\xe0\x00\x03\xff\xf8\x00\x07\xff\xfc\x00\x0f\xff\xfe\x00\x1f\xff\xff\x00?\xf3\xff\x00?\xf3\xff\x80\x7f\xf3\xff\x80\x7f\xf3\xff\xc0\x7f\xf3\xff\xc0\xff\xf3\xff\xc0\xff\xf3\xff\xc0\xff\xf1\xff\xc0\xff\xf8\x7f\xc0\xff\xfe?\xc0\x7f\xff\x1f\xc0\x7f\xff\xdf\xc0\x7f\xff\xff\x80?\xff\xff\x80?\xff\xff\x00\x1f\xff\xff\x00\x0f\xff\xfe\x00\x07\xff\xfc\x00\x03\xff\xf0\x00\x00\x7f\xc0\x00')
|
||||
|
||||
def draw():
|
||||
# Layer 1
|
||||
display.rect(0, 0, 128, 64, 1)
|
||||
|
||||
# Layer 2
|
||||
display.text("HELP", 1, 2, 1)
|
||||
|
||||
# cards_hearts
|
||||
fb_image_cards_hearts_bits = framebuf.FrameBuffer(image_cards_hearts_bits, 15, 16, framebuf.MONO_HLSB)
|
||||
display.blit(fb_image_cards_hearts_bits, 111, 47)
|
||||
|
||||
# clock_solid_full
|
||||
fb_image_clock_solid_full_bits = framebuf.FrameBuffer(image_clock_solid_full_bits, 26, 26, framebuf.MONO_HLSB)
|
||||
display.blit(fb_image_clock_solid_full_bits, 51, 19)
|
||||
|
||||
display.show()
|
||||
|
||||
|
||||
|
||||
# 3. Initialize I2C (using Software I2C for better stability on ESP32-S3 pins)
|
||||
# SDA is GPIO 17, SCL is GPIO 18
|
||||
scl_pin = Pin(18, Pin.OUT, pull=Pin.PULL_UP)
|
||||
sda_pin = Pin(17, Pin.OUT, pull=Pin.PULL_UP)
|
||||
i2c = SoftI2C(scl=scl_pin, sda=sda_pin, freq=100000)
|
||||
|
||||
# 4. Bind the SSD1306 driver to our I2C bus (default address is 0x3C)
|
||||
# Display is 128x64 pixels
|
||||
display = ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3C)
|
||||
|
||||
# 5. Clear and write Hello World!
|
||||
draw()
|
||||
|
||||
print("Hello World printed to OLED successfully!")
|
||||
Reference in New Issue
Block a user