v1.3.93
This commit is contained in:
parent
3224610575
commit
de15924447
@ -40,6 +40,7 @@ lib_deps_rgbled =
|
|||||||
SmartLeds@>=1.1.3
|
SmartLeds@>=1.1.3
|
||||||
lib_deps_gps =
|
lib_deps_gps =
|
||||||
TinyGPSPlus@>=1.0.2
|
TinyGPSPlus@>=1.0.2
|
||||||
|
Time@>=1.5
|
||||||
build_flags =
|
build_flags =
|
||||||
; we need build_flag for logging, otherwise we can't use ESP_LOGx in arduino framework
|
; we need build_flag for logging, otherwise we can't use ESP_LOGx in arduino framework
|
||||||
; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <---
|
; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <---
|
||||||
|
@ -45,7 +45,7 @@ uint16_t read_voltage() {
|
|||||||
#ifdef BATT_FACTOR
|
#ifdef BATT_FACTOR
|
||||||
voltage *= BATT_FACTOR;
|
voltage *= BATT_FACTOR;
|
||||||
#endif
|
#endif
|
||||||
ESP_LOGI(TAG, "Raw: %d / Voltage: %dmV", adc_reading, voltage);
|
ESP_LOGD(TAG, "Raw: %d / Voltage: %dmV", adc_reading, voltage);
|
||||||
return voltage;
|
return voltage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include <esp32-hal-log.h>
|
#include <esp32-hal-log.h>
|
||||||
|
|
||||||
// attn: increment version after modifications to configData_t truct!
|
// attn: increment version after modifications to configData_t truct!
|
||||||
#define PROGVERSION "1.3.92" // use max 10 chars here!
|
#define PROGVERSION "1.3.93" // use max 10 chars here!
|
||||||
#define PROGNAME "PAXCNT"
|
#define PROGNAME "PAXCNT"
|
||||||
|
|
||||||
// std::set for unified array functions
|
// std::set for unified array functions
|
||||||
@ -44,6 +44,7 @@ extern uint16_t macs_total, macs_wifi, macs_ble, batt_voltage; // display values
|
|||||||
extern std::set<uint16_t> macs; // temp storage for MACs
|
extern std::set<uint16_t> macs; // temp storage for MACs
|
||||||
extern hw_timer_t *channelSwitch, *sendCycle;
|
extern hw_timer_t *channelSwitch, *sendCycle;
|
||||||
extern portMUX_TYPE timerMux;
|
extern portMUX_TYPE timerMux;
|
||||||
|
extern volatile int SendCycleTimerIRQ;
|
||||||
|
|
||||||
#ifdef HAS_GPS
|
#ifdef HAS_GPS
|
||||||
#include "gps.h"
|
#include "gps.h"
|
||||||
|
40
src/homecycle.cpp
Normal file
40
src/homecycle.cpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/* This routine is called by interrupt in regular intervals */
|
||||||
|
/* Interval can be set in paxcounter.conf (HOMECYCLE) */
|
||||||
|
|
||||||
|
// Basic config
|
||||||
|
#include "globals.h"
|
||||||
|
#include "senddata.h"
|
||||||
|
|
||||||
|
// Local logging tag
|
||||||
|
static const char TAG[] = "main";
|
||||||
|
|
||||||
|
// do all housekeeping
|
||||||
|
void doHomework() {
|
||||||
|
// read battery voltage into global variable
|
||||||
|
#ifdef HAS_BATTERY_PROBE
|
||||||
|
batt_voltage = read_voltage();
|
||||||
|
ESP_LOGI(TAG, "Measured Voltage: %dmV", batt_voltage);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// sync time & date if we have valid gps time
|
||||||
|
#ifdef HAS_GPS
|
||||||
|
if (gps.time.isValid()) {
|
||||||
|
setTime(gps.time.hour(), gps.time.minute(), gps.time.second(),
|
||||||
|
gps.date.day(), gps.date.month(), gps.date.year());
|
||||||
|
ESP_LOGI(TAG, "Time synced to %02d:%02d:%02d", hour(), minute(), second());
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(TAG, "No valid GPS time");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// check free memory
|
||||||
|
if (esp_get_minimum_free_heap_size() <= MEM_LOW) {
|
||||||
|
ESP_LOGW(TAG,
|
||||||
|
"Memory full, counter cleared (heap low water mark = %d Bytes / "
|
||||||
|
"free heap = %d bytes)",
|
||||||
|
esp_get_minimum_free_heap_size(), ESP.getFreeHeap());
|
||||||
|
senddata(COUNTERPORT); // send data before clearing counters
|
||||||
|
reset_counters(); // clear macs container and reset all counters
|
||||||
|
reset_salt(); // get new salt for salting hashes
|
||||||
|
}
|
||||||
|
}
|
6
src/homecycle.h
Normal file
6
src/homecycle.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef _HOMECYCLE_H
|
||||||
|
#define _HOMECYCLE_H
|
||||||
|
|
||||||
|
void doHomework(void);
|
||||||
|
|
||||||
|
#endif
|
92
src/main.cpp
92
src/main.cpp
@ -35,11 +35,11 @@ uint16_t macs_total = 0, macs_wifi = 0, macs_ble = 0,
|
|||||||
|
|
||||||
// hardware timer for cyclic tasks
|
// hardware timer for cyclic tasks
|
||||||
hw_timer_t *channelSwitch = NULL, *displaytimer = NULL, *sendCycle = NULL,
|
hw_timer_t *channelSwitch = NULL, *displaytimer = NULL, *sendCycle = NULL,
|
||||||
*battCycle = NULL;
|
*homeCycle = NULL;
|
||||||
|
|
||||||
// this variables will be changed in the ISR, and read in main loop
|
// this variables will be changed in the ISR, and read in main loop
|
||||||
static volatile int ButtonPressedIRQ = 0, ChannelTimerIRQ = 0,
|
volatile int ButtonPressedIRQ = 0, ChannelTimerIRQ = 0, SendCycleTimerIRQ = 0,
|
||||||
SendCycleTimerIRQ = 0, DisplayTimerIRQ = 0, BattReadIRQ = 0;
|
DisplayTimerIRQ = 0, HomeCycleIRQ = 0;
|
||||||
|
|
||||||
portMUX_TYPE timerMux =
|
portMUX_TYPE timerMux =
|
||||||
portMUX_INITIALIZER_UNLOCKED; // sync main loop and ISR when modifying IRQ
|
portMUX_INITIALIZER_UNLOCKED; // sync main loop and ISR when modifying IRQ
|
||||||
@ -113,6 +113,12 @@ void IRAM_ATTR SendCycleIRQ() {
|
|||||||
portEXIT_CRITICAL(&timerMux);
|
portEXIT_CRITICAL(&timerMux);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IRAM_ATTR homeCycleIRQ() {
|
||||||
|
portENTER_CRITICAL(&timerMux);
|
||||||
|
HomeCycleIRQ++;
|
||||||
|
portEXIT_CRITICAL(&timerMux);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAS_DISPLAY
|
#ifdef HAS_DISPLAY
|
||||||
void IRAM_ATTR DisplayIRQ() {
|
void IRAM_ATTR DisplayIRQ() {
|
||||||
portENTER_CRITICAL_ISR(&timerMux);
|
portENTER_CRITICAL_ISR(&timerMux);
|
||||||
@ -129,21 +135,14 @@ void updateDisplay() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAS_BATTERY_PROBE
|
void checkHousekeeping() {
|
||||||
void IRAM_ATTR BattCycleIRQ() {
|
if (HomeCycleIRQ) {
|
||||||
portENTER_CRITICAL(&timerMux);
|
portENTER_CRITICAL(&timerMux);
|
||||||
BattReadIRQ++;
|
HomeCycleIRQ = 0;
|
||||||
portEXIT_CRITICAL(&timerMux);
|
portEXIT_CRITICAL(&timerMux);
|
||||||
}
|
doHomework();
|
||||||
void readBattery() {
|
|
||||||
if (BattReadIRQ) {
|
|
||||||
portENTER_CRITICAL(&timerMux);
|
|
||||||
BattReadIRQ = 0;
|
|
||||||
portEXIT_CRITICAL(&timerMux);
|
|
||||||
batt_voltage = read_voltage();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAS_BUTTON
|
#ifdef HAS_BUTTON
|
||||||
void IRAM_ATTR ButtonIRQ() { ButtonPressedIRQ++; }
|
void IRAM_ATTR ButtonIRQ() { ButtonPressedIRQ++; }
|
||||||
@ -193,43 +192,6 @@ uint64_t uptime() {
|
|||||||
return (uint64_t)high32 << 32 | low32;
|
return (uint64_t)high32 << 32 | low32;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendPayload() {
|
|
||||||
|
|
||||||
if (SendCycleTimerIRQ) {
|
|
||||||
portENTER_CRITICAL(&timerMux);
|
|
||||||
SendCycleTimerIRQ = 0;
|
|
||||||
portEXIT_CRITICAL(&timerMux);
|
|
||||||
|
|
||||||
// append counter data to payload
|
|
||||||
payload.reset();
|
|
||||||
payload.addCount(macs_wifi, cfg.blescan ? macs_ble : 0);
|
|
||||||
// append GPS data, if present
|
|
||||||
|
|
||||||
#ifdef HAS_GPS
|
|
||||||
if ((cfg.gpsmode) && (gps.location.isValid())) {
|
|
||||||
gps_read();
|
|
||||||
payload.addGPS(gps_status);
|
|
||||||
}
|
|
||||||
// log NMEA status, useful for debugging GPS connection
|
|
||||||
ESP_LOGD(TAG, "GPS NMEA data: passed %d / failed: %d / with fix: %d",
|
|
||||||
gps.passedChecksum(), gps.failedChecksum(),
|
|
||||||
gps.sentencesWithFix());
|
|
||||||
// log GPS position if we have a fix
|
|
||||||
if ((cfg.gpsmode) && (gps.location.isValid())) {
|
|
||||||
gps_read();
|
|
||||||
ESP_LOGI(TAG, "lat=%.6f | lon=%.6f | %u Sats | HDOP=%.1f | Altitude=%um",
|
|
||||||
gps_status.latitude / (float)1e6,
|
|
||||||
gps_status.longitude / (float)1e6, gps_status.satellites,
|
|
||||||
gps_status.hdop / (float)100, gps_status.altitude);
|
|
||||||
} else {
|
|
||||||
ESP_LOGI(TAG, "No valid GPS position or GPS disabled");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
senddata(COUNTERPORT);
|
|
||||||
}
|
|
||||||
} // sendPayload()
|
|
||||||
|
|
||||||
/* begin Aruino SETUP
|
/* begin Aruino SETUP
|
||||||
* ------------------------------------------------------------ */
|
* ------------------------------------------------------------ */
|
||||||
|
|
||||||
@ -367,13 +329,11 @@ void setup() {
|
|||||||
timerAlarmWrite(sendCycle, cfg.sendcycle * 2 * 10000, true);
|
timerAlarmWrite(sendCycle, cfg.sendcycle * 2 * 10000, true);
|
||||||
timerAlarmEnable(sendCycle);
|
timerAlarmEnable(sendCycle);
|
||||||
|
|
||||||
// setup battery read cycle trigger IRQ using esp32 hardware timer 3
|
// setup house keeping cycle trigger IRQ using esp32 hardware timer 3
|
||||||
#ifdef HAS_BATTERY_PROBE
|
homeCycle = timerBegin(3, 8000, true);
|
||||||
battCycle = timerBegin(3, 8000, true);
|
timerAttachInterrupt(homeCycle, &homeCycleIRQ, true);
|
||||||
timerAttachInterrupt(battCycle, &BattCycleIRQ, true);
|
timerAlarmWrite(homeCycle, HOMECYCLE * 10000, true);
|
||||||
timerAlarmWrite(battCycle, BATTREADCYCLE * 10000, true);
|
timerAlarmEnable(homeCycle);
|
||||||
timerAlarmEnable(battCycle);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// show payload encoder
|
// show payload encoder
|
||||||
#if PAYLOAD_ENCODER == 1
|
#if PAYLOAD_ENCODER == 1
|
||||||
@ -464,24 +424,12 @@ void loop() {
|
|||||||
readButton();
|
readButton();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAS_BATTERY_PROBE
|
|
||||||
readBattery();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAS_DISPLAY
|
#ifdef HAS_DISPLAY
|
||||||
updateDisplay();
|
updateDisplay();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// check free memory
|
// check housekeeping cycle and to homework if expired
|
||||||
if (esp_get_minimum_free_heap_size() <= MEM_LOW) {
|
checkHousekeeping();
|
||||||
ESP_LOGI(TAG,
|
|
||||||
"Memory full, counter cleared (heap low water mark = %d Bytes / "
|
|
||||||
"free heap = %d bytes)",
|
|
||||||
esp_get_minimum_free_heap_size(), ESP.getFreeHeap());
|
|
||||||
senddata(COUNTERPORT); // send data before clearing counters
|
|
||||||
reset_counters(); // clear macs container and reset all counters
|
|
||||||
reset_salt(); // get new salt for salting hashes
|
|
||||||
}
|
|
||||||
|
|
||||||
// check send cycle and send payload if cycle is expired
|
// check send cycle and send payload if cycle is expired
|
||||||
sendPayload();
|
sendPayload();
|
||||||
|
@ -5,10 +5,13 @@
|
|||||||
#include "macsniff.h"
|
#include "macsniff.h"
|
||||||
#include "configmanager.h"
|
#include "configmanager.h"
|
||||||
#include "senddata.h"
|
#include "senddata.h"
|
||||||
|
#include "homecycle.h"
|
||||||
|
|
||||||
#include <esp_spi_flash.h> // needed for reading ESP32 chip attributes
|
#include <esp_spi_flash.h> // needed for reading ESP32 chip attributes
|
||||||
#include <esp_event_loop.h> // needed for Wifi event handler
|
#include <esp_event_loop.h> // needed for Wifi event handler
|
||||||
|
|
||||||
|
#include <TimeLib.h>
|
||||||
|
|
||||||
void reset_counters(void);
|
void reset_counters(void);
|
||||||
void blink_LED(uint16_t set_color, uint16_t set_blinkduration);
|
void blink_LED(uint16_t set_color, uint16_t set_blinkduration);
|
||||||
void led_loop(void);
|
void led_loop(void);
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
#define VERBOSE 1 // comment out to silence the device, for mute use build option
|
#define VERBOSE 1 // comment out to silence the device, for mute use build option
|
||||||
|
|
||||||
// Payload send cycle and encoding
|
// Payload send cycle and encoding
|
||||||
#define SEND_SECS 30 // payload send cycle [seconds/2] -> 240 sec.
|
#define SEND_SECS 30 // payload send cycle [seconds/2] -> 60 sec.
|
||||||
#define PAYLOAD_ENCODER 3 // payload encoder: 1=Plain, 2=Packed, 3=CayenneLPP dynamic, 4=CayenneLPP packed
|
#define PAYLOAD_ENCODER 1 // payload encoder: 1=Plain, 2=Packed, 3=CayenneLPP dynamic, 4=CayenneLPP packed
|
||||||
|
|
||||||
// Set this to include BLE counting and vendor filter functions
|
// Set this to include BLE counting and vendor filter functions
|
||||||
#define VENDORFILTER 1 // comment out if you want to count things, not people
|
#define VENDORFILTER 1 // comment out if you want to count things, not people
|
||||||
@ -40,9 +40,6 @@
|
|||||||
#define WIFI_CHANNEL_SWITCH_INTERVAL 50 // [seconds/100] -> 0,5 sec.
|
#define WIFI_CHANNEL_SWITCH_INTERVAL 50 // [seconds/100] -> 0,5 sec.
|
||||||
|
|
||||||
// LoRa payload default parameters
|
// LoRa payload default parameters
|
||||||
#define PAYLOAD_ENCODER 1 // select payload encoder: 1=Plain [default], 2=Packed, 3=CayenneLPP dynmic, 4=CayenneLPP packed
|
|
||||||
#define SEND_SECS 30 // payload send cycle [seconds/2] -> 60 sec.
|
|
||||||
|
|
||||||
#define MEM_LOW 2048 // [Bytes] low memory threshold triggering a send cycle
|
#define MEM_LOW 2048 // [Bytes] low memory threshold triggering a send cycle
|
||||||
#define RETRANSMIT_RCMD 5 // [seconds] wait time before retransmitting rcommand results
|
#define RETRANSMIT_RCMD 5 // [seconds] wait time before retransmitting rcommand results
|
||||||
#define PAYLOAD_BUFFER_SIZE 51 // maximum size of payload block per transmit
|
#define PAYLOAD_BUFFER_SIZE 51 // maximum size of payload block per transmit
|
||||||
@ -62,7 +59,7 @@
|
|||||||
// Some hardware settings
|
// Some hardware settings
|
||||||
#define RGBLUMINOSITY 30 // RGB LED luminosity [default = 30%]
|
#define RGBLUMINOSITY 30 // RGB LED luminosity [default = 30%]
|
||||||
#define DISPLAYREFRESH_MS 40 // OLED refresh cycle in ms [default = 40] -> 1000/40 = 25 frames per second
|
#define DISPLAYREFRESH_MS 40 // OLED refresh cycle in ms [default = 40] -> 1000/40 = 25 frames per second
|
||||||
#define BATTREADCYCLE 60 // battery measuring cycle in seconds [default = 60 secs]
|
#define HOMECYCLE 60 // house keeping cycle in seconds [default = 60 secs]
|
||||||
|
|
||||||
// LMIC settings
|
// LMIC settings
|
||||||
// define hardware independent LMIC settings here, settings of standard library in /lmic/config.h will be ignored
|
// define hardware independent LMIC settings here, settings of standard library in /lmic/config.h will be ignored
|
||||||
|
@ -32,3 +32,37 @@ void senddata(uint8_t port) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // senddata
|
} // senddata
|
||||||
|
|
||||||
|
void sendPayload() {
|
||||||
|
|
||||||
|
if (SendCycleTimerIRQ) {
|
||||||
|
portENTER_CRITICAL(&timerMux);
|
||||||
|
SendCycleTimerIRQ = 0;
|
||||||
|
portEXIT_CRITICAL(&timerMux);
|
||||||
|
|
||||||
|
// append counter data to payload
|
||||||
|
payload.reset();
|
||||||
|
payload.addCount(macs_wifi, cfg.blescan ? macs_ble : 0);
|
||||||
|
// append GPS data, if present
|
||||||
|
|
||||||
|
#ifdef HAS_GPS
|
||||||
|
// show NMEA data in debug mode, useful for debugging GPS on board
|
||||||
|
// connection
|
||||||
|
ESP_LOGD(TAG, "GPS NMEA data: passed %d / failed: %d / with fix: %d",
|
||||||
|
gps.passedChecksum(), gps.failedChecksum(),
|
||||||
|
gps.sentencesWithFix());
|
||||||
|
// log GPS position if we have a fix and gps data mode is enabled
|
||||||
|
if ((cfg.gpsmode) && (gps.location.isValid())) {
|
||||||
|
gps_read();
|
||||||
|
payload.addGPS(gps_status);
|
||||||
|
ESP_LOGD(TAG, "lat=%.6f | lon=%.6f | %u Sats | HDOP=%.1f | Altitude=%um",
|
||||||
|
gps_status.latitude / (float)1e6,
|
||||||
|
gps_status.longitude / (float)1e6, gps_status.satellites,
|
||||||
|
gps_status.hdop / (float)100, gps_status.altitude);
|
||||||
|
} else {
|
||||||
|
ESP_LOGD(TAG, "No valid GPS position or GPS data mode disabled");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
senddata(COUNTERPORT);
|
||||||
|
}
|
||||||
|
} // sendpayload();
|
@ -2,5 +2,6 @@
|
|||||||
#define _SENDDATA_H
|
#define _SENDDATA_H
|
||||||
|
|
||||||
void senddata(uint8_t port);
|
void senddata(uint8_t port);
|
||||||
|
void sendPayload(void);
|
||||||
|
|
||||||
#endif // _SENDDATA_H_
|
#endif // _SENDDATA_H_
|
Loading…
Reference in New Issue
Block a user