I want to scan LoRa frequencies to choose a low traffic channel for a LoRaWAN. sendTester.ino below sends a transparent mode message on channel 0x23 every second and scanner.ino listens cycling through a small range of channels that includes 0x23. It reports channels with non-zero rssi values.
The problem is that scanner.ino hears a few consecutive (5 – 10) messages on 0x23 but then goes deaf. I’m baffled. Is a buffer overflowing?
sendTest.ino
/*
* sends a message on channel 23 at 1 second intervals
*/
#include "Arduino.h"
#include "LoRa_E22.h"
// ---------- esp32 pins --------------
LoRa_E22 e22ttl(&Serial2, 15, 21, 19); // RX AUX M0 M1
void setup() {
Serial.begin(9600);
delay(500);
// Startup all pins and UART
e22ttl.begin();
// If you have ever change configuration you must restore It
ResponseStructContainer c;
c = e22ttl.getConfiguration();
Configuration configuration = *(Configuration*) c.data;
Serial.println(c.status.getResponseDescription());
configuration.ADDL = 0x03;
configuration.ADDH = 0x00;
configuration.NETID = 0x00;
configuration.CHAN = 0x23;
configuration.SPED.uartBaudRate = UART_BPS_9600;
configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
configuration.SPED.uartParity = MODE_00_8N1;
configuration.OPTION.subPacketSetting = SPS_240_00;
configuration.OPTION.RSSIAmbientNoise = RSSI_AMBIENT_NOISE_DISABLED;
configuration.OPTION.transmissionPower = POWER_22;
configuration.TRANSMISSION_MODE.enableRSSI = RSSI_ENABLED;
configuration.TRANSMISSION_MODE.fixedTransmission = FT_TRANSPARENT_TRANSMISSION;
configuration.TRANSMISSION_MODE.enableRepeater = REPEATER_DISABLED;
configuration.TRANSMISSION_MODE.enableLBT = LBT_DISABLED;
configuration.TRANSMISSION_MODE.WORTransceiverControl = WOR_RECEIVER;
configuration.TRANSMISSION_MODE.WORPeriod = WOR_2000_011;
e22ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
c.close();
}
void loop() {
// Send message
ResponseStatus rs = e22ttl.sendMessage("Hello, world?");
// Check if problem with sending
Serial.println(rs.getResponseDescription());
delay(1000);
}
<div></div> scanner.ino
/* Look for LoRa transmissions - test with sendTester.ino
* scans channels 0 - 80
* receives in transparent mode
* writes received channel id, RSSI, message to stdout
*/
#include "Arduino.h"
#include "LoRa_E22.h"
// ---------- esp32 pins --------------
LoRa_E22 e22ttl(&Serial2, 15, 21, 19); // RX AUX M0 M1
#define ENABLE_RSSI true
Configuration configuration;
ResponseStructContainer c;
int channel = 0x00;
void setup() {
Serial.begin(9600);
delay(500);
// Startup all pins and UART
e22ttl.begin();
c = e22ttl.getConfiguration();
configuration = *(Configuration*) c.data;
Serial.println(c.status.getResponseDescription());
configuration.ADDL = 0x03;
configuration.ADDH = 0x00;
configuration.NETID = 0x00;
// configuration.CHAN = 0x23;
configuration.SPED.uartBaudRate = UART_BPS_9600;
configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
configuration.SPED.uartParity = MODE_00_8N1;
configuration.OPTION.subPacketSetting = SPS_240_00;
configuration.OPTION.RSSIAmbientNoise = RSSI_AMBIENT_NOISE_DISABLED;
configuration.OPTION.transmissionPower = POWER_22;
configuration.TRANSMISSION_MODE.enableRSSI = RSSI_ENABLED;
configuration.TRANSMISSION_MODE.fixedTransmission = FT_TRANSPARENT_TRANSMISSION;
configuration.TRANSMISSION_MODE.enableRepeater = REPEATER_DISABLED;
configuration.TRANSMISSION_MODE.enableLBT = LBT_DISABLED;
configuration.TRANSMISSION_MODE.WORTransceiverControl = WOR_RECEIVER;
configuration.TRANSMISSION_MODE.WORPeriod = WOR_2000_011;
e22ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
c.close();
}
void loop() {
channel = channel % 0x25; // scan only 0x22 - 0x24 for testing
if (channel == 0x00) { channel = 0x22; }
c = e22ttl.getConfiguration(); // change to next channel
configuration = *(Configuration*) c.data;
configuration.CHAN = channel;
e22ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
Serial.print("channel "); Serial.println(channel);
c.close();
delay(1000);
while (!e22ttl.available()>1) { ;} // wait for message
ResponseContainer rc = e22ttl.receiveMessageRSSI(); // read the String message
// If something goes wrong print error
if (rc.status.code!=1) {
Serial.print("1 "); Serial.println(rc.status.getResponseDescription());
}
else if (rc.rssi > 0) {
// Print the data received
Serial.print(channel);
Serial.print("\t");
Serial.print(rc.rssi);
Serial.print("\t");
Serial.print(rc.data);
Serial.print("\n");
}
channel++;
}
When I commented out the code that sets the frequency in the iteration through the channels …
c = e22ttl.getConfiguration(); // change to next channel
configuration = *(Configuration*) c.data;
configuration.CHAN = channel;
e22ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
Serial.print("channel "); Serial.println(channel);
c.close();
the sketch stays on the setup() channel 0x23 and receives the transmission properly. Should I give up on scanning or is there a good way to change the channel on the fly?
Hi Sid,
try to put the procedure in a function to check if something in the context remains dirty.
Use only local variables and not global ones.
Bye Renzo
Sorry to be a pest and grateful for your help so far, still haven’t been able to change E22 channels on the fly. I replaced the inline channel-changing code with a function as you suggested but that didn’t fix it. The sketch receives data when the channel is fixed but doesn’t when I cycle through the channel, as in the code blow. I re-implemented it with a Pi Pico and get the same behaviour. Have you other suggestions?
/* Look for LoRa transmissions - on Pi Pico, test with sendTester.ino
* scans channels 0x22 - 0x24
* receives in transparent mode
* writes received channel id, RSSI, message to stdout
*
* E22 ----- Raspberry Pi Pico
* M0 ----- 10
* M1 ----- 11
* TX ----- 9 (PullUP)
* RX ----- 8 (PullUP)
* AUX ----- 2 (PullUP)
*/
#include "Arduino.h"
#include "LoRa_E22.h"
#define ENABLE_RSSI true
#define beeper 25 // led signals LoRa reception
// ---------- Raspberry PI Pico pins --------------
LoRa_E22 e22ttl(&Serial2, 2, 10, 11); // RX AUX M0 M1
// -------------------------------------
int channel = 0x00;
void setup() {
Serial.begin(9600);
delay(500);
// Startup all pins and UART
e22ttl.begin();
// If you have ever change configuration you must restore It
Configuration configuration;
ResponseStructContainer c;
c = e22ttl.getConfiguration();
configuration = *(Configuration*) c.data;
Serial.println(c.status.getResponseDescription());
configuration.ADDL = 0x03;
configuration.ADDH = 0x00;
configuration.NETID = 0x00;
configuration.CHAN = 23;
configuration.SPED.uartBaudRate = UART_BPS_9600;
configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
configuration.SPED.uartParity = MODE_00_8N1;
configuration.OPTION.subPacketSetting = SPS_240_00;
configuration.OPTION.RSSIAmbientNoise = RSSI_AMBIENT_NOISE_DISABLED;
configuration.OPTION.transmissionPower = POWER_22;
configuration.TRANSMISSION_MODE.enableRSSI = RSSI_ENABLED;
configuration.TRANSMISSION_MODE.fixedTransmission = FT_TRANSPARENT_TRANSMISSION;
configuration.TRANSMISSION_MODE.enableRepeater = REPEATER_DISABLED;
configuration.TRANSMISSION_MODE.enableLBT = LBT_DISABLED;
configuration.TRANSMISSION_MODE.WORTransceiverControl = WOR_RECEIVER;
configuration.TRANSMISSION_MODE.WORPeriod = WOR_2000_011;
e22ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
c.close();
}
void loop() {
channel = channel % 0x25;
if (channel == 0x00) { channel = 0x22; } // cycle through only 0x22 - 0x24
set_channel(channel); // receives ok if this line commented out
Serial.print("channel "); Serial.println(channel);
delay(2000);
if (e22ttl.available()>1) {
// read the String message
ResponseContainer rc = e22ttl.receiveMessageRSSI();
// Is something goes wrong print error
if (rc.status.code!=1) {
Serial.print("0 "); Serial.println(rc.status.getResponseDescription());
}
else if (rc.rssi > 0) {
// Print the data received
// Serial.println(rc.status.getResponseDescription());
Serial.print(channel);
Serial.print("\t");
Serial.print(rc.rssi);
Serial.print("\t");
Serial.print(rc.data);
Serial.print("\n");
}
}
channel++;
}
void set_channel(int chan) {
Configuration configuration;
ResponseStructContainer c;
c = e22ttl.getConfiguration(); // change radio to arg channel
configuration = *(Configuration*) c.data;
configuration.CHAN = chan;
e22ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
c.close();
}
I’m able to scan channels now. Instead of only changing the channel and saving that parameter alone with setConfiguration() in loop() as in the code above, I copied all of the setup() code between e22ttl.begin() and c.close() into the function set_channel() and call it in loop(), iterating through the channels successfully. When I removed all of the parameter assignments except CHAN from the function, it still worked. Now I see that the above code would have worked if I’d included e22ttl.begin() in the function.
Maintaining a repository (or site or forum) is a lot like tending to a garden - it requires constant care and attention to keep it thriving. If you're a skilled gardener (or coder!) and want to help keep our repository blooming, we'd love to have you on board! We're also looking for talented writers and forum moderators to help us grow our community. Interested in joining our team? Don't hesitate to reach out and let us know how you can contribute!
Are you a fan of electronics or programming? Share your knowledge with others, write a simple tutorial or how to make a great project Contact me: share_your_ideas@mischianti.org
The content displayed on this website is protected under a CC BY-NC-ND license. Visitors are prohibited from using, redistributing, or altering any content from this website for commercial purposes, including generating revenue through advertising. Any unauthorized use is a violation of the license terms and legal action may be taken against individuals or entities found to be in violation.
You must also provide the link to the source.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.