diff --git a/MultiNode/MNLib.cpp b/MultiNode/MNLib.cpp index 2db0ebf..95666ec 100644 --- a/MultiNode/MNLib.cpp +++ b/MultiNode/MNLib.cpp @@ -196,7 +196,13 @@ void loadMemory() void refreshConfig() { - radio.setFrequency(configuration.modem_frequency); + float frequency = configuration.modem_frequency; + + if (MODEM_FREQ_LOWER < value && value < MODEM_FREQ_UPPER) + radio.setFrequency(configuration.modem_frequency); + + else + radio.setFrequency(0); // The default transmitter power is 13dBm, using PA_BOOST. // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then @@ -308,7 +314,7 @@ bool receive() { case MT_Time: rtc_offset = server_message_id - RTC->MODE1.COUNT.reg; - + if (server_message_id > message_id) // Ensure that IDs are sequential message_id = server_message_id; diff --git a/MultiNode/MNLib.h b/MultiNode/MNLib.h index ffb9586..28e40c6 100644 --- a/MultiNode/MNLib.h +++ b/MultiNode/MNLib.h @@ -12,7 +12,8 @@ #define MODEM_CONFIG RH_RF95::Bw125Cr45Sf128 #define MODEM_POWER 13 -#define MODEM_FREQ 868.0 +#define MODEM_FREQ_LOWER 863 +#define MODEM_FREQ_UPPER 870 #define HASH_LENGTH 8 // 8 bytes #define RF_SS_PIN 1 diff --git a/MultiNode/MultiNode.ino b/MultiNode/MultiNode.ino index 2fa2e7d..d0a8a86 100644 --- a/MultiNode/MultiNode.ino +++ b/MultiNode/MultiNode.ino @@ -124,6 +124,43 @@ void loop() case 's': saveMemory(); + break; + + case 'T': + case 't': + String in_str = ""; + while (in_str != "END") + { + in_str = SerialUSB.readStringUntil('\n'); + in_str.trim(); + if (in_str[0] != '#') + { + in_str.toLowerCase(); + in_str.replace("\t", " "); + + while (in_str.indexOf(" ") != -1) + in_str.replace(" ", " "); + + int space_index = in_str.indexOf(" "); + String option = in_str.substring(0, space_index); + + if (option == "frequency") + { + float value = in_str.substring(space_index, in_str.indexOf(" ", space_index + 1)).toFloat(); + if (MODEM_FREQ_LOWER < value && value < MODEM_FREQ_UPPER) + configuration.modem_frequency = value; + else + SerialUSB.print("Frequency out of range!") + } + else if (option == "power") + int value = in_str.substring(space_index, in_str.indexOf(" ", space_index + 1)).toInt(); + if (2 < value && value < 20) + configuration.modem_power = value; + else + SerialUSB.print("Power out of range!") + } + } + break; } } @@ -154,7 +191,7 @@ void loop() long next_tick_device_dt = next_tick_device - now_time; long next_tick_sensors_dt = next_tick_sensors - now_time; long min_delay = min(next_tick_device_dt, next_tick_sensors_dt); - + if (min_delay > 1000 && !USBDevice.connected() && message_id > 1000000000) // Listen until the time is initialized { power_sleep(min_delay);