minor fixes
This commit is contained in:
parent
0777f53b93
commit
61bd56860f
@ -171,10 +171,12 @@ void onEvent (ev_t ev) {
|
|||||||
|
|
||||||
joinstate=true;
|
joinstate=true;
|
||||||
strcpy_P(buff, PSTR("JOINED"));
|
strcpy_P(buff, PSTR("JOINED"));
|
||||||
|
sprintf(display_lora, ""); // clear previous lmic status message from display
|
||||||
|
|
||||||
// Disable link check validation (automatically enabled
|
// Disable link check validation (automatically enabled
|
||||||
// during join, but not supported by TTN at this time).
|
// during join, but not supported by TTN at this time).
|
||||||
LMIC_setLinkCheckMode(0);
|
// LMIC_setLinkCheckMode(0); -> do we need this?
|
||||||
|
|
||||||
// set data rate adaptation
|
// set data rate adaptation
|
||||||
LMIC_setAdrMode(cfg.adrmode);
|
LMIC_setAdrMode(cfg.adrmode);
|
||||||
// Set data rate and transmit power (note: txpower seems to be ignored by the library)
|
// Set data rate and transmit power (note: txpower seems to be ignored by the library)
|
||||||
@ -187,7 +189,7 @@ void onEvent (ev_t ev) {
|
|||||||
case EV_TXCOMPLETE:
|
case EV_TXCOMPLETE:
|
||||||
|
|
||||||
strcpy_P(buff, (LMIC.txrxFlags & TXRX_ACK) ? PSTR("RECEIVED ACK") : PSTR("TX COMPLETE"));
|
strcpy_P(buff, (LMIC.txrxFlags & TXRX_ACK) ? PSTR("RECEIVED ACK") : PSTR("TX COMPLETE"));
|
||||||
sprintf(display_lora, ""); // erase previous LoRa message from display
|
sprintf(display_lora, ""); // clear previous lmic status message from display
|
||||||
|
|
||||||
if (LMIC.dataLen) {
|
if (LMIC.dataLen) {
|
||||||
ESP_LOGI(TAG, "Received %d bytes of payload, RSSI %d SNR %d", LMIC.dataLen, LMIC.rssi, (signed char)LMIC.snr / 4);
|
ESP_LOGI(TAG, "Received %d bytes of payload, RSSI %d SNR %d", LMIC.dataLen, LMIC.rssi, (signed char)LMIC.snr / 4);
|
||||||
|
38
src/main.cpp
38
src/main.cpp
@ -134,8 +134,9 @@ static void lora_init (osjob_t* j) {
|
|||||||
LMIC_reset();
|
LMIC_reset();
|
||||||
// This tells LMIC to make the receive windows bigger, in case your clock is 1% faster or slower.
|
// This tells LMIC to make the receive windows bigger, in case your clock is 1% faster or slower.
|
||||||
LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100);
|
LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100);
|
||||||
// start joining
|
// start joining -> will happen automatically after first do_send job
|
||||||
LMIC_startJoining();
|
// LMIC_startJoining();
|
||||||
|
// lmic init done - onEvent() callback will be invoked when events occur
|
||||||
}
|
}
|
||||||
|
|
||||||
// LMIC FreeRTos Task
|
// LMIC FreeRTos Task
|
||||||
@ -552,18 +553,19 @@ void setup() {
|
|||||||
|
|
||||||
sprintf(display_lora, "Join wait");
|
sprintf(display_lora, "Join wait");
|
||||||
|
|
||||||
// setup Display IRQ, thanks to https://techtutorialsx.com/2017/10/07/esp32-arduino-timer-interrupts/
|
// setup display refresh trigger IRQ using esp32 hardware timer 0
|
||||||
|
// for explanation see https://techtutorialsx.com/2017/10/07/esp32-arduino-timer-interrupts/
|
||||||
displaytimer = timerBegin(0, 80, true); // prescaler 80 -> divides 80 MHz CPU freq to 1 MHz, timer 0, count up
|
displaytimer = timerBegin(0, 80, true); // prescaler 80 -> divides 80 MHz CPU freq to 1 MHz, timer 0, count up
|
||||||
timerAttachInterrupt(displaytimer, &DisplayIRQ, true); // interrupt handler DisplayIRQ, triggered by edge
|
timerAttachInterrupt(displaytimer, &DisplayIRQ, true); // interrupt handler DisplayIRQ, triggered by edge
|
||||||
timerAlarmWrite(displaytimer, DISPLAYREFRESH_MS * 1000, true); // reload interrupt after each trigger of display refresh cycle
|
timerAlarmWrite(displaytimer, DISPLAYREFRESH_MS * 1000, true); // reload interrupt after each trigger of display refresh cycle
|
||||||
timerAlarmEnable(displaytimer); // enable display interrupt
|
timerAlarmEnable(displaytimer); // enable display interrupt
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// setup channel rotation IRQ, thanks to https://techtutorialsx.com/2017/10/07/esp32-arduino-timer-interrupts/
|
// setup channel rotation trigger IRQ using esp32 hardware timer 1
|
||||||
channelSwitch = timerBegin(1, 80, true); // prescaler 80 -> divides 80 MHz CPU freq to 1 MHz, timer 1, count up
|
channelSwitch = timerBegin(1, 80, true);
|
||||||
timerAttachInterrupt(channelSwitch, &ChannelSwitchIRQ, true); // interrupt handler, triggered by edge
|
timerAttachInterrupt(channelSwitch, &ChannelSwitchIRQ, true);
|
||||||
timerAlarmWrite(channelSwitch, cfg.wifichancycle * 10000, true); // reload interrupt after each trigger of channel switch cycle
|
timerAlarmWrite(channelSwitch, cfg.wifichancycle * 10000, true);
|
||||||
timerAlarmEnable(channelSwitch); // enable channel switching interrupt
|
timerAlarmEnable(channelSwitch);
|
||||||
|
|
||||||
// show compiled features
|
// show compiled features
|
||||||
ESP_LOGI(TAG, "Features %s", features);
|
ESP_LOGI(TAG, "Features %s", features);
|
||||||
@ -573,21 +575,19 @@ ESP_LOGI(TAG, "Features %s", features);
|
|||||||
printKeys();
|
printKeys();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
os_init(); // setup LMIC
|
os_init(); // initialize lmic run-time environment
|
||||||
LMIC_reset(); // Reset the MAC state. Session and pending data transfers will be discarded.
|
os_setCallback(&initjob, lora_init); // setup initial job & join LoRaWAN network
|
||||||
os_setCallback(&initjob, lora_init); // setup initial job & join network
|
|
||||||
|
|
||||||
wifi_sniffer_init(); // setup wifi in monitor mode and start MAC counting
|
// start lmic runloop in rtos task on core 1 (arduino main loop runs on core 1)
|
||||||
|
|
||||||
// initialize salt value using esp_random() called by random() in arduino-esp32 core
|
|
||||||
// note: do this *after* wifi has started, since gets it's seed from RF noise
|
|
||||||
reset_salt(); // get new 16bit for salting hashes
|
|
||||||
|
|
||||||
// run wifi channel switching task on core 0 and lora lmic task on core 1 (arduino main loop runs on core 1)
|
|
||||||
ESP_LOGI(TAG, "Starting Lora task on core 1");
|
ESP_LOGI(TAG, "Starting Lora task on core 1");
|
||||||
xTaskCreatePinnedToCore(lorawan_loop, "loratask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 1);
|
xTaskCreatePinnedToCore(lorawan_loop, "loratask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 1);
|
||||||
|
|
||||||
|
// start wifi in monitor mode and start channel rotation task on core 0
|
||||||
ESP_LOGI(TAG, "Starting Wifi task on core 0");
|
ESP_LOGI(TAG, "Starting Wifi task on core 0");
|
||||||
|
wifi_sniffer_init();
|
||||||
|
// initialize salt value using esp_random() called by random() in arduino-esp32 core
|
||||||
|
// note: do this *after* wifi has started, since function gets it's seed from RF noise
|
||||||
|
reset_salt(); // get new 16bit for salting hashes
|
||||||
xTaskCreatePinnedToCore(sniffer_loop, "wifisniffer", 2048, ( void * ) 1, 1, NULL, 0);
|
xTaskCreatePinnedToCore(sniffer_loop, "wifisniffer", 2048, ( void * ) 1, 1, NULL, 0);
|
||||||
|
|
||||||
// start BLE scan callback if BLE function is enabled in NVRAM configuration
|
// start BLE scan callback if BLE function is enabled in NVRAM configuration
|
||||||
@ -597,7 +597,7 @@ xTaskCreatePinnedToCore(sniffer_loop, "wifisniffer", 2048, ( void * ) 1, 1, NULL
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Finally: kickoff first sendjob and join, then send initial payload "0000"
|
// kickoff first sendjob -> joins network and transmits initial payload "0000"
|
||||||
uint8_t mydata[] = "0000";
|
uint8_t mydata[] = "0000";
|
||||||
do_send(&sendjob);
|
do_send(&sendjob);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user