Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/simple_repeater/MyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
_prefs.advert_loc_policy = ADVERT_LOC_PREFS;

_prefs.adc_multiplier = 0.0f; // 0.0f means use default board multiplier
_prefs.idle_interval = 0;
}

void MyMesh::begin(FILESYSTEM *fs) {
Expand Down
1 change: 1 addition & 0 deletions examples/simple_repeater/MyMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
const char* getBuildDate() override { return FIRMWARE_BUILD_DATE; }
const char* getRole() override { return FIRMWARE_ROLE; }
const char* getNodeName() { return _prefs.node_name; }
const uint32_t getIdleInterval() { return _prefs.idle_interval; }
NodePrefs* getNodePrefs() {
return &_prefs;
}
Expand Down
16 changes: 16 additions & 0 deletions examples/simple_repeater/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ void halt() {

static char command[160];

constexpr unsigned long ACTIVE_TIME_MS_INUSE = 3 * 60 * 1000; // 3 minutes
constexpr unsigned long ACTIVE_TIME_MS_IDLE = 5 * 1000; // 5 seconds

unsigned long active_timestamp;
unsigned long active_time_ms = ACTIVE_TIME_MS_INUSE;

void setup() {
Serial.begin(115200);
delay(1000);
Expand Down Expand Up @@ -82,6 +88,7 @@ void setup() {

// send out initial Advertisement to the mesh
the_mesh.sendSelfAdvertisement(16000);
active_timestamp = millis();
}

void loop() {
Expand All @@ -103,6 +110,8 @@ void loop() {
Serial.print('\n');
command[len - 1] = 0; // replace newline with C string null terminator
char reply[160];
active_timestamp = millis();
active_time_ms = ACTIVE_TIME_MS_INUSE;
the_mesh.handleCommand(0, command, reply); // NOTE: there is no sender_timestamp via serial!
if (reply[0]) {
Serial.print(" -> "); Serial.println(reply);
Expand All @@ -117,4 +126,11 @@ void loop() {
ui_task.loop();
#endif
rtc_clock.tick();

if (the_mesh.getIdleInterval() && ((millis() - active_timestamp) > active_time_ms) &&
!the_mesh.hasOutboundPackets()) {
radio_driver.blockTaskUntilRXEvent(the_mesh.getIdleInterval() * 1000);
active_timestamp = millis();
active_time_ms = ACTIVE_TIME_MS_IDLE;
}
}
1 change: 1 addition & 0 deletions src/Dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class Dispatcher {
Packet* obtainNewPacket();
void releasePacket(Packet* packet);
void sendPacket(Packet* packet, uint8_t priority, uint32_t delay_millis=0);
bool hasOutboundPackets() { return _mgr->getOutboundCount(0xFFFFFFFF); }

unsigned long getTotalAirTime() const { return total_air_time; } // in milliseconds
unsigned long getReceiveAirTime() const {return rx_air_time; }
Expand Down
14 changes: 11 additions & 3 deletions src/helpers/CommonCLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
file.read((uint8_t *)&_prefs->gps_interval, sizeof(_prefs->gps_interval)); // 157
file.read((uint8_t *)&_prefs->advert_loc_policy, sizeof (_prefs->advert_loc_policy)); // 161
file.read((uint8_t *)&_prefs->discovery_mod_timestamp, sizeof(_prefs->discovery_mod_timestamp)); // 162
file.read((uint8_t *)&_prefs->adc_multiplier, sizeof(_prefs->adc_multiplier)); // 166
// 170
file.read((uint8_t *)&_prefs->adc_multiplier, sizeof(_prefs->adc_multiplier)); // 166
file.read((uint8_t *)&_prefs->idle_interval, sizeof(_prefs->idle_interval)); // 170
// 174

// sanitise bad pref values
_prefs->rx_delay_base = constrain(_prefs->rx_delay_base, 0, 20.0f);
Expand Down Expand Up @@ -151,7 +152,8 @@ void CommonCLI::savePrefs(FILESYSTEM* fs) {
file.write((uint8_t *)&_prefs->advert_loc_policy, sizeof(_prefs->advert_loc_policy)); // 161
file.write((uint8_t *)&_prefs->discovery_mod_timestamp, sizeof(_prefs->discovery_mod_timestamp)); // 162
file.write((uint8_t *)&_prefs->adc_multiplier, sizeof(_prefs->adc_multiplier)); // 166
// 170
file.write((uint8_t *)&_prefs->idle_interval, sizeof(_prefs->idle_interval)); // 170
// 174

file.close();
}
Expand Down Expand Up @@ -301,6 +303,8 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
sprintf(reply, "> %d", (uint32_t) _prefs->tx_power_dbm);
} else if (memcmp(config, "freq", 4) == 0) {
sprintf(reply, "> %s", StrHelper::ftoa(_prefs->freq));
} else if (memcmp(config, "idle.interval", 13) == 0) {
sprintf(reply, "> %d", ((uint32_t)_prefs->idle_interval));
} else if (memcmp(config, "public.key", 10) == 0) {
strcpy(reply, "> ");
mesh::Utils::toHex(&reply[2], _callbacks->getSelfId().pub_key, PUB_KEY_SIZE);
Expand Down Expand Up @@ -484,6 +488,10 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
_prefs->freq = atof(&config[5]);
savePrefs();
strcpy(reply, "OK - reboot to apply");
} else if (memcmp(config, "idle.interval ", 14) == 0) {
_prefs->idle_interval = atoi(&config[14]);
savePrefs();
strcpy(reply, "OK");
#ifdef WITH_BRIDGE
} else if (memcmp(config, "bridge.enabled ", 15) == 0) {
_prefs->bridge_enabled = memcmp(&config[15], "on", 2) == 0;
Expand Down
1 change: 1 addition & 0 deletions src/helpers/CommonCLI.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct NodePrefs { // persisted to file
uint8_t advert_loc_policy;
uint32_t discovery_mod_timestamp;
float adc_multiplier;
uint32_t idle_interval; // in seconds
};

class CommonCLICallbacks {
Expand Down
11 changes: 11 additions & 0 deletions src/helpers/radiolib/RadioLibWrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define SAMPLING_THRESHOLD 14

static volatile uint8_t state = STATE_IDLE;
static SemaphoreHandle_t rx_wait_sem;

// this function is called when a complete packet
// is transmitted by the module
Expand All @@ -22,6 +23,8 @@ static
void setFlag(void) {
// we sent a packet, set the flag
state |= STATE_INT_READY;

if (state & STATE_RX) xSemaphoreGive(rx_wait_sem);
}

void RadioLibWrapper::begin() {
Expand All @@ -38,13 +41,21 @@ void RadioLibWrapper::begin() {
// start average out some samples
_num_floor_samples = 0;
_floor_sample_sum = 0;

rx_wait_sem = xSemaphoreCreateBinary();
xSemaphoreGive(rx_wait_sem);
xSemaphoreTake(rx_wait_sem, portMAX_DELAY);
}

void RadioLibWrapper::idle() {
_radio->standby();
state = STATE_IDLE; // need another startReceive()
}

int RadioLibWrapper::blockTaskUntilRXEvent(unsigned int timeout = 5000) {
return xSemaphoreTake(rx_wait_sem, pdMS_TO_TICKS(timeout));
}

void RadioLibWrapper::triggerNoiseFloorCalibrate(int threshold) {
_threshold = threshold;
if (_num_floor_samples >= NUM_NOISE_FLOOR_SAMPLES) { // ignore trigger if currently sampling
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/radiolib/RadioLibWrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class RadioLibWrapper : public mesh::Radio {
return isChannelActive();
}

int blockTaskUntilRXEvent(unsigned int timeout);

virtual float getCurrentRSSI() =0;

int getNoiseFloor() const override { return _noise_floor; }
Expand Down
6 changes: 4 additions & 2 deletions src/helpers/sensors/EnvironmentSensorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ void EnvironmentSensorManager::rakGPSInit(){
MESH_DEBUG_PRINTLN("No GPS found");
gps_active = false;
gps_detected = false;
Serial1.end();
return;
}

Expand Down Expand Up @@ -644,8 +645,7 @@ bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){

_location = &RAK12500_provider;
return true;
}
else if(Serial1){
} else if (Serial1.available()) {
MESH_DEBUG_PRINTLN("Serial GPS init correctly and is turned on");
if(PIN_GPS_EN){
gpsResetPin = PIN_GPS_EN;
Expand All @@ -655,6 +655,8 @@ bool EnvironmentSensorManager::gpsIsAwake(uint8_t ioPin){
gps_detected = true;
return true;
}

pinMode(ioPin, INPUT);
MESH_DEBUG_PRINTLN("GPS did not init with this IO pin... try the next");
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion variants/rak4631/RAK4631Board.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// LoRa radio module pins for RAK4631
#define P_LORA_DIO_1 47
#define P_LORA_NSS 42
#define P_LORA_RESET RADIOLIB_NC // 38
#define P_LORA_RESET 38
#define P_LORA_BUSY 46
#define P_LORA_SCLK 43
#define P_LORA_MISO 45
Expand Down