merge pull request #21 for testing
This commit is contained in:
parent
f266da5a9f
commit
4246359c30
@ -13,9 +13,11 @@
|
|||||||
#include <lmic.h>
|
#include <lmic.h>
|
||||||
#include <hal/hal.h>
|
#include <hal/hal.h>
|
||||||
|
|
||||||
|
// LED controls
|
||||||
#ifdef HAS_RGB_LED
|
#ifdef HAS_RGB_LED
|
||||||
#include <SmartLeds.h>
|
#include <SmartLeds.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "rgb_led.h"
|
#include "rgb_led.h"
|
||||||
#include "macsniff.h"
|
#include "macsniff.h"
|
||||||
|
|
||||||
|
108
src/main.cpp
108
src/main.cpp
@ -27,11 +27,9 @@ Refer to LICENSE.txt file in repository for more details.
|
|||||||
|
|
||||||
// std::set for unified array functions
|
// std::set for unified array functions
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <Wire.h>
|
|
||||||
|
|
||||||
|
|
||||||
// OLED driver
|
// OLED driver
|
||||||
#include <U8x8lib.h>
|
#include <U8x8lib.h> // includes <wire.h> if needed for other on board i2c components
|
||||||
|
|
||||||
// LMIC-Arduino LoRaWAN Stack
|
// LMIC-Arduino LoRaWAN Stack
|
||||||
#include "loraconf.h"
|
#include "loraconf.h"
|
||||||
@ -197,6 +195,8 @@ void lorawan_loop(void * pvParameters) {
|
|||||||
|
|
||||||
#ifdef HAS_DISPLAY
|
#ifdef HAS_DISPLAY
|
||||||
HAS_DISPLAY u8x8(OLED_RST, OLED_SCL, OLED_SDA);
|
HAS_DISPLAY u8x8(OLED_RST, OLED_SCL, OLED_SDA);
|
||||||
|
#else
|
||||||
|
U8X8_NULL u8x8;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAS_ANTENNA_SWITCH
|
#ifdef HAS_ANTENNA_SWITCH
|
||||||
@ -410,9 +410,9 @@ void init_display(const char *Productname, const char *Version) {
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
// disable brownout detection
|
// disable brownout detection
|
||||||
#ifdef DISABLE_BROWNOUT
|
#ifdef DISABLE_BROWNOUT
|
||||||
// Register with brownout is at address DR_REG_RTCCNTL_BASE + 0xd4
|
// register with brownout is at address DR_REG_RTCCNTL_BASE + 0xd4
|
||||||
(*((volatile uint32_t *)ETS_UNCACHED_ADDR((DR_REG_RTCCNTL_BASE+0xd4)))) = 0;
|
(*((volatile uint32_t *)ETS_UNCACHED_ADDR((DR_REG_RTCCNTL_BASE+0xd4)))) = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -429,10 +429,10 @@ void setup() {
|
|||||||
ESP_LOGI(TAG, "Starting %s %s", PROGNAME, PROGVERSION);
|
ESP_LOGI(TAG, "Starting %s %s", PROGNAME, PROGVERSION);
|
||||||
rgb_set_color(COLOR_NONE);
|
rgb_set_color(COLOR_NONE);
|
||||||
|
|
||||||
// system event handler for wifi task, needed for wifi_sniffer_init()
|
// initialize system event handler for wifi task, needed for wifi_sniffer_init()
|
||||||
esp_event_loop_init(NULL, NULL);
|
esp_event_loop_init(NULL, NULL);
|
||||||
|
|
||||||
// Print chip information on startup
|
// print chip information on startup if in verbose mode
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
esp_chip_info_t chip_info;
|
esp_chip_info_t chip_info;
|
||||||
esp_chip_info(&chip_info);
|
esp_chip_info(&chip_info);
|
||||||
@ -445,16 +445,16 @@ void setup() {
|
|||||||
ESP_LOGI(TAG, "ESP32 SDK: %s", ESP.getSdkVersion());
|
ESP_LOGI(TAG, "ESP32 SDK: %s", ESP.getSdkVersion());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Read settings from NVRAM
|
// read settings from NVRAM
|
||||||
loadConfig(); // includes initialize if necessary
|
loadConfig(); // includes initialize if necessary
|
||||||
|
|
||||||
// initialize hardware
|
// initialize led if needed
|
||||||
#ifdef HAS_LED
|
#ifdef HAS_LED
|
||||||
// initialize LED
|
|
||||||
pinMode(HAS_LED, OUTPUT);
|
pinMode(HAS_LED, OUTPUT);
|
||||||
digitalWrite(HAS_LED, LOW);
|
digitalWrite(HAS_LED, LOW);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// initialize button handling if needed
|
||||||
#ifdef HAS_BUTTON
|
#ifdef HAS_BUTTON
|
||||||
#ifdef BUTTON_PULLUP
|
#ifdef BUTTON_PULLUP
|
||||||
// install button interrupt (pullup mode)
|
// install button interrupt (pullup mode)
|
||||||
@ -467,60 +467,58 @@ void setup() {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// initialize wifi antenna
|
// initialize wifi antenna if needed
|
||||||
#ifdef HAS_ANTENNA_SWITCH
|
#ifdef HAS_ANTENNA_SWITCH
|
||||||
antenna_init();
|
antenna_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ======================================
|
// read DEVEUI from Microchip 24AA02E64 2Kb serial eeprom if present
|
||||||
// READ Microchip 24AA02E64 EEP DEVEUI
|
#ifdef MCP_24AA02E64_I2C_ADDRESS
|
||||||
// ======================================
|
uint8_t i2c_ret;
|
||||||
#ifdef MCP_24AA02E64_I2C_ADDRESS
|
// Init this before OLED, we just need to get value then we're done with i2c bus
|
||||||
//#if 0
|
Wire.begin(OLED_SDA, OLED_SDA, 100000);
|
||||||
uint8_t i2c_ret;
|
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
|
||||||
// Init this before OLED, we just need to get value then we done
|
Wire.write(MCP_24AA02E64_MAC_ADDRESS);
|
||||||
Wire.begin(OLED_SDA, OLED_SDA, 100000);
|
i2c_ret = Wire.endTransmission();
|
||||||
|
// check if device seen on i2c bus
|
||||||
|
if (i2c_ret == 0) {
|
||||||
|
char deveui[24];
|
||||||
|
uint8_t data;
|
||||||
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
|
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
|
||||||
Wire.write(MCP_24AA02E64_MAC_ADDRESS);
|
while (Wire.available()) {
|
||||||
i2c_ret = Wire.endTransmission();
|
data = Wire.read();
|
||||||
// device seen
|
sprintf(deveui+strlen(deveui), "%02X ", data) ;
|
||||||
if (i2c_ret == 0) {
|
|
||||||
char deveui[24];
|
|
||||||
uint8_t data;
|
|
||||||
Wire.beginTransmission(MCP_24AA02E64_I2C_ADDRESS);
|
|
||||||
while (Wire.available()) {
|
|
||||||
data = Wire.read();
|
|
||||||
sprintf(deveui+strlen(deveui), "%02X ", data) ;
|
|
||||||
}
|
|
||||||
i2c_ret = Wire.endTransmission();
|
|
||||||
ESP_LOGI(TAG, "24AA02E64 found DEVEUI %s", deveui);
|
|
||||||
} else {
|
|
||||||
ESP_LOGI(TAG, "24AA02E64 not found ret=%d", i2c_ret);
|
|
||||||
}
|
}
|
||||||
#endif // MCP 24AA02E64
|
i2c_ret = Wire.endTransmission();
|
||||||
|
ESP_LOGI(TAG, "Serial EEPROM 24AA02E64 found, read DEVEUI %s", deveui);
|
||||||
// initialize salt value using esp_random() called by random() in arduino-esp32 core
|
} else {
|
||||||
salt = random(65536); // get new 16bit random for salting hashes
|
ESP_LOGI(TAG, "Serial EEPROM 24AA02E64 not found ret=%d", i2c_ret);
|
||||||
|
}
|
||||||
|
#endif // MCP 24AA02E64
|
||||||
|
|
||||||
// initialize display
|
// initialize display
|
||||||
#ifdef HAS_DISPLAY
|
#ifdef HAS_DISPLAY
|
||||||
init_display(PROGNAME, PROGVERSION);
|
init_display(PROGNAME, PROGVERSION);
|
||||||
u8x8.setPowerSave(!cfg.screenon); // set display off if disabled
|
u8x8.setPowerSave(!cfg.screenon); // set display off if disabled
|
||||||
u8x8.setCursor(0,5);
|
u8x8.setCursor(0,5);
|
||||||
u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %4i", cfg.rssilimit);
|
u8x8.printf(!cfg.rssilimit ? "RLIM: off" : "RLIM: %4i", cfg.rssilimit);
|
||||||
u8x8.drawString(0,6,"Join Wait ");
|
u8x8.drawString(0,6,"Join Wait ");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// output LoRaWAN keys to console
|
// output LoRaWAN keys to console
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
printKeys();
|
printKeys();
|
||||||
#endif // VERBOSE
|
#endif
|
||||||
|
|
||||||
os_init(); // setup LMIC
|
os_init(); // setup LMIC
|
||||||
os_setCallback(&initjob, lora_init); // setup initial job & join network
|
os_setCallback(&initjob, lora_init); // setup initial job & join network
|
||||||
wifi_sniffer_init(); // setup wifi in monitor mode and start MAC counting
|
wifi_sniffer_init(); // setup wifi in monitor mode and start MAC counting
|
||||||
|
|
||||||
|
// 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
|
||||||
|
salt = random(65536); // get new 16bit random for salting hashes
|
||||||
|
|
||||||
// Start FreeRTOS tasks
|
// Start FreeRTOS tasks
|
||||||
#if CONFIG_FREERTOS_UNICORE // run all tasks on core 0 and switch off core 1
|
#if CONFIG_FREERTOS_UNICORE // run all tasks on core 0 and switch off core 1
|
||||||
ESP_LOGI(TAG, "Starting Lora task on core 0");
|
ESP_LOGI(TAG, "Starting Lora task on core 0");
|
||||||
xTaskCreatePinnedToCore(lorawan_loop, "loratask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 0);
|
xTaskCreatePinnedToCore(lorawan_loop, "loratask", 2048, ( void * ) 1, ( 5 | portPRIVILEGE_BIT ), NULL, 0);
|
||||||
@ -534,9 +532,9 @@ void setup() {
|
|||||||
xTaskCreatePinnedToCore(wifi_sniffer_loop, "wifisniffer", 4096, ( void * ) 1, 1, NULL, 0);
|
xTaskCreatePinnedToCore(wifi_sniffer_loop, "wifisniffer", 4096, ( void * ) 1, 1, NULL, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Kickoff first sendjob, use payload "0000"
|
// Finally: kickoff first sendjob and join, then send initial payload "0000"
|
||||||
uint8_t mydata[] = "0000";
|
uint8_t mydata[] = "0000";
|
||||||
do_send(&sendjob);
|
do_send(&sendjob);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* end Aruino SETUP ------------------------------------------------------------ */
|
/* end Aruino SETUP ------------------------------------------------------------ */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// program version - note: increment version after modifications to configData_t struct!!
|
// program version - note: increment version after modifications to configData_t struct!!
|
||||||
#define PROGVERSION "1.2.88" // use max 10 chars here!
|
#define PROGVERSION "1.2.9" // use max 10 chars here!
|
||||||
#define PROGNAME "PAXCNT"
|
#define PROGNAME "PAXCNT"
|
||||||
|
|
||||||
// Verbose enables serial output
|
// Verbose enables serial output
|
||||||
|
Loading…
Reference in New Issue
Block a user