Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TTGOv1 support added (experimental, not yet tested) #3

Merged
merged 4 commits into from
Mar 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Paxcounter
Wifi & Bluetooth driven, LoRaWAN enabled, battery powered mini ESP32 Paxcounter
built on cheap ESP32 boards
**Wifi & Bluetooth driven, LoRaWAN enabled, battery powered mini ESP32 Paxcounter
built on cheap ESP32 boards**

<img src="img/foto_no_exif.jpg">

# Hardware

Currently supported IoT boards:
- Heltec LoRa-32
- TTGOv1
- TTGOv2
- Pycom LoPy
- Pycom LoPy4
Expand Down Expand Up @@ -152,6 +153,10 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts.
0x81 get device uptime

bytes 1-7: Uptime in seconds (little endian format)

0x82 get device cpu temperature

bytes 1-3: chip temperature in celsius (little endian format)

# License

Expand Down
30 changes: 26 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
; http://docs.platformio.org/page/projectconf.html

[platformio]
env_default = heltec_wifi_lora_32
;env_default = ttgo
;env_default = heltec_wifi_lora_32
env_default = ttgov2
;env_default = ttgov1
;env_default = lopy
;env_default = lopy4

Expand All @@ -34,7 +35,7 @@ build_flags =
;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp)
; -DCONFIG_FREERTOS_UNICORE

[env:ttgo]
[env:ttgov1]
platform = espressif32
board = esp32dev
framework = arduino
Expand All @@ -50,7 +51,28 @@ 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/ttgo.h"
-include "src/hal/ttgov1.h"
;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp)
; -DCONFIG_FREERTOS_UNICORE


[env:ttgov2]
platform = espressif32
board = esp32dev
framework = arduino
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
;needed for ESP32 BLE Ardunio v0.4.9
-fexceptions
-std=c++11
;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/ttgov2.h"
;FreeRTOS single core operation, switches off core 1 (see arduino-esp32/cores/esp32/main.cpp)
; -DCONFIG_FREERTOS_UNICORE

Expand Down
4 changes: 2 additions & 2 deletions src/hal/heltec.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#define HELTEC
#define HAS_DISPLAY // has OLED-Display
#define HAS_LED // has on usable board LED
#define HAS_BUTTON // has onboard button
#define HAS_LED // has usable on board LED
#define HAS_BUTTON // has usable on board button
#define CFG_sx1276_radio 1

// re-define pin definitions of pins_arduino.h
Expand Down
22 changes: 22 additions & 0 deletions src/hal/ttgov1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Hardware related definitions for Heltec TTGOv1 board

#define TTGO
#define HAS_DISPLAY // has OLED-Display
#define CFG_sx1276_radio 1

// 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

// non arduino pin definitions
#define RST 14 // ESP32 GPIO14 (Pin14) -- SX1276 NRESET (Pin7) Reset Trigger Input
#define DIO0 26 // ESP32 GPIO26 (Pin15) -- SX1276 DIO0 (Pin8) used by LMIC for detecting LoRa RX_Done & TX_Done
#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
#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
96 changes: 48 additions & 48 deletions src/hal/ttgo.h → src/hal/ttgov2.h
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
// Hardware related definitions for TTGO V2 Board

#define TTGO
#define HAS_DISPLAY // has OLED-Display
#define CFG_sx1276_radio 1

// 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

// 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)

// 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


/*
ESP32 LoRa module (SPI) OLED display (I2C)
--------- ----------------- ------------------
5 SCK SCK
27 MOSI MOSI
19 MISO MISO
18 SS NSS
14 RST
26 DIO0
33 DIO1 (see note {1})
32 DIO2 (see note {2})
22 SCL SCL
21 SDA SDA
22 LED (useless, see note {3})
{1} Must be manually wired!
DIO1 is wired to a separate pin but is not wired on-board to pin/GPIO33.
Explicitly wire board pin labeled DIO1 to pin 33 (see TTGO V2.0 pinout).
{2} Must be manually wired!
DIO2 is wired to a separate pin but is not wired on-board to pin/GPIO32.
Explicitly wire board pin labeled DIO2 to pin 32 (see TTGO V2.0 pinout).
{3} The on-board LED is wired to SCL (used by display) therefore totally useless!
*/
// Hardware related definitions for TTGO V2 Board

#define TTGO
#define HAS_DISPLAY // has OLED-Display
#define CFG_sx1276_radio 1

// 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

// 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)

// 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


/*
ESP32 LoRa module (SPI) OLED display (I2C)
--------- ----------------- ------------------
5 SCK SCK
27 MOSI MOSI
19 MISO MISO
18 SS NSS
14 RST
26 DIO0
33 DIO1 (see note {1})
32 DIO2 (see note {2})
22 SCL SCL
21 SDA SDA
22 LED (useless, see note {3})
{1} Must be manually wired!
DIO1 is wired to a separate pin but is not wired on-board to pin/GPIO33.
Explicitly wire board pin labeled DIO1 to pin 33 (see TTGO V2.0 pinout).
{2} Must be manually wired!
DIO2 is wired to a separate pin but is not wired on-board to pin/GPIO32.
Explicitly wire board pin labeled DIO2 to pin 32 (see TTGO V2.0 pinout).
{3} The on-board LED is wired to SCL (used by display) therefore totally useless!
*/

6 changes: 5 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,11 @@ 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);
esp_event_loop_init(NULL, NULL); // not sure if necessary -> to be checked
*/

// Print chip information on startup
#ifdef VERBOSE
Expand All @@ -339,6 +342,7 @@ void setup() {
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "",
chip_info.revision, spi_flash_get_chip_size() / (1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
ESP_LOGI(TAG, "ESP32 SDK: %s", ESP.getSdkVersion());
#endif // VERBOSE

// Read settings from NVRAM
Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// program version
#define PROGVERSION "1.2.0" // use max 10 chars here!
#define PROGVERSION "1.2.22" // use max 10 chars here!
#define PROGNAME "PAXCNT"

// Verbose enables serial output
Expand Down
16 changes: 14 additions & 2 deletions src/rcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void get_config (int val) {
memcpy(sendData, &cfg, size);
LMIC_setTxData2(RCMDPORT, sendData, size-1, 0); // send data unconfirmed on RCMD Port
delete sendData; // free memory
ESP_LOGI(TAG, "Configuration data queued in send queue");
ESP_LOGI(TAG, "%i bytes queued in send queue", size-1);
};

void get_uptime (int val) {
Expand All @@ -175,7 +175,18 @@ void get_uptime (int val) {
memcpy(sendData, (unsigned char*)&uptimecounter, size);
LMIC_setTxData2(RCMDPORT, sendData, size-1, 0); // send data unconfirmed on RCMD Port
delete sendData; // free memory
ESP_LOGI(TAG, "Uptime queued in send queue");
ESP_LOGI(TAG, "%i bytes queued in send queue", size-1);
};

void get_cputemp (int val) {
ESP_LOGI(TAG, "Remote command: get cpu temperature");
float temp = temperatureRead();
int size = sizeof(temp);
unsigned char *sendData = new unsigned char[size];
memcpy(sendData, (unsigned char*)&temp, size);
LMIC_setTxData2(RCMDPORT, sendData, size-1, 0); // send data unconfirmed on RCMD Port
delete sendData; // free memory
ESP_LOGI(TAG, "%i bytes queued in send queue", size-1);
};

// assign previously defined functions to set of numeric remote commands
Expand All @@ -197,6 +208,7 @@ cmd_t table[] = {
{0x0d, set_blescan, true},
{0x80, get_config, false},
{0x81, get_uptime, false},
{0x82, get_cputemp, false}
};

// check and execute remote command
Expand Down
13 changes: 7 additions & 6 deletions src/wifisniffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ typedef struct {

void wifi_sniffer_init(void) {
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
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_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
cfg.nvs_enable = 0; // we don't want wifi settings from NVRAM
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_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
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));
Expand Down