Merge pull request #4 from cyberman54/TTGOv1-test

v1.2.3
This commit is contained in:
Verkehrsrot 2018-03-21 18:07:06 +01:00 committed by GitHub
commit c84600022f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 119 additions and 147 deletions

View File

@ -8,10 +8,11 @@
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html
; ---> SELECT TARGET PLATFORM HERE! <---
[platformio]
;env_default = heltec_wifi_lora_32
env_default = ttgov2
env_default = heltec_wifi_lora_32
;env_default = ttgov1
;env_default = ttgov2
;env_default = lopy
;env_default = lopy4
@ -23,8 +24,8 @@ monitor_baud = 115200
lib_deps = U8g2
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
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
;needed for ESP32 BLE Ardunio v0.4.9
-fexceptions
-std=c++11
@ -43,8 +44,8 @@ monitor_baud = 115200
lib_deps = U8g2
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
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
;needed for ESP32 BLE Ardunio v0.4.9
-fexceptions
-std=c++11
@ -64,8 +65,8 @@ monitor_baud = 115200
lib_deps = U8g2
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
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
;needed for ESP32 BLE Ardunio v0.4.9
-fexceptions
-std=c++11
@ -92,7 +93,6 @@ build_flags =
;override lora settings from LMiC library in lmic/config.h and use main.h instead
-D_lmic_config_h_
-include "src/main.h"
-include "src/hal/antenna.h"
-include "src/hal/lopy.h"
;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp)
; -DCONFIG_FREERTOS_UNICORE
@ -113,7 +113,6 @@ build_flags =
;override lora settings from LMiC library in lmic/config.h and use main.h instead
-D_lmic_config_h_
-include "src/main.h"
-include "src/hal/antenna.h"
-include "src/hal/lopy4.h"
;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp)
; -DCONFIG_FREERTOS_UNICORE

View File

@ -1,15 +1,10 @@
// Log Level magic
#include "main.h"
// not using this seems to break U8X8LIB
#include <Arduino.h>
// Local logging tag
static const char *TAG = "blecount";
//#include <Arduino.h>
// Basic Config
#include "main.h"
#include "globals.h"
#include "loraconf.h"
//#include "loraconf.h"
#ifdef BLECOUNTER
#include <BLEDevice.h>
@ -17,6 +12,9 @@ static const char *TAG = "blecount";
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
// Local logging tag
static const char *TAG = "blecount";
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
}

View File

@ -1,5 +1,6 @@
/* configmanager persists runtime configuration using NVRAM of ESP32*/
#include "main.h"
#include "globals.h"
#include <nvs.h>
#include <nvs_flash.h>

View File

@ -1,16 +0,0 @@
/* struct holding devices's runtime configuration */
typedef struct {
int8_t lorasf; // 7-12, lora spreadfactor
int8_t txpower; // 2-15, lora tx power
int8_t adrmode; // 0=disabled, 1=enabled
int8_t screensaver; // 0=disabled, 1=enabled
int8_t screenon; // 0=disabled, 1=enabled
int8_t countermode; // 0=cyclic unconfirmed, 1=cumulative, 2=cyclic confirmed
int16_t rssilimit; // threshold for rssilimiter, negative value!
int8_t wifiscancycle; // wifi scan cycle [seconds/2]
int8_t wifichancycle; // wifi channel switch cycle [seconds/100]
int8_t blescancycle; // BLE scan cycle [seconds]
int8_t blescan; // 0=disabled, 1=enabled
char version[10]; // Firmware version
} configData_t;

View File

@ -1,14 +1,6 @@
// First things first
#include "main.h"
// The mother of all embedded development...
#include <Arduino.h>
// we neededthis to ESP_LOGx on arduino framework
#include "esp32-hal-log.h"
#include <String.h>
// std::set for unified array functions
#include <set>
@ -19,21 +11,36 @@
#include <lmic.h>
#include <hal/hal.h>
// configData_t
#include "configmanager.h"
// Struct holding devices's runtime configuration
extern uint8_t mydata[];
extern uint64_t uptimecounter;
extern int macnum, blenum, countermode, screensaver, adrmode, lorasf, txpower, rlim;
extern bool joinstate;
extern osjob_t sendjob;
extern std::set<uint64_t, std::greater <uint64_t> > macs;
extern U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8;
typedef struct {
int8_t lorasf; // 7-12, lora spreadfactor
int8_t txpower; // 2-15, lora tx power
int8_t adrmode; // 0=disabled, 1=enabled
int8_t screensaver; // 0=disabled, 1=enabled
int8_t screenon; // 0=disabled, 1=enabled
int8_t countermode; // 0=cyclic unconfirmed, 1=cumulative, 2=cyclic confirmed
int16_t rssilimit; // threshold for rssilimiter, negative value!
int8_t wifiscancycle; // wifi scan cycle [seconds/2]
int8_t wifichancycle; // wifi channel switch cycle [seconds/100]
int8_t blescancycle; // BLE scan cycle [seconds]
int8_t blescan; // 0=disabled, 1=enabled
char version[10]; // Firmware version
} configData_t;
extern configData_t cfg;
extern uint8_t mydata[];
extern uint64_t uptimecounter;
extern osjob_t sendjob;
extern int macnum, blenum, countermode, screensaver, adrmode, lorasf, txpower, rlim;
extern bool joinstate;
extern std::set<uint64_t, std::greater <uint64_t> > macs;
#ifdef HAS_DISPLAY
extern HAS_DISPLAY u8x8;
#else
extern U8X8_NULL u8x8;
#endif
#ifdef BLECOUNTER
extern int scanTime;

View File

@ -1,21 +0,0 @@
/*
* Copyright (c) 2016, Pycom Limited.
*
* This software is licensed under the GNU GPL version 3 or any
* later version, with permitted additional terms. For more information
* see the Pycom Licence v1.0 document supplied with this file, or
* available at https://www.pycom.io/opensource/licensing
*/
#ifndef _ANTENNA_H_
#define _ANTENNA_H_
typedef enum {
ANTENNA_TYPE_INTERNAL = 0,
ANTENNA_TYPE_EXTERNAL
} antenna_type_t;
extern void antenna_init (void);
extern void antenna_select (antenna_type_t antenna_type);
#endif /* _ANTENNA_H_ */

View File

@ -1,9 +1,8 @@
// Hardware related definitions for Heltec LoRa-32 Board
#define HELTEC
#define HAS_DISPLAY // has OLED-Display
#define HAS_LED // has usable on board LED
#define HAS_BUTTON // has usable on board button
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
#define HAS_LED GPIO_NUM_25 // white LED on board
#define HAS_BUTTON GPIO_NUM_0 // button "PROG" on board
#define CFG_sx1276_radio 1
// re-define pin definitions of pins_arduino.h
@ -19,6 +18,6 @@
#define DIO2 32 // ESP32 GPIO32 (Pin12) -- SX1276 DIO2 (Pin10) not used by LMIC for LoRa (Timeout for FSK only)
// Hardware pin definitions for Heltec LoRa-32 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_RST 16 // ESP32 GPIO16 (Pin16) -- SD1306 RST
#define OLED_SDA 4 // ESP32 GPIO4 (Pin4) -- SD1306 D1+D2
#define OLED_SCL 15 // ESP32 GPIO15 (Pin15) -- SD1306 D0

View File

@ -16,3 +16,11 @@
// select WIFI antenna (internal = onboard / external = u.fl socket)
#define PIN_ANTENNA_SWITCH 16
#define WIFI_LOPY_ANTENNA ANTENNA_TYPE_INTERNAL
typedef enum {
ANTENNA_TYPE_INTERNAL = 0,
ANTENNA_TYPE_EXTERNAL
} antenna_type_t;
extern void antenna_init (void);
extern void antenna_select (antenna_type_t antenna_type);

View File

@ -16,3 +16,11 @@
// select WIFI antenna (internal = onboard / external = u.fl socket)
#define PIN_ANTENNA_SWITCH 21
#define WIFI_LOPY_ANTENNA ANTENNA_TYPE_INTERNAL
typedef enum {
ANTENNA_TYPE_INTERNAL = 0,
ANTENNA_TYPE_EXTERNAL
} antenna_type_t;
extern void antenna_init (void);
extern void antenna_select (antenna_type_t antenna_type);

View File

@ -1,7 +1,6 @@
// Hardware related definitions for Heltec TTGOv1 board
#define TTGO
#define HAS_DISPLAY // has OLED-Display
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C
#define CFG_sx1276_radio 1
// re-define pin definitions of pins_arduino.h
@ -16,7 +15,7 @@
#define DIO1 33 // ESP32 GPIO33 (Pin13) -- SX1276 DIO1 (Pin9) used by LMIC for detecting LoRa RX_Timeout
#define DIO2 32 // ESP32 GPIO32 (Pin12) -- SX1276 DIO2 (Pin10) not used by LMIC for LoRa (Timeout for FSK only)
// Hardware pin definitions for Heltec LoRa-32 Board with OLED SSD1306 I2C Display
// 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

View File

@ -1,7 +1,6 @@
// Hardware related definitions for TTGO V2 Board
#define TTGO
#define HAS_DISPLAY // has OLED-Display
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C
#define CFG_sx1276_radio 1
// re-define pin definitions of pins_arduino.h

View File

@ -1,12 +1,9 @@
// Basic Config
#include "main.h"
// #include <Arduino.h>
#include "globals.h"
#include "loraconf.h"
// LMIC-Arduino LoRaWAN Stack
#include "loraconf.h"
#include <lmic.h>
#include <hal/hal.h>

View File

@ -1,27 +1,29 @@
/*
*
* Oliver Brandmueller <ob@sysadm.in> 2017/2018
* Klaus Wilting <verkehrsrot@arcor.de> 2018
*
* some lines of code taken from:
*
* Copyright (c) 2017, Łukasz Marcin Podkalicki <lpodkalicki@gmail.com>
* ESP32/016 WiFi Sniffer.
* https://github.com/lpodkalicki/blog/tree/master/esp32/016_wifi_sniffer
*
* Arduino-LMIC Library
* TTN OTAA Example
* https://github.com/matthijskooijman/arduino-lmic/blob/master/examples/ttn-otaa/
*
* nkolban esp32 snippets
* BLE Scan
* https://github.com/nkolban/esp32-snippets/tree/master/cpp_utils/tests/BLETests/Arduino/BLE_scan
*
* parts of code in lorawan.cpp has been grabbed from RadioHead Library
Copyright 2018 Oliver Brandmueller <ob@sysadm.in>
Copyright 2018 Klaus Wilting <verkehrsrot@arcor.de>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
NOTICE:
Parts of the source files in this repository are made available under different licenses.
Refer to LICENSE.txt file in repository for more details.
*/
// First things first
// Basic Config
#include "main.h"
#include "globals.h"
// std::set for unified array functions
#include <set>
@ -29,20 +31,11 @@
// OLED driver
#include <U8x8lib.h>
#ifdef HAS_DISPLAY
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(OLED_RST, OLED_SCL, OLED_SDA);
#else
U8X8_NULL u8x8;
#endif
// LMIC-Arduino LoRaWAN Stack
#include "loraconf.h"
#include <lmic.h>
#include <hal/hal.h>
// Basic Config
#include "loraconf.h"
#include "configmanager.h"
// WiFi Functions
#include <esp_wifi.h>
#include <esp_wifi_types.h>
@ -50,15 +43,15 @@
#include <esp_event.h>
#include <esp_event_loop.h>
#include <esp_spi_flash.h>
#include <esp32-hal-log.h> // we need this for ESP_LOGx on arduino framework
configData_t cfg; // struct holds current device configuration
osjob_t sendjob, initjob; // LMIC
// Initialize global variables
int macnum = 0, blenum = 0;
uint32_t uptimecounter = 0;
uint64_t uptimecounter = 0;
bool joinstate = false;
extern uint8_t mydata[];
std::set<uint64_t, std::greater <uint64_t> > macs; // storage holds MAC frames
@ -67,8 +60,8 @@ static volatile bool ButtonTriggered = false;
// local Tag for logging
static const char *TAG = "paxcnt";
// Note: Log level control seems working during runtime, so we need to switch loglevel
// by compiler build option in platformio.ini
// Note: Log level control seems not working during runtime,
// so we need to switch loglevel by compiler build option in platformio.ini
#ifndef VERBOSE
int redirect_log(const char * fmt, va_list args) {
//do nothing
@ -140,6 +133,12 @@ void lorawan_loop(void * pvParameters) {
/* beginn hardware specific parts -------------------------------------------------------- */
#ifdef HAS_DISPLAY
HAS_DISPLAY u8x8(OLED_RST, OLED_SCL, OLED_SDA);
#else
U8X8_NULL u8x8;
#endif
#ifdef LOPY
// defined in antenna.cpp
void antenna_init (void);
@ -155,8 +154,8 @@ void lorawan_loop(void * pvParameters) {
void set_onboard_led(int st){
#ifdef HAS_LED
switch (st) {
case 1: digitalWrite(LED_BUILTIN, HIGH); break;
case 0: digitalWrite(LED_BUILTIN, LOW); break;
case 1: digitalWrite(HAS_LED, HIGH); break;
case 0: digitalWrite(HAS_LED, LOW); break;
}
#endif
};
@ -326,11 +325,8 @@ void setup() {
ESP_LOGI(TAG, "Starting %s %s", PROGNAME, PROGVERSION);
/*
tcpip_adapter_init(); // not sure if necessary, but seems needed for TTGOv1
// ESP Event Loop
esp_event_loop_init(NULL, NULL); // not sure if necessary -> to be checked
*/
// system event handler for wifi task, needed for wifi_sniffer_init()
esp_event_loop_init(NULL, NULL);
// Print chip information on startup
#ifdef VERBOSE
@ -348,17 +344,17 @@ void setup() {
// Read settings from NVRAM
loadConfig(); // includes initialize if necessary
// initialize hardware -> perhaps to be moved to new hal.cpp
// initialize hardware
#ifdef HAS_LED
// initialize LED
pinMode(LED_BUILTIN, OUTPUT); // white LED on Heltec board
digitalWrite(LED_BUILTIN, LOW);
pinMode(HAS_LED, OUTPUT);
digitalWrite(HAS_LED, LOW);
#endif
#ifdef HAS_BUTTON
// install button interrupt
pinMode(GPIO_NUM_0, INPUT_PULLDOWN); // button "PROG" on Heltec board
attachInterrupt(digitalPinToInterrupt(GPIO_NUM_0), isr_button_pressed, FALLING);
pinMode(HAS_BUTTON, INPUT_PULLDOWN);
attachInterrupt(digitalPinToInterrupt(HAS_BUTTON), isr_button_pressed, FALLING);
#endif
// initialize wifi antenna

View File

@ -1,5 +1,5 @@
// program version
#define PROGVERSION "1.2.22" // use max 10 chars here!
#define PROGVERSION "1.2.3" // use max 10 chars here!
#define PROGNAME "PAXCNT"
// Verbose enables serial output

View File

@ -2,6 +2,8 @@
// parses multiple number of command / value pairs from LoRaWAN remote command port (RCMDPORT)
// checks commands and executes each command with 1 argument per command
// Basic Config
#include "main.h"
#include "globals.h"
// Local logging tag

View File

@ -1,10 +1,6 @@
#include "main.h"
#include <Arduino.h>
// Basic Config
#include "main.h"
#include "globals.h"
#include "loraconf.h"
// WiFi Functions
#include <esp_wifi.h>
@ -49,7 +45,7 @@ void wifi_sniffer_init(void) {
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_wifi_set_country(&wifi_country));
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM) );
//ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL) );
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL) );
//ESP_ERROR_CHECK( esp_wifi_start() );
//ESP_ERROR_CHECK( esp_wifi_set_max_tx_power(-128) ); // we don't need to TX, so we use lowest power level to save energy
wifi_promiscuous_filter_t filter = {.filter_mask = WIFI_PROMIS_FILTER_MASK_MGMT}; // we need only MGMT frames