Modifying LILYGO T3 LoRa32 RTL_433 ESP OOK receiver example - log found devices to file
https://techcoderadio.blogspot.com/2025/10/modifying-lilygo-t3-lora32-rtl433-esp.html
https://github.com/NorthernMan54/rtl_433_ESP
Log found devices to file (SD card)
appendFile(SD, "/rtl433data.txt", JSONmessageBuffer);
bin files:
https://github.com/OH1GIU-P/ESP32-RTL433ESP-logger-firmware
/*
Basic rtl_433_ESP example for OOK/ASK Devices
*/
#include <ArduinoJson.h>
#include <ArduinoLog.h>
#include <rtl_433_ESP.h>
#include <wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SD.h>
#include <FS.h>
#include <SPI.h>
#ifndef RF_MODULE_FREQUENCY
# define RF_MODULE_FREQUENCY 433.92
#endif
#define JSON_MSG_BUFFER 512
#define LED_SDA 21
#define LED_SCL 22
#define LED_RST -1
#define SD_CS 13
#define SD_MOSI 15
#define SD_SCK 14
#define SD_MISO 2
#define SCR_W 128
#define SCR_H 64
Adafruit_SSD1306 display(SCR_W, SCR_H, &Wire, LED_RST);
bool bLED = false;
bool bSD = false;
SPIClass spi = SPIClass(HSPI);
char messageBuffer[JSON_MSG_BUFFER];
rtl_433_ESP rf; // use -1 to disable transmitter
int count = 0;
void appendFile(fs::FS &fs, const char * path, const char * message) {
File file = fs.open(path, FILE_APPEND);
if(!file) {
Log.notice(F("Failed to open file for appending"));
return;
}
if (file.print(message)) {
file.print("\n");
}
else {
Log.notice(F("Append failed"));
}
file.close();
}
void rtl_433_Callback(char* message) {
JsonDocument jsonDocument;
deserializeJson(jsonDocument,message);
logJson(jsonDocument);
count++;
}
void logJson(JsonDocument jsondata) {
#if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
char JSONmessageBuffer[measureJson(jsondata) + 1];
serializeJson(jsondata, JSONmessageBuffer, measureJson(jsondata) + 1);
#else
char JSONmessageBuffer[JSON_MSG_BUFFER];
serializeJson(jsondata, JSONmessageBuffer, JSON_MSG_BUFFER);
#endif
#if defined(setBitrate) || defined(setFreqDev) || defined(setRxBW)
Log.setShowLevel(false);
Log.notice(F("."));
Log.setShowLevel(true);
#else
Log.notice(F("Received message : %s" CR), JSONmessageBuffer);
if (bSD) {
appendFile(SD, "/rtl433data.txt", JSONmessageBuffer);
}
if (bLED) {
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(0,0);
display.print(JSONmessageBuffer);
display.display();
}
#endif
}
void setup() {
Serial.begin(921600);
delay(1000);
Wire.begin(LED_SDA, LED_SCL);
delay(50);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) {
Log.notice(F("SSD1306 allocation failed"));
}
else {
bLED = true;
}
spi.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS);
delay(10);
if (!SD.begin(SD_CS, spi, 80000000)) {
Log.notice(F("SD card mount failed"));
}
else {
if (SD.cardType() == CARD_NONE) {
Log.notice(F("No SD card attached"));
}
else {
bSD = true;
}
}
#ifndef LOG_LEVEL
LOG_LEVEL_INFO
#endif
Log.begin(LOG_LEVEL, &Serial);
Log.notice(F(" " CR));
Log.notice(F("****** setup ******" CR));
rf.initReceiver(RF_MODULE_RECEIVER_GPIO, RF_MODULE_FREQUENCY);
rf.setCallback(rtl_433_Callback, messageBuffer, JSON_MSG_BUFFER);
rf.enableReceiver();
Log.notice(F("****** setup complete ******" CR));
rf.getModuleStatus();
}
unsigned long uptime() {
static unsigned long lastUptime = 0;
static unsigned long uptimeAdd = 0;
unsigned long uptime = millis() / 1000 + uptimeAdd;
if (uptime < lastUptime) {
uptime += 4294967;
uptimeAdd += 4294967;
}
lastUptime = uptime;
return uptime;
}
int next = uptime() + 30;
#if defined(setBitrate) || defined(setFreqDev) || defined(setRxBW)
# ifdef setBitrate
# define TEST "setBitrate" // 17.24 was suggested
# define STEP 2
# define stepMin 1
# define stepMax 300
// # define STEP 1
// # define stepMin 133
// # define stepMax 138
# elif defined(setFreqDev) // 40 kHz was suggested
# define TEST "setFrequencyDeviation"
# define STEP 1
# define stepMin 5
# define stepMax 200
# elif defined(setRxBW)
# define TEST "setRxBandwidth"
# ifdef defined(RF_SX1276) || defined(RF_SX1278)
# define STEP 5
# define stepMin 5
# define stepMax 250
# else
# define STEP 5
# define stepMin 58
# define stepMax 812
// # define STEP 0.01
// # define stepMin 202.00
// # define stepMax 205.00
# endif
# endif
float step = stepMin;
#endif
void loop() {
rf.loop();
#if defined(setBitrate) || defined(setFreqDev) || defined(setRxBW)
char stepPrint[8];
if (uptime() > next) {
next = uptime() + 120; // 60 seconds
dtostrf(step, 7, 2, stepPrint);
Log.notice(F(CR "Finished %s: %s, count: %d" CR), TEST, stepPrint, count);
step += STEP;
if (step > stepMax) {
step = stepMin;
}
dtostrf(step, 7, 2, stepPrint);
Log.notice(F("Starting %s with %s" CR), TEST, stepPrint);
count = 0;
int16_t state = 0;
# ifdef setBitrate
state = rf.setBitRate(step);
RADIOLIB_STATE(state, TEST);
# elif defined(setFreqDev)
state = rf.setFrequencyDeviation(step);
RADIOLIB_STATE(state, TEST);
# elif defined(setRxBW)
state = rf.setRxBandwidth(step);
if ((state) != RADIOLIB_ERR_NONE) {
Log.notice(F(CR "Setting %s: to %s, failed" CR), TEST, stepPrint);
next = uptime() - 1;
}
# endif
rf.receiveDirect();
// rf.getModuleStatus();
}
#endif
}
Building in release mode
Compiling .pio\build\esp32_lilygo\src\OOK_Receiver.ino.cpp.o
Retrieving maximum program size .pio\build\esp32_lilygo\firmware.elf
Checking size .pio\build\esp32_lilygo\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [= ] 9.8% (used 32200 bytes from 327680 bytes)
Flash: [===== ] 50.7% (used 664317 bytes from 1310720 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, esp-bridge, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
Looking for upload port...
Auto-detected: COM3
Uploading .pio\build\esp32_lilygo\firmware.bin
esptool.py v4.5
Serial port COM3
Connecting....
Chip is ESP32-PICO-D4 (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, Embedded Flash, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: x:x:x:x
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Flash will be erased from 0x00001000 to 0x00005fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x000b2fff...
Compressed 17488 bytes to 12168...
Writing at 0x00001000... (100 %)
Wrote 17488 bytes (12168 compressed) at 0x00001000 in 0.4 seconds (effective 351.9 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 146...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (146 compressed) at 0x00008000 in 0.1 seconds (effective 464.0 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 604.5 kbit/s)...
Hash of data verified.
Compressed 664688 bytes to 398915...
Writing at 0x00010000... (4 %)
Writing at 0x0001ae9f... (8 %)
Writing at 0x00026756... (12 %)
Writing at 0x00031d0c... (16 %)
Writing at 0x0003ea71... (20 %)
Writing at 0x00046580... (24 %)
Writing at 0x0004b783... (28 %)
Writing at 0x00050778... (32 %)
Writing at 0x000553f6... (36 %)
Writing at 0x0005a2ff... (40 %)
Writing at 0x0005efdc... (44 %)
Writing at 0x00063d8f... (48 %)
Writing at 0x00068f66... (52 %)
Writing at 0x0006e001... (56 %)
Writing at 0x000732b4... (60 %)
Writing at 0x00078dff... (64 %)
Writing at 0x0007e792... (68 %)
Writing at 0x0008421d... (72 %)
Writing at 0x00089177... (76 %)
Writing at 0x0008ea26... (80 %)
Writing at 0x00094658... (84 %)
Writing at 0x0009ced8... (88 %)
Writing at 0x000a58b6... (92 %)
Writing at 0x000aad09... (96 %)
Writing at 0x000b0573... (100 %)
Wrote 664688 bytes (398915 compressed) at 0x00010000 in 6.3 seconds (effective 839.0 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
Comments
Post a Comment