Changed Lora SF to Lora DR control
This commit is contained in:
1 parent
cc248419ae
commit
c3bad526a7
11 files changed
+90
-83
No files matched your search
@@ -37,7 +37,7 @@ function Decoder(bytes, port) {
|
||||
|
||||
if (port === 3) {
|
||||
// device config data
|
||||
return decode(bytes, [uint8, uint8, int16, uint8, uint8, uint8, uint8, bitmap1, bitmap2, version], ['lorasf', 'txpower', 'rssilimit', 'sendcycle', 'wifichancycle', 'blescantime', 'rgblum', 'flags', 'payloadmask', 'version']);
|
||||
return decode(bytes, [uint8, uint8, int16, uint8, uint8, uint8, uint8, bitmap1, bitmap2, version], ['loradr', 'txpower', 'rssilimit', 'sendcycle', 'wifichancycle', 'blescantime', 'rgblum', 'flags', 'payloadmask', 'version']);
|
||||
}
|
||||
|
||||
if (port === 4) {
|
||||
|
||||
+18
-17
@@ -9,19 +9,20 @@ nvs_handle my_handle;
|
||||
esp_err_t err;
|
||||
|
||||
#define PAYLOADMASK \
|
||||
((GPS_DATA | ALARM_DATA | MEMS_DATA | COUNT_DATA | SENSOR1_DATA | \
|
||||
SENSOR2_DATA | SENSOR3_DATA) & ~BATT_DATA)
|
||||
((GPS_DATA | ALARM_DATA | MEMS_DATA | COUNT_DATA | SENSOR1_DATA | \
|
||||
SENSOR2_DATA | SENSOR3_DATA) & \
|
||||
~BATT_DATA)
|
||||
|
||||
// populate cfg vars with factory settings
|
||||
void defaultConfig() {
|
||||
cfg.lorasf = LORASFDEFAULT; // 7-12, initial lora sf, see pacounter.conf
|
||||
cfg.txpower = 15; // 2-15, lora tx power
|
||||
cfg.adrmode = 1; // 0=disabled, 1=enabled
|
||||
cfg.screensaver = 0; // 0=disabled, 1=enabled
|
||||
cfg.screenon = 1; // 0=disabled, 1=enabled
|
||||
cfg.countermode = 0; // 0=cyclic, 1=cumulative, 2=cyclic confirmed
|
||||
cfg.rssilimit = 0; // threshold for rssilimiter, negative value!
|
||||
cfg.sendcycle = SENDCYCLE; // payload send cycle [seconds/2]
|
||||
cfg.loradr = LORADRDEFAULT; // 0-15, lora datarate, see pacounter.conf
|
||||
cfg.txpower = LORATXPOWDEFAULT; // 0-15, lora tx power
|
||||
cfg.adrmode = 1; // 0=disabled, 1=enabled
|
||||
cfg.screensaver = 0; // 0=disabled, 1=enabled
|
||||
cfg.screenon = 1; // 0=disabled, 1=enabled
|
||||
cfg.countermode = 0; // 0=cyclic, 1=cumulative, 2=cyclic confirmed
|
||||
cfg.rssilimit = 0; // threshold for rssilimiter, negative value!
|
||||
cfg.sendcycle = SENDCYCLE; // payload send cycle [seconds/2]
|
||||
cfg.wifichancycle =
|
||||
WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100]
|
||||
cfg.blescantime =
|
||||
@@ -96,9 +97,9 @@ void saveConfig() {
|
||||
strcmp(storedversion, cfg.version) != 0)
|
||||
nvs_set_str(my_handle, "version", cfg.version);
|
||||
|
||||
if (nvs_get_i8(my_handle, "lorasf", &flash8) != ESP_OK ||
|
||||
flash8 != cfg.lorasf)
|
||||
nvs_set_i8(my_handle, "lorasf", cfg.lorasf);
|
||||
if (nvs_get_i8(my_handle, "loradr", &flash8) != ESP_OK ||
|
||||
flash8 != cfg.loradr)
|
||||
nvs_set_i8(my_handle, "loradr", cfg.loradr);
|
||||
|
||||
if (nvs_get_i8(my_handle, "txpower", &flash8) != ESP_OK ||
|
||||
flash8 != cfg.txpower)
|
||||
@@ -221,11 +222,11 @@ void loadConfig() {
|
||||
ESP_LOGI(TAG, "bsecstate = %d", cfg.bsecstate[BSEC_MAX_STATE_BLOB_SIZE]);
|
||||
};
|
||||
|
||||
if (nvs_get_i8(my_handle, "lorasf", &flash8) == ESP_OK) {
|
||||
cfg.lorasf = flash8;
|
||||
ESP_LOGI(TAG, "lorasf = %d", flash8);
|
||||
if (nvs_get_i8(my_handle, "loradr", &flash8) == ESP_OK) {
|
||||
cfg.loradr = flash8;
|
||||
ESP_LOGI(TAG, "loradr = %d", flash8);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "lorasf set to default %d", cfg.lorasf);
|
||||
ESP_LOGI(TAG, "loradr set to default %d", cfg.loradr);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -205,7 +205,7 @@ void draw_page(time_t t, uint8_t page) {
|
||||
u8x8.setCursor(11, 3);
|
||||
if (cfg.adrmode) // if ADR=on then display SF value inverse
|
||||
u8x8.setInverseFont(1);
|
||||
u8x8.printf("%5s", getSfName(LMIC.rps));
|
||||
u8x8.printf("%5s", getSfName(updr2rps(LMIC.datarate)));
|
||||
if (cfg.adrmode) // switch off inverse if it was turned on
|
||||
u8x8.setInverseFont(0);
|
||||
#endif // HAS_LORA
|
||||
|
||||
+16
-49
@@ -234,11 +234,15 @@ void onEvent(ev_t ev) {
|
||||
sprintf(display_line6, " "); // clear previous lmic status
|
||||
// set data rate adaptation according to saved setting
|
||||
LMIC_setAdrMode(cfg.adrmode);
|
||||
// set data rate and transmit power if we have no ADR
|
||||
// set data rate and transmit power to defaults only if we have no ADR
|
||||
if (!cfg.adrmode)
|
||||
switch_lora(cfg.lorasf, cfg.txpower);
|
||||
LMIC_setDrTxpow(assertDR(cfg.loradr), cfg.txpower);
|
||||
// show current devaddr
|
||||
ESP_LOGI(TAG, "DEVaddr=%08X", LMIC.devaddr);
|
||||
ESP_LOGI(TAG, "Radio parameters %s / %s / %s",
|
||||
getSfName(updr2rps(LMIC.datarate)),
|
||||
getBwName(updr2rps(LMIC.datarate)),
|
||||
getCrName(updr2rps(LMIC.datarate)));
|
||||
break;
|
||||
|
||||
case EV_RFU1:
|
||||
@@ -321,53 +325,6 @@ void onEvent(ev_t ev) {
|
||||
}
|
||||
}
|
||||
|
||||
// helper function to assign LoRa datarates to numeric spreadfactor values
|
||||
void switch_lora(uint8_t sf, uint8_t tx) {
|
||||
if (tx > 20)
|
||||
return;
|
||||
cfg.txpower = tx;
|
||||
switch (sf) {
|
||||
case 7:
|
||||
LMIC_setDrTxpow(DR_SF7, tx);
|
||||
cfg.lorasf = sf;
|
||||
break;
|
||||
case 8:
|
||||
LMIC_setDrTxpow(DR_SF8, tx);
|
||||
cfg.lorasf = sf;
|
||||
break;
|
||||
case 9:
|
||||
LMIC_setDrTxpow(DR_SF9, tx);
|
||||
cfg.lorasf = sf;
|
||||
break;
|
||||
case 10:
|
||||
LMIC_setDrTxpow(DR_SF10, tx);
|
||||
cfg.lorasf = sf;
|
||||
break;
|
||||
case 11:
|
||||
#if defined(CFG_us915)
|
||||
LMIC_setDrTxpow(DR_SF11CR, tx);
|
||||
cfg.lorasf = sf;
|
||||
break;
|
||||
#else
|
||||
LMIC_setDrTxpow(DR_SF11, tx);
|
||||
cfg.lorasf = sf;
|
||||
break;
|
||||
#endif
|
||||
case 12:
|
||||
#if defined(CFG_us915)
|
||||
LMIC_setDrTxpow(DR_SF12CR, tx);
|
||||
cfg.lorasf = sf;
|
||||
break;
|
||||
#else
|
||||
LMIC_setDrTxpow(DR_SF12, tx);
|
||||
cfg.lorasf = sf;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// LMIC send task
|
||||
void lora_send(void *pvParameters) {
|
||||
configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
|
||||
@@ -698,4 +655,14 @@ const char *getSfName(rps_t rps) {
|
||||
return t[getSf(rps)];
|
||||
}
|
||||
|
||||
const char *getBwName(rps_t rps) {
|
||||
const char *const t[] = {"BW125", "BW250", "BW500", "BWrfu"};
|
||||
return t[getBw(rps)];
|
||||
}
|
||||
|
||||
const char *getCrName(rps_t rps) {
|
||||
const char *const t[] = {"CR 4/5", "CR 4/6", "CR 4/7", "CR 4/8"};
|
||||
return t[getCr(rps)];
|
||||
}
|
||||
|
||||
#endif // HAS_LORA
|
||||
+4
-1
@@ -1,3 +1,5 @@
|
||||
// clang-format off
|
||||
|
||||
// ----- Paxcounter user config file ------
|
||||
//
|
||||
// --> adapt to your needs and use case <--
|
||||
@@ -46,7 +48,8 @@
|
||||
#define MEM_LOW 2048 // [Bytes] low memory threshold triggering a send cycle
|
||||
#define RETRANSMIT_RCMD 5 // [seconds] wait time before retransmitting rcommand results
|
||||
#define PAYLOAD_BUFFER_SIZE 51 // maximum size of payload block per transmit
|
||||
#define LORASFDEFAULT 9 // 7 ... 12 SF, according to LoRaWAN specs
|
||||
#define LORADRDEFAULT 5 // 0 .. 15, LoRaWAN datarate, according to regional LoRaWAN specs [default = 5]
|
||||
#define LORATXPOWDEFAULT 14 // 0 .. 15, LoRaWAN TX power
|
||||
#define MAXLORARETRY 500 // maximum count of TX retries if LoRa busy
|
||||
#define SEND_QUEUE_SIZE 10 // maximum number of messages in payload send queue [1 = no queue]
|
||||
|
||||
|
||||
+2
-2
@@ -36,7 +36,7 @@ void PayloadConvert::addVoltage(uint16_t value) {
|
||||
}
|
||||
|
||||
void PayloadConvert::addConfig(configData_t value) {
|
||||
buffer[cursor++] = value.lorasf;
|
||||
buffer[cursor++] = value.loradr;
|
||||
buffer[cursor++] = value.txpower;
|
||||
buffer[cursor++] = value.adrmode;
|
||||
buffer[cursor++] = value.screensaver;
|
||||
@@ -157,7 +157,7 @@ void PayloadConvert::addAlarm(int8_t rssi, uint8_t msg) {
|
||||
void PayloadConvert::addVoltage(uint16_t value) { writeUint16(value); }
|
||||
|
||||
void PayloadConvert::addConfig(configData_t value) {
|
||||
writeUint8(value.lorasf);
|
||||
writeUint8(value.loradr);
|
||||
writeUint8(value.txpower);
|
||||
writeUint16(value.rssilimit);
|
||||
writeUint8(value.sendcycle);
|
||||
|
||||
+26
-6
@@ -193,10 +193,22 @@ void set_monitor(uint8_t val[]) {
|
||||
cfg.monitormode = val[0] ? 1 : 0;
|
||||
}
|
||||
|
||||
void set_lorasf(uint8_t val[]) {
|
||||
void set_loradr(uint8_t val[]) {
|
||||
#if (HAS_LORA)
|
||||
ESP_LOGI(TAG, "Remote command: set LoRa SF to %d", val[0]);
|
||||
switch_lora(val[0], cfg.txpower);
|
||||
if (validDR(val[0])) {
|
||||
cfg.loradr = val[0];
|
||||
ESP_LOGI(TAG, "Remote command: set LoRa Datarate to %d", cfg.loradr);
|
||||
LMIC_setDrTxpow(assertDR(cfg.loradr), cfg.txpower);
|
||||
ESP_LOGI(TAG, "Radio parameters now %s / %s / %s",
|
||||
getSfName(updr2rps(LMIC.datarate)),
|
||||
getBwName(updr2rps(LMIC.datarate)),
|
||||
getCrName(updr2rps(LMIC.datarate)));
|
||||
|
||||
} else
|
||||
ESP_LOGI(
|
||||
TAG,
|
||||
"Remote command: set LoRa Datarate called with illegal datarate %d",
|
||||
val[0]);
|
||||
#else
|
||||
ESP_LOGW(TAG, "Remote command: LoRa not implemented");
|
||||
#endif // HAS_LORA
|
||||
@@ -247,8 +259,16 @@ void set_rgblum(uint8_t val[]) {
|
||||
|
||||
void set_lorapower(uint8_t val[]) {
|
||||
#if (HAS_LORA)
|
||||
ESP_LOGI(TAG, "Remote command: set LoRa TXPOWER to %d", val[0]);
|
||||
switch_lora(cfg.lorasf, val[0]);
|
||||
// set data rate and transmit power only if we have no ADR
|
||||
if (!cfg.adrmode) {
|
||||
cfg.txpower = val[0] & 0x0f;
|
||||
ESP_LOGI(TAG, "Remote command: set LoRa TXPOWER to %d", cfg.txpower);
|
||||
LMIC_setDrTxpow(assertDR(cfg.loradr), cfg.txpower);
|
||||
} else
|
||||
ESP_LOGI(
|
||||
TAG,
|
||||
"Remote command: set LoRa TXPOWER, not executed because ADR is on");
|
||||
|
||||
#else
|
||||
ESP_LOGW(TAG, "Remote command: LoRa not implemented");
|
||||
#endif // HAS_LORA
|
||||
@@ -331,7 +351,7 @@ void set_flush(uint8_t val[]) {
|
||||
static cmd_t table[] = {
|
||||
{0x01, set_rssi, 1, true}, {0x02, set_countmode, 1, true},
|
||||
{0x03, set_gps, 1, true}, {0x04, set_display, 1, true},
|
||||
{0x05, set_lorasf, 1, true}, {0x06, set_lorapower, 1, true},
|
||||
{0x05, set_loradr, 1, true}, {0x06, set_lorapower, 1, true},
|
||||
{0x07, set_loraadr, 1, true}, {0x08, set_screensaver, 1, true},
|
||||
{0x09, set_reset, 1, true}, {0x0a, set_sendcycle, 1, true},
|
||||
{0x0b, set_wifichancycle, 1, true}, {0x0c, set_blescantime, 1, true},
|
||||
|
||||
Reference in new issue
Block a user