Skip to content

Commit

Permalink
Merge pull request #17 from cyberman54/hallard-master
Browse files Browse the repository at this point in the history
v1.2.8 - thanks to Charles Hallard for contribution!
  • Loading branch information
cyberman54 authored Apr 2, 2018
2 parents cc6d8da + 95358eb commit 2a23f66
Show file tree
Hide file tree
Showing 18 changed files with 1,942 additions and 1,658 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts.
0x07 set LoRa Adaptive Data Rate mode

0 = ADR off
1 = ADR on [default]
1 = ADR on [default]

note: set ADR to off, if device is moving, set to on, if not.

0x08 do nothing
Expand Down Expand Up @@ -165,6 +165,11 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts.
0 = internal antenna [default]
1 = external antenna

0x0F set RGB led luminosity (works on LoPy/LoPy4 and LoRaNode32 shield only)

0 ... 100 percentage of luminosity (100% = full light)
e.g. 40 -> 40% of luminosity

0x80 get device configuration

device answers with it's current configuration:
Expand All @@ -181,7 +186,8 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts.
byte 11: BLE scan cycle duration in seconds (0..255)
byte 12: BLE scan mode (1=on, 0=0ff)
byte 13: Wifi antenna switch (0=internal, 1=external)
bytes 14-23: Software version (ASCII format)
byte 14: RGB LED luminosity (0..100 %)
bytes 15-24: Software version (ASCII format)

0x81 get device uptime

Expand Down
15 changes: 7 additions & 8 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ monitor_baud = 115200
lib_deps =
U8g2@>2.21.7
ESP32 BLE Arduino@>=0.4.9
; NeoPixelBus
SmartLeds
build_flags =
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
Expand All @@ -118,8 +118,8 @@ monitor_baud = 115200
lib_deps =
U8g2@>2.21.7
ESP32 BLE Arduino@>=0.4.9
; NeoPixelBus
build_flags =
SmartLeds
build_flags =
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
Expand All @@ -142,8 +142,8 @@ upload_speed = 256000
lib_deps =
U8g2
ESP32 BLE Arduino@>=0.4.9
; NeoPixelBus
build_flags =
SmartLeds
build_flags =
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
Expand All @@ -166,8 +166,8 @@ upload_speed = 921600
lib_deps =
U8g2
ESP32 BLE Arduino@>=0.4.9
; NeoPixelBus
build_flags =
SmartLeds
build_flags =
;set log level, we need build_flag for this, otherwise we can't use ESP_LOGx in arduino framework
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
Expand All @@ -180,4 +180,3 @@ build_flags =
-include "src/hal/lolin32_lora.h"
;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp)
; -DCONFIG_FREERTOS_UNICORE

32 changes: 0 additions & 32 deletions src/blecount.cpp

This file was deleted.

45 changes: 29 additions & 16 deletions src/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ void defaultConfig() {
cfg.wifiscancycle = SEND_SECS; // wifi scan cycle [seconds/2]
cfg.wifichancycle = WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100]
cfg.blescancycle = BLESCANTIME; // BLE scan cycle [seconds]
cfg.blescan = 0; // 0=disabled, 1=enabled
cfg.blescan = 1; // 0=disabled, 1=enabled
cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4)
cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0 100%)

strncpy( cfg.version, PROGVERSION, sizeof(cfg.version)-1 );
}

Expand All @@ -47,7 +49,7 @@ void open_storage() {
// Open
ESP_LOGI(TAG, "Opening NVS");
err = nvs_open("config", NVS_READWRITE, &my_handle);
if (err != ESP_OK)
if (err != ESP_OK)
ESP_LOGI(TAG, "Error (%d) opening NVS handle", err);
else
ESP_LOGI(TAG, "Done");
Expand All @@ -56,14 +58,14 @@ void open_storage() {
// erase all keys and values in NVRAM
void eraseConfig() {
ESP_LOGI(TAG, "Clearing settings in NVS");
open_storage();
open_storage();
if (err == ESP_OK) {
nvs_erase_all(my_handle);
nvs_commit(my_handle);
nvs_close(my_handle);
ESP_LOGI(TAG, "Done");}
else {
ESP_LOGW(TAG, "NVS erase failed"); }
ESP_LOGI(TAG, "Done");}
else {
ESP_LOGW(TAG, "NVS erase failed"); }
}

// save current configuration from RAM to NVRAM
Expand All @@ -75,10 +77,10 @@ void saveConfig() {
int16_t flash16 = 0;
size_t required_size;
char storedversion[10];

if( nvs_get_str(my_handle, "version", storedversion, &required_size) != ESP_OK || 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);

Expand Down Expand Up @@ -110,11 +112,14 @@ void saveConfig() {
nvs_set_i8(my_handle, "blescanmode", cfg.blescan);

if( nvs_get_i8(my_handle, "wifiant", &flash8) != ESP_OK || flash8 != cfg.wifiant )
nvs_set_i8(my_handle, "wifiant", cfg.wifiant);
nvs_set_i8(my_handle, "wifiant", cfg.wifiant);

if( nvs_get_i8(my_handle, "rgblum", &flash8) != ESP_OK || flash8 != cfg.rgblum )
nvs_set_i8(my_handle, "rgblum", cfg.rgblum);

if( nvs_get_i16(my_handle, "rssilimit", &flash16) != ESP_OK || flash16 != cfg.rssilimit )
nvs_set_i16(my_handle, "rssilimit", cfg.rssilimit);

err = nvs_commit(my_handle);
nvs_close(my_handle);
if ( err == ESP_OK ) {
Expand Down Expand Up @@ -146,7 +151,7 @@ void loadConfig() {
int8_t flash8 = 0;
int16_t flash16 = 0;
size_t required_size;

// check if configuration stored in NVRAM matches PROGVERSION
if( nvs_get_str(my_handle, "version", NULL, &required_size) == ESP_OK ) {
nvs_get_str(my_handle, "version", cfg.version, &required_size);
Expand Down Expand Up @@ -227,7 +232,7 @@ void loadConfig() {
ESP_LOGI(TAG, "WIFI channel cycle set to default %i", cfg.wifichancycle);
saveConfig();
}

if( nvs_get_i8(my_handle, "wifiant", &flash8) == ESP_OK ) {
cfg.wifiant = flash8;
ESP_LOGI(TAG, "wifiantenna = %i", flash8);
Expand All @@ -236,6 +241,14 @@ void loadConfig() {
saveConfig();
}

if( nvs_get_i8(my_handle, "rgblum", &flash8) == ESP_OK ) {
cfg.rgblum = flash8;
ESP_LOGI(TAG, "rgbluminosity = %i", flash8);
} else {
ESP_LOGI(TAG, "RGB luminosity set to default %i", cfg.rgblum);
saveConfig();
}

if( nvs_get_i8(my_handle, "blescancycle", &flash8) == ESP_OK ) {
cfg.blescancycle = flash8;
ESP_LOGI(TAG, "blescancycle = %i", flash8);
Expand All @@ -251,15 +264,15 @@ void loadConfig() {
ESP_LOGI(TAG, "BLEscanmode set to default %i", cfg.blescan);
saveConfig();
}

if( nvs_get_i16(my_handle, "rssilimit", &flash16) == ESP_OK ) {
cfg.rssilimit = flash16;
ESP_LOGI(TAG, "rssilimit = %i", flash16);
} else {
ESP_LOGI(TAG, "rssilimit set to default %i", cfg.rssilimit);
saveConfig();
}

nvs_close(my_handle);
ESP_LOGI(TAG, "Done");

Expand All @@ -268,5 +281,5 @@ void loadConfig() {
#ifdef HAS_ANTENNA_SWITCH // set antenna type, if device has one
antenna_select(cfg.wifiant);
#endif
}
}
}
}
16 changes: 13 additions & 3 deletions src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

// std::set for unified array functions
#include <set>
#include <array>
#include <algorithm>

// OLED Display
#include <U8x8lib.h>
Expand All @@ -11,6 +13,12 @@
#include <lmic.h>
#include <hal/hal.h>

#ifdef HAS_RGB_LED
#include <SmartLeds.h>
#endif
#include "rgb_led.h"
#include "macsniff.h"

// Struct holding devices's runtime configuration
typedef struct {
int8_t lorasf; // 7-12, lora spreadfactor
Expand All @@ -25,16 +33,17 @@ typedef struct {
int8_t blescancycle; // BLE scan cycle [seconds]
int8_t blescan; // 0=disabled, 1=enabled
int8_t wifiant; // 0=internal, 1=external (for LoPy/LoPy4)
int8_t rgblum; // RGB Led luminosity (0 100%)
char version[10]; // Firmware version
} configData_t;

extern configData_t cfg;
extern uint8_t mydata[];
extern uint64_t uptimecounter;
extern osjob_t sendjob;
extern uint16_t macnum, blenum, salt;
extern int countermode, screensaver, adrmode, lorasf, txpower, rlim;
extern int countermode, screensaver, adrmode, lorasf, txpower, rlim, salt;
extern bool joinstate;
extern std::set<uint16_t> wifis;
extern std::set<uint16_t> macs;

#ifdef HAS_DISPLAY
Expand All @@ -45,4 +54,5 @@ extern std::set<uint16_t> macs;

#ifdef BLECOUNTER
extern int scanTime;
#endif
extern std::set<uint16_t> bles;
#endif
2 changes: 1 addition & 1 deletion src/hal/lolin32_lora.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
#define HAS_LED NOT_A_PIN // Led os on same pin than Lora SS pin, to avoid pb, we don't use it
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
// Anyway shield is on over the LoLin32 board, so we won't be able to see this LED
#define HAS_RGB_LED 13 // ESP32 GPIO13 (pin13) On Board Shield WS2812B RGB LED
#define HAS_BUTTON 15 // ESP32 GPIO15 (pin15) Button is on the LoraNode32 shield
Expand All @@ -30,4 +31,3 @@
#define OLED_RST U8X8_PIN_NONE // Not reset pin
#define OLED_SDA 21 // ESP32 GPIO21 (Pin21) -- OLED SDA
#define OLED_SCL 22 // ESP32 GPIO22 (Pin22) -- OLED SCL

5 changes: 2 additions & 3 deletions src/hal/lolin32lite_lora.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature

#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
#define HAS_LED NOT_A_PIN // Led os on same pin than Lora SS pin, to avoid pb, we don't use it
// Anyway shield is on over the LoLin32 board, so we won't be able to see this LED
#define HAS_LED 22 // ESP32 GPIO12 (pin22) On Board LED
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
#define HAS_RGB_LED 13 // ESP32 GPIO13 (pin13) On Board Shield WS2812B RGB LED
#define HAS_BUTTON 15 // ESP32 GPIO15 (pin15) Button is on the LoraNode32 shield
#define BUTTON_PULLUP 1 // Button need pullup instead of default pulldown
Expand All @@ -30,4 +30,3 @@
#define OLED_RST U8X8_PIN_NONE // Not reset pin
#define OLED_SDA 14 // ESP32 GPIO14 (Pin14) -- OLED SDA
#define OLED_SCL 12 // ESP32 GPIO12 (Pin12) -- OLED SCL

3 changes: 2 additions & 1 deletion src/hal/ttgov1.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
#define HAS_LED GPIO_NUM_2 // white LED on board
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
#define HAS_BUTTON GPIO_NUM_0 // button "PRG" on board

// re-define pin definitions of pins_arduino.h
Expand All @@ -21,4 +22,4 @@
// Hardware pin definitions for TTGOv1 Board with OLED SSD1306 I2C Display
#define OLED_RST 16 // ESP32 GPIO16 (Pin16) -- SD1306 Reset
#define OLED_SDA 4 // ESP32 GPIO4 (Pin4) -- SD1306 Data
#define OLED_SCL 15 // ESP32 GPIO15 (Pin15) -- SD1306 Clock
#define OLED_SCL 15 // ESP32 GPIO15 (Pin15) -- SD1306 Clock
27 changes: 19 additions & 8 deletions src/lorawan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,22 @@ void printKeys(void) {
#endif // VERBOSE

void do_send(osjob_t* j){
mydata[0] = (macnum & 0xff00) >> 8;
mydata[1] = macnum & 0x00ff;
mydata[2] = (blenum & 0xff00) >> 8;
mydata[3] = blenum & 0x00ff;
uint16_t data;
// Total BLE+WIFI unique MACs seen
data = (uint16_t) macs.size();
mydata[0] = (data & 0xff00) >> 8;
mydata[1] = data & 0xff;

// Sum of unique BLE MACs seen
data = (uint16_t) bles.size();
mydata[2] = (data & 0xff00) >> 8;
mydata[3] = data & 0xff;

// Sum of unique WIFI MACs seen
// TBD ?
//data = (uint16_t) wifis.size();
//mydata[4] = (data & 0xff00) >> 8;
//mydata[5] = data & 0xff;

// Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
Expand All @@ -95,7 +107,6 @@ void do_send(osjob_t* j){
ESP_LOGI(TAG, "Packet queued");
u8x8.clearLine(7);
u8x8.drawString(0, 7, "PACKET QUEUED");
set_onboard_led(1);
}
// Next TX is scheduled after TX_COMPLETE event.
}
Expand Down Expand Up @@ -162,7 +173,6 @@ void onEvent (ev_t ev) {
ESP_LOGI(TAG, "EV_TXCOMPLETE (includes waiting for RX windows)");
u8x8.clearLine(7);
u8x8.drawString(0, 7, "TX COMPLETE");
set_onboard_led(0);
if (LMIC.txrxFlags & TXRX_ACK) {
ESP_LOGI(TAG, "Received ack");
u8x8.clearLine(7);
Expand All @@ -176,7 +186,7 @@ void onEvent (ev_t ev) {
u8x8.clearLine(7);
u8x8.setCursor(0, 7);
// LMIC.snr = SNR twos compliment [dB] * 4
// LMIC.rssi = RSSI [dBm] (-196...+63)
// LMIC.rssi = RSSI [dBm] (-196...+63)
u8x8.printf("RSSI %d SNR %d", LMIC.rssi, (signed char)LMIC.snr / 4);
// check if payload received on command port, then call remote command interpreter
if ( (LMIC.txrxFlags & TXRX_PORT) && (LMIC.frame[LMIC.dataBeg-1] == RCMDPORT ) ) {
Expand Down Expand Up @@ -223,4 +233,5 @@ void onEvent (ev_t ev) {
u8x8.printf("UNKNOWN EVENT %d", ev);
break;
}
}
}

Loading

0 comments on commit 2a23f66

Please sign in to comment.