Merge pull request #120 from cyberman54/development

v1.3.93
This commit is contained in:
Verkehrsrot 2018-07-22 20:30:39 +02:00 committed by GitHub
commit 031a88887e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 112 additions and 81 deletions

View File

@ -40,6 +40,7 @@ lib_deps_rgbled =
SmartLeds@>=1.1.3
lib_deps_gps =
TinyGPSPlus@>=1.0.2
Time@>=1.5
build_flags =
; 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! <---

View File

@ -45,7 +45,7 @@ uint16_t read_voltage() {
#ifdef BATT_FACTOR
voltage *= BATT_FACTOR;
#endif
ESP_LOGI(TAG, "Raw: %d / Voltage: %dmV", adc_reading, voltage);
ESP_LOGD(TAG, "Raw: %d / Voltage: %dmV", adc_reading, voltage);
return voltage;
}

View File

@ -8,7 +8,7 @@
#include <esp32-hal-log.h>
// 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"
// 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 hw_timer_t *channelSwitch, *sendCycle;
extern portMUX_TYPE timerMux;
extern volatile int SendCycleTimerIRQ;
#ifdef HAS_GPS
#include "gps.h"

40
src/homecycle.cpp Normal file
View 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
View File

@ -0,0 +1,6 @@
#ifndef _HOMECYCLE_H
#define _HOMECYCLE_H
void doHomework(void);
#endif

View File

@ -35,11 +35,11 @@ uint16_t macs_total = 0, macs_wifi = 0, macs_ble = 0,
// hardware timer for cyclic tasks
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
static volatile int ButtonPressedIRQ = 0, ChannelTimerIRQ = 0,
SendCycleTimerIRQ = 0, DisplayTimerIRQ = 0, BattReadIRQ = 0;
volatile int ButtonPressedIRQ = 0, ChannelTimerIRQ = 0, SendCycleTimerIRQ = 0,
DisplayTimerIRQ = 0, HomeCycleIRQ = 0;
portMUX_TYPE timerMux =
portMUX_INITIALIZER_UNLOCKED; // sync main loop and ISR when modifying IRQ
@ -113,6 +113,12 @@ void IRAM_ATTR SendCycleIRQ() {
portEXIT_CRITICAL(&timerMux);
}
void IRAM_ATTR homeCycleIRQ() {
portENTER_CRITICAL(&timerMux);
HomeCycleIRQ++;
portEXIT_CRITICAL(&timerMux);
}
#ifdef HAS_DISPLAY
void IRAM_ATTR DisplayIRQ() {
portENTER_CRITICAL_ISR(&timerMux);
@ -129,21 +135,14 @@ void updateDisplay() {
}
#endif
#ifdef HAS_BATTERY_PROBE
void IRAM_ATTR BattCycleIRQ() {
void checkHousekeeping() {
if (HomeCycleIRQ) {
portENTER_CRITICAL(&timerMux);
BattReadIRQ++;
HomeCycleIRQ = 0;
portEXIT_CRITICAL(&timerMux);
}
void readBattery() {
if (BattReadIRQ) {
portENTER_CRITICAL(&timerMux);
BattReadIRQ = 0;
portEXIT_CRITICAL(&timerMux);
batt_voltage = read_voltage();
doHomework();
}
}
#endif
#ifdef HAS_BUTTON
void IRAM_ATTR ButtonIRQ() { ButtonPressedIRQ++; }
@ -193,43 +192,6 @@ uint64_t uptime() {
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
* ------------------------------------------------------------ */
@ -367,13 +329,11 @@ void setup() {
timerAlarmWrite(sendCycle, cfg.sendcycle * 2 * 10000, true);
timerAlarmEnable(sendCycle);
// setup battery read cycle trigger IRQ using esp32 hardware timer 3
#ifdef HAS_BATTERY_PROBE
battCycle = timerBegin(3, 8000, true);
timerAttachInterrupt(battCycle, &BattCycleIRQ, true);
timerAlarmWrite(battCycle, BATTREADCYCLE * 10000, true);
timerAlarmEnable(battCycle);
#endif
// setup house keeping cycle trigger IRQ using esp32 hardware timer 3
homeCycle = timerBegin(3, 8000, true);
timerAttachInterrupt(homeCycle, &homeCycleIRQ, true);
timerAlarmWrite(homeCycle, HOMECYCLE * 10000, true);
timerAlarmEnable(homeCycle);
// show payload encoder
#if PAYLOAD_ENCODER == 1
@ -464,24 +424,12 @@ void loop() {
readButton();
#endif
#ifdef HAS_BATTERY_PROBE
readBattery();
#endif
#ifdef HAS_DISPLAY
updateDisplay();
#endif
// check free memory
if (esp_get_minimum_free_heap_size() <= MEM_LOW) {
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 housekeeping cycle and to homework if expired
checkHousekeeping();
// check send cycle and send payload if cycle is expired
sendPayload();

View File

@ -5,10 +5,13 @@
#include "macsniff.h"
#include "configmanager.h"
#include "senddata.h"
#include "homecycle.h"
#include <esp_spi_flash.h> // needed for reading ESP32 chip attributes
#include <esp_event_loop.h> // needed for Wifi event handler
#include <TimeLib.h>
void reset_counters(void);
void blink_LED(uint16_t set_color, uint16_t set_blinkduration);
void led_loop(void);

View File

@ -8,8 +8,8 @@
#define VERBOSE 1 // comment out to silence the device, for mute use build option
// Payload send cycle and encoding
#define SEND_SECS 30 // payload send cycle [seconds/2] -> 240 sec.
#define PAYLOAD_ENCODER 3 // payload encoder: 1=Plain, 2=Packed, 3=CayenneLPP dynamic, 4=CayenneLPP packed
#define SEND_SECS 30 // payload send cycle [seconds/2] -> 60 sec.
#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
#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.
// 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 RETRANSMIT_RCMD 5 // [seconds] wait time before retransmitting rcommand results
#define PAYLOAD_BUFFER_SIZE 51 // maximum size of payload block per transmit
@ -62,7 +59,7 @@
// Some hardware settings
#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 BATTREADCYCLE 60 // battery measuring cycle in seconds [default = 60 secs]
#define HOMECYCLE 60 // house keeping cycle in seconds [default = 60 secs]
// LMIC settings
// define hardware independent LMIC settings here, settings of standard library in /lmic/config.h will be ignored

View File

@ -32,3 +32,37 @@ void senddata(uint8_t port) {
}
} // 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();

View File

@ -2,5 +2,6 @@
#define _SENDDATA_H
void senddata(uint8_t port);
void sendPayload(void);
#endif // _SENDDATA_H_