Hello to everyone, this is my first post, so I hope that someone can help me out.
I've built a sniffer using the ESP-32WROOM, although the IDE reports LilyGO T-display, but stuff from Ali always surprises.
I've connected it to a E220-900M22S, ChatGPT was so kind to write the code for me, but it doesn't work, DUH!
I have read on github that this module won't work, but it's all I have, and why wouldn't it work?
Here's the link:
So if someone over here has encountered problems with this setup, feedback would be highly appreciated.
Oh, and here's the code:
#include <U8g2lib.h>
#include <RadioLib.h>
#include <RotaryEncoder.h>
// OLED Display (U8g2)
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* SCL=*/ 22, /* SDA=*/ 21);
// LoRa Radio (using RadioLib)
SX1262 radio = new Module(5, 26, 27, 33); // NSS, DIO1, NRST, BUSY (adjust pins to your setup)
// Rotary Encoder
#define ROTARY_PIN_A 32
#define ROTARY_PIN_B 33
RotaryEncoder rotary(ROTARY_PIN_A, ROTARY_PIN_B);
// Frequencies
float frequency = 868.0; // Starting frequency (in MHz)
float stepSize = 0.2; // Step size for frequency adjustments
// Debug Control
#define DEBUG 1 // Set to 1 to enable serial debugging
void debugPrint(const char* message) {
if (DEBUG) {
Serial.println(message);
}
}
// Display update function
void updateDisplay() {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_ncenB08_tr); // Small font for saving space
u8g2.setCursor(0, 12);
u8g2.print(F("LoRa Sniffer"));
u8g2.setCursor(0, 28);
u8g2.print(F("Frequency:"));
u8g2.setCursor(0, 44);
u8g2.print(frequency, 2); // Display frequency with 2 decimals
u8g2.print(F(" MHz"));
u8g2.sendBuffer();
}
// Display received packet function
void displayReceivedPacket(String packet) {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.setCursor(0, 12);
u8g2.print(F("Packet Received:"));
u8g2.setCursor(0, 28);
u8g2.print(packet);
u8g2.sendBuffer();
}
void setup() {
// Initialize serial (for debugging)
if (DEBUG) {
Serial.begin(115200);
while (!Serial);
}
// Initialize display
u8g2.begin();
// Initialize rotary encoder
pinMode(ROTARY_PIN_A, INPUT_PULLUP);
pinMode(ROTARY_PIN_B, INPUT_PULLUP);
// Initialize LoRa module
int state = radio.begin(frequency, 125.0, 7, 5, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, 10);
if (state != RADIOLIB_ERR_NONE) {
Serial.print("Radio initialization failed with code: ");
Serial.println(state);
} else {
Serial.println("LoRa module initialized successfully!");
}
if (state != RADIOLIB_ERR_NONE) {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.setCursor(0, 12);
u8g2.print(F("Radio init failed!"));
u8g2.sendBuffer();
while (1);
}
// Initial display update
updateDisplay();
}
void loop() {
// Update rotary encoder
rotary.tick();
static long oldPosition = -999;
long newPosition = rotary.getPosition();
// Handle frequency change
if (newPosition != oldPosition) {
oldPosition = newPosition;
frequency = 868.0 + (newPosition * stepSize); // Calculate new frequency
radio.setFrequency(frequency); // Update frequency
updateDisplay(); // Update OLED display
}
// Sniff LoRa packets
String received;
int state = radio.receive(received);
if (state == RADIOLIB_ERR_NONE) {
// Successfully received a packet
displayReceivedPacket(received);
debugPrint("Packet received:");
debugPrint(received.c_str());
delay(2000); // Wait to let user read display
updateDisplay();
} else if (state != RADIOLIB_ERR_RX_TIMEOUT) {
// Something went wrong (ignore RX_TIMEOUT as it's normal)
debugPrint("Receive failed, code:");
debugPrint(String(state).c_str());
}
}
LoRaWAN communications can be on a range of frequencies and spreading factors, so a single LoRa device will have problems as a 'sniffer', it will miss heaps of transmissions.
You have not provided an explanation of the problems you are seeing ?
The author of an Arduino boards platform can associate a board definition with identifying information from the port. If a port on the user's computer has identification properties that match with a board definition from an Arduino platform, the port will be labeled with that board name in some parts of the Arduino IDE user interface:
The Tools > Port menu
The "BN" (board name) field of the "Board Info" dialog
The board selector menu on the toolbar (under certain conditions)
This identification system is very convenient in the common situation where there are multiple ports on the computer because it helps the user to easily select the correct port for their board.
Although any arbitrary identification properties are supported by the Arduino boards platform framework, most platforms use the USB VID/PID identifier pair. This is a good choice when the manufacturer of a board has dedicated a unique VID/PID pair to a specific board model, as Arduino has done with most of the boards they manufacture.
Typically in the case where a port property is not uniquely identifying, the platform author would not associate it with the board. For example, the classic Nano uses the FTDI FT232R USB chip, which has the 0403:6001 VID/PID pair provided by the chip manufacturer by default on all FT232R chips. For this reason, Arduino does not associate the 0403:6001 VID/PID pair with the Nano's board definition because this would cause the ports of other boards using the FT232R to be incorrectly identified in Arduino IDE as a Nano.
Although the assumption is made that only uniquely identifying properties will be used in board definitions, there is nothing in the Arduino boards platform framework to enforce that. The "LilyGo T-Display" board uses the general purpose WCH CH9102 USB to serial bridge chip. The maintainers of the "esp32" boards platform made an association between the VID/PID pair of that chip and the LilyGo T-Display board definition. Making this association was inappropriate because that VID/PID pair is not unique to the LilyGo T-Display board, and thus the association will cause other boards that use this chip to also be incorrectly identified as "LilyGo T-Display".
I have already submitted a correction for this bug:
However, it will take some time for that correction to propagate downstream to the IDE. Until then, please ignore the inappropriate identification. The port identification is only a convenience feature, so an incorrect identification won't cause any problems other than making Arduino IDE's user interface a bit confusing. Just make sure you have selected the appropriate board from Arduino IDE's Tools > Board menu and everything will be fine. As long as you do that, you can be confident that any problems you have with your project are not related to the incorrect port identification.
So dump the fantasy code and start at the beginning, with real proven code.
The library being used is Radiolib, so start with the simple published examples for that library. If the radio does still not intialise then suspect a wiring problem.
And if you want further help, give the forum a schematic and picture of how you have it all wired up.