From ce5dadeffefedfc513298f60cfecd4e03ea4ca5b Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Wed, 21 Mar 2018 21:53:42 +0100 Subject: [PATCH] code sanitization; button on TTGOv1 --- src/blecount.cpp | 4 ---- src/hal/ttgov1.h | 6 ++++-- src/hal/ttgov2.h | 24 ++++++++++++------------ src/lorawan.cpp | 1 - src/main.cpp | 12 ++++-------- src/main.h | 2 +- src/wifisniffer.cpp | 30 +++++++++++++----------------- 7 files changed, 34 insertions(+), 45 deletions(-) diff --git a/src/blecount.cpp b/src/blecount.cpp index 6ee2fc00..b2cd6c92 100644 --- a/src/blecount.cpp +++ b/src/blecount.cpp @@ -1,10 +1,6 @@ -// not using this seems to break U8X8LIB -//#include // Basic Config -#include "main.h" #include "globals.h" -//#include "loraconf.h" #ifdef BLECOUNTER #include diff --git a/src/hal/ttgov1.h b/src/hal/ttgov1.h index b80e4f2d..99f0adc4 100644 --- a/src/hal/ttgov1.h +++ b/src/hal/ttgov1.h @@ -1,6 +1,8 @@ -// Hardware related definitions for Heltec TTGOv1 board +// Hardware related definitions for TTGOv1 board -#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C +#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board +#define HAS_LED GPIO_NUM_2 // white LED on board +#define HAS_BUTTON GPIO_NUM_0 // button "PRG" on board #define CFG_sx1276_radio 1 // re-define pin definitions of pins_arduino.h diff --git a/src/hal/ttgov2.h b/src/hal/ttgov2.h index b815520b..d22dd5d4 100644 --- a/src/hal/ttgov2.h +++ b/src/hal/ttgov2.h @@ -1,24 +1,24 @@ // Hardware related definitions for TTGO V2 Board #define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C -#define CFG_sx1276_radio 1 +#define CFG_sx1276_radio 1 // HPD13A LoRa SoC // re-define pin definitions of pins_arduino.h -#define PIN_SPI_SS 18 // ESP32 GPIO18 (Pin18) -- SX1276 NSS (Pin19) SPI Chip Select Input -#define PIN_SPI_MOSI 27 // ESP32 GPIO27 (Pin27) -- SX1276 MOSI (Pin18) SPI Data Input -#define PIN_SPI_MISO 19 // ESP32 GPIO19 (Pin19) -- SX1276 MISO (Pin17) SPI Data Output -#define PIN_SPI_SCK 5 // ESP32 GPIO5 (Pin5) -- SX1276 SCK (Pin16) SPI Clock Input +#define PIN_SPI_SS 18 // ESP32 GPIO18 (Pin18) -- HPD13A NSS/SEL (Pin4) SPI Chip Select Input +#define PIN_SPI_MOSI 27 // ESP32 GPIO27 (Pin27) -- HPD13A MOSI/DSI (Pin6) SPI Data Input +#define PIN_SPI_MISO 19 // ESP32 GPIO19 (Pin19) -- HPD13A MISO/DSO (Pin7) SPI Data Output +#define PIN_SPI_SCK 5 // ESP32 GPIO5 (Pin5) -- HPD13A SCK (Pin5) SPI Clock Input // non arduino pin definitions -#define RST LMIC_UNUSED_PIN // not sure -#define DIO0 26 // wired on PCB -#define DIO1 33 // needs to be wired external -#define DIO2 32 // needs to be wired external (but not necessary for LoRa) +#define RST LMIC_UNUSED_PIN // connected to ESP32 RST/EN +#define DIO0 26 // ESP32 GPIO26 wired on PCB to HPD13A +#define DIO1 33 // HPDIO1 on pcb, needs to be wired external to GPIO33 +#define DIO2 32 // HPDIO2 on pcb, needs to be wired external to GPIO32 (not necessary for LoRa, only FSK) // Hardware pin definitions for TTGO V2 Board with OLED SSD1306 0,96" I2C Display -#define OLED_RST U8X8_PIN_NONE // to be checked if really not connected -#define OLED_SDA 21 // ESP32 GPIO4 (Pin4) -- SD1306 Data -#define OLED_SCL 22 // ESP32 GPIO15 (Pin15) -- SD1306 Clock +#define OLED_RST U8X8_PIN_NONE // connected to CPU RST/EN +#define OLED_SDA 21 // ESP32 GPIO4 (Pin4) -- SD1306 D1+D2 +#define OLED_SCL 22 // ESP32 GPIO15 (Pin15) -- SD1306 D0 /* diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 389aa89d..b47d6ea3 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -7,7 +7,6 @@ #include #include -// needs to be defined here uint8_t mydata[] = "0000"; // Local logging Tag diff --git a/src/main.cpp b/src/main.cpp index ca669f4d..c1cf2128 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,14 +36,10 @@ Refer to LICENSE.txt file in repository for more details. #include #include -// WiFi Functions -#include -#include -#include -#include -#include -#include -#include // we need this for ESP_LOGx on arduino framework +// ESP32 Functions +#include // needed for Wifi event handler +#include // needed for reading ESP32 chip attributes +#include // needed for ESP_LOGx on arduino framework configData_t cfg; // struct holds current device configuration osjob_t sendjob, initjob; // LMIC diff --git a/src/main.h b/src/main.h index e93b5603..84392654 100644 --- a/src/main.h +++ b/src/main.h @@ -1,5 +1,5 @@ // program version -#define PROGVERSION "1.2.3" // use max 10 chars here! +#define PROGVERSION "1.2.31" // use max 10 chars here! #define PROGNAME "PAXCNT" // Verbose enables serial output diff --git a/src/wifisniffer.cpp b/src/wifisniffer.cpp index 6c388d80..f2ee2d17 100644 --- a/src/wifisniffer.cpp +++ b/src/wifisniffer.cpp @@ -2,28 +2,20 @@ #include "main.h" #include "globals.h" -// WiFi Functions +// ESP32 Functions #include -#include -#include -#include -#include + +#ifdef VENDORFILTER + #include + #include + #include "vendor_array.h" +#endif // Local logging tag static const char *TAG = "wifisniffer"; static wifi_country_t wifi_country = {.cc="EU", .schan=1, .nchan=13, .policy=WIFI_COUNTRY_POLICY_AUTO}; -#ifdef VENDORFILTER -#include -#include -#include "vendor_array.h" -#endif - -extern void wifi_sniffer_init(void); -extern void wifi_sniffer_set_channel(uint8_t channel); -extern void wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type); - typedef struct { unsigned frame_ctrl:16; unsigned duration_id:16; @@ -39,6 +31,10 @@ typedef struct { uint8_t payload[0]; /* network data ended with 4 bytes csum (CRC32) */ } wifi_ieee80211_packet_t; +extern void wifi_sniffer_init(void); +extern void wifi_sniffer_set_channel(uint8_t channel); +extern void wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type); + void wifi_sniffer_init(void) { wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); cfg.nvs_enable = 0; // we don't want wifi settings from NVRAM @@ -46,8 +42,8 @@ void wifi_sniffer_init(void) { 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_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 + //ESP_ERROR_CHECK(esp_wifi_start()); // not sure if we need this in this application? + //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 ESP_ERROR_CHECK(esp_wifi_set_promiscuous_filter(&filter)); // set MAC frame filter ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler));