Merge pull request #670 from cyberman54/master

sync dev to master
This commit is contained in:
Verkehrsrot 2020-11-02 18:48:13 +01:00 committed by GitHub
commit 70a37322b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 80 additions and 94 deletions

View File

@ -4,6 +4,10 @@
#include "cyclic.h"
#include "qrcode.h"
#if (COUNT_ENS)
#include "corona.h"
#endif
#if (HAS_DISPLAY) == 1
#include <OneBitDisplay.h>
#elif (HAS_DISPLAY) == 2

View File

@ -60,6 +60,11 @@
; \
}
// emulate millis to avoid rollovers
#define _millis() esp_timer_get_time() / 1000
#define _micros() esp_timer_get_time()
#define _seconds() _millis() / 1000.0
enum sendprio_t { prio_low, prio_normal, prio_high };
enum timesource_t { _gps, _rtc, _lora, _unsynced };

View File

@ -10,6 +10,10 @@
#include "cyclic.h"
#include "led.h"
#if (COUNT_ENS)
#include "corona.h"
#endif
#define MAC_SNIFF_WIFI 0
#define MAC_SNIFF_BLE 1
#define MAC_SNIFF_BLE_CWA 2

View File

@ -8,7 +8,10 @@
#include "lorawan.h"
#include "display.h"
#include "sdcard.h"
#if (COUNT_ENS)
#include "corona.h"
#endif
extern Ticker sendTimer;

View File

@ -1,6 +1,8 @@
#ifndef _SENSOR_H
#define _SENSOR_H
#define HAS_SENSORS (HAS_SENSOR_1 || HAS_SENSOR_2 || HAS_SENSOR_3)
uint8_t sensor_mask(uint8_t sensor_no);
uint8_t *sensor_read(uint8_t sensor);
void sensor_init(void);

View File

@ -228,7 +228,7 @@ void updateState(void) {
} else {
/* Update every STATE_SAVE_PERIOD minutes */
if ((stateUpdateCounter * STATE_SAVE_PERIOD) < millis()) {
if ((stateUpdateCounter * STATE_SAVE_PERIOD) < _millis()) {
update = true;
stateUpdateCounter++;
}

View File

@ -49,7 +49,7 @@ bool cwa_init(void) {
}
void cwa_mac_add(uint16_t hashedmac) {
cwaSeenNotifiers[hashedmac] = millis(); // hash last seen at ....
cwaSeenNotifiers[hashedmac] = _millis(); // hash last seen at ....
}
#endif

View File

@ -33,7 +33,10 @@ void doHousekeeping() {
}
}
// task storage debugging //
// heap and task storage debugging
ESP_LOGD(TAG, "Heap: Free:%d, Min:%d, Size:%d, Alloc:%d, StackHWM:%d",
ESP.getFreeHeap(), ESP.getMinFreeHeap(), ESP.getHeapSize(),
ESP.getMaxAllocHeap(), uxTaskGetStackHighWaterMark(NULL));
ESP_LOGD(TAG, "IRQhandler %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(irqHandlerTask),
eTaskGetState(irqHandlerTask));
@ -130,15 +133,7 @@ void doHousekeeping() {
} // doHousekeeping()
// uptime counter 64bit to prevent millis() rollover after 49 days
uint64_t uptime() {
static uint32_t low32, high32;
uint32_t new_low32 = millis();
if (new_low32 < low32)
high32++;
low32 = new_low32;
return (uint64_t)high32 << 32 | low32;
}
uint64_t uptime() { return _millis(); }
uint32_t getFreeRAM() {
#ifndef BOARD_HAS_PSRAM

View File

@ -94,7 +94,7 @@ void dp_init(bool verbose) {
#if (HAS_DISPLAY) == 1 // i2c
// block i2c bus access
if (!I2C_MUTEX_LOCK())
ESP_LOGV(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0);
ESP_LOGV(TAG, "[%0.3f] i2c mutex lock failed", _seconds());
else {
#endif
@ -190,7 +190,7 @@ void dp_refresh(bool nextPage) {
// block i2c bus access
if (!I2C_MUTEX_LOCK())
ESP_LOGV(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0);
ESP_LOGV(TAG, "[%0.3f] i2c mutex lock failed", _seconds());
else {
// set display on/off according to current device configuration
if (DisplayIsOn != cfg.screenon) {
@ -265,11 +265,13 @@ void dp_drawPage(time_t t, bool nextpage) {
else
dp_printf("WIFI:off");
if (cfg.blescan)
if (!cfg.enscount)
dp_printf("BLTH:%-5d", macs_ble);
else
#if (COUNT_ENS)
if (cfg.enscount)
dp_printf(" CWA:%-5d", cwa_report());
else
#endif
dp_printf("BLTH:%-5d", macs_ble);
else
dp_printf(" BLTH:off");
#elif ((WIFICOUNTER) && (!BLECOUNTER))
if (cfg.wifiscan)
@ -277,11 +279,13 @@ void dp_drawPage(time_t t, bool nextpage) {
else
dp_printf("WIFI:off");
#elif ((!WIFICOUNTER) && (BLECOUNTER))
if (cfg.blescan) {
if (cfg.blescan)
dp_printf("BLTH:%-5d", macs_ble);
#if (COUNT_ENS)
if (cfg.enscount)
dp_printf("(CWA:%d)", cwa_report());
} else
else
#endif
dp_printf("BLTH:off");
#else
dp_printf("Sniffer disabled");
@ -596,7 +600,7 @@ void dp_shutdown(void) {
#if (HAS_DISPLAY) == 1
// block i2c bus access
if (!I2C_MUTEX_LOCK())
ESP_LOGV(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0);
ESP_LOGV(TAG, "[%0.3f] i2c mutex lock failed", _seconds());
else {
cfg.screenon = 0;
obdPower(&ssoled, false);

View File

@ -38,7 +38,7 @@
#define RTC_INT GPIO_NUM_0 //
// Settings for IF482 interface
#define HAS_IF482 9600, SERIAL_7E1, GPIO_NUM_3, GPIO_NUM_1 // RX, TX
//#define HAS_IF482 9600, SERIAL_7E1, GPIO_NUM_3, GPIO_NUM_1 // RX, TX
// Settings for DCF77 interface
//#define HAS_DCF77 GPIO_NUM_14 // JP8 #13

View File

@ -55,8 +55,10 @@
#define SDS_TX 19 // connect to RX on the SDS011
#define SDS_RX 23 // connect to TX on the SDS011
// user defined sensors
#define HAS_SENSORS 1 // comment out if device has user defined sensors
// up to three user defined sensors (if connected)
//#define HAS_SENSOR_1 1 // comment out if device has user defined sensor #1
//#define HAS_SENSOR_2 1 // comment out if device has user defined sensor #2
//#define HAS_SENSOR_3 1 // comment out if device has user defined sensor #3
#define CFG_sx1276_radio 1 // select LoRa chip
//#define CFG_sx1272_radio 1 // select LoRa chip

View File

@ -31,18 +31,18 @@
#define HAS_ANTENNA_SWITCH (21) // pin for switching wifi antenna (P12)
#define WIFI_ANTENNA 0 // 0 = internal, 1 = external
// uncomment this only if your LoPy runs on a PYTRACK BOARD
// uncomment defines in this section ONLY if your LoPy lives on a PYTRACK BOARD
//#define HAS_GPS 1
//#define GPS_I2C GPIO_NUM_25, GPIO_NUM_26 // SDA (P22), SCL (P21)
//#define GPS_ADDR 0x10
// uncomment this only if your LoPy runs on a EXPANSION BOARD
#define HAS_LED (12) // use if LoPy is on Expansion Board, this has a user LED
#define LED_ACTIVE_LOW 1 // use if LoPy is on Expansion Board, this has a user LED
#define HAS_BUTTON (13) // user button on expansion board
#define BUTTON_PULLUP 1 // Button need pullup instead of default pulldown
#define BAT_MEASURE_ADC ADC1_GPIO39_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7
#define BAT_VOLTAGE_DIVIDER 2 // voltage divider 1MOhm/1MOhm -> expansion board 3.0
// uncomment defines in this section ONLY if your LoPy lives on a EXPANSION BOARD
//#define HAS_LED (12) // use if LoPy is on Expansion Board, this has a user LED
//#define LED_ACTIVE_LOW 1 // use if LoPy is on Expansion Board, this has a user LED
//#define HAS_BUTTON (13) // user button on expansion board
//#define BUTTON_PULLUP 1 // Button need pullup instead of default pulldown
//#define BAT_MEASURE_ADC ADC1_GPIO39_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7
//#define BAT_VOLTAGE_DIVIDER 2 // voltage divider 1MOhm/1MOhm -> expansion board 3.0
//#define BAT_VOLTAGE_DIVIDER 4 // voltage divider 115kOhm/56kOhm -> expansion board 2.0
#endif

View File

@ -25,9 +25,6 @@
#define SDCARD_MISO MISO
#define SDCARD_SCLK SCK
// user defined sensors
//#define HAS_SENSORS 1 // comment out if device has user defined sensors
#define CFG_sx1276_radio 1 // select LoRa chip
#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature

View File

@ -28,9 +28,6 @@
#define SDCARD_MISO MISO
#define SDCARD_SCLK SCK
// user defined sensors
//#define HAS_SENSORS 1 // comment out if device has user defined sensors
#define CFG_sx1276_radio 1 // select LoRa chip
#define BOARD_HAS_PSRAM // use if board has external PSRAM
#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature

View File

@ -20,9 +20,6 @@
#define HAS_BME680 GPIO_NUM_23, GPIO_NUM_22 // SDA, SCL
#define BME680_ADDR BME680_I2C_ADDR_PRIMARY // connect SDIO of BME680 to GND
// user defined sensors
//#define HAS_SENSORS 1 // comment out if device has user defined sensors
#define HAS_LED 13 // ESP32 GPIO12 (pin22) On Board LED
//#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
//#define HAS_RGB_LED SmartLed rgb_led(LED_WS2812, 1, GPIO_NUM_13) // ESP32 GPIO13 (pin13) On Board Shield WS2812B RGB LED

View File

@ -39,9 +39,6 @@
#define MY_DISPLAY_RST NOT_A_PIN
//#define MY_DISPLAY_FLIP 1 // use if display is rotated
// user defined sensors (if connected)
//#define HAS_SENSORS 1 // comment out if device has user defined sensors
//#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
#endif

View File

@ -52,9 +52,6 @@ Reset -> reset device
//#define HAS_BME680 SDA, SCL
//#define BME680_ADDR BME680_I2C_ADDR_PRIMARY // !! connect SDIO of BME680 to GND !!
// user defined sensors (if connected)
//#define HAS_SENSORS 1 // comment out if device has user defined sensors
//#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
#endif

View File

@ -109,7 +109,7 @@ uint8_t i2c_readBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len) {
I2C_MUTEX_UNLOCK(); // release i2c bus access
return ret;
} else {
ESP_LOGW(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0);
ESP_LOGW(TAG, "[%0.3f] i2c mutex lock failed", _seconds());
return 0xFF;
}
}
@ -128,7 +128,7 @@ uint8_t i2c_writeBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len) {
I2C_MUTEX_UNLOCK(); // release i2c bus access
return ret ? ret : 0xFF;
} else {
ESP_LOGW(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0);
ESP_LOGW(TAG, "[%0.3f] i2c mutex lock failed", _seconds());
return 0xFF;
}
}

View File

@ -9,7 +9,7 @@ led_states previousLEDState =
TaskHandle_t ledLoopTask;
uint16_t LEDColor = COLOR_NONE, LEDBlinkDuration = 0; // state machine variables
unsigned long LEDBlinkStarted = 0; // When (in millis() led blink started)
unsigned long LEDBlinkStarted = 0; // When (in _millis() led blink started)
#ifdef HAS_RGB_LED
@ -133,7 +133,7 @@ void blink_LED(uint16_t set_color, uint16_t set_blinkduration) {
#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
LEDColor = set_color; // set color for RGB LED
LEDBlinkDuration = set_blinkduration; // duration
LEDBlinkStarted = millis(); // Time Start here
LEDBlinkStarted = _millis(); // Time Start here
LEDState = LED_ON; // Let main set LED on
#endif
}
@ -145,8 +145,8 @@ void ledLoop(void *parameter) {
// Custom blink running always have priority other LoRaWAN led
// management
if (LEDBlinkStarted && LEDBlinkDuration) {
// Custom blink is finished, let this order, avoid millis() overflow
if ((millis() - LEDBlinkStarted) >= LEDBlinkDuration) {
// Custom blink is finished, let this order, avoid _millis() overflow
if ((_millis() - LEDBlinkStarted) >= LEDBlinkDuration) {
// Led becomes off, and stop blink
LEDState = LED_OFF;
LEDBlinkStarted = 0;
@ -165,7 +165,7 @@ void ledLoop(void *parameter) {
LEDColor = COLOR_YELLOW;
// quick blink 20ms on each 1/5 second
LEDState =
((millis() % 200) < 20) ? LED_ON : LED_OFF; // TX data pending
((_millis() % 200) < 20) ? LED_ON : LED_OFF; // TX data pending
} else if (LMIC.opmode & (OP_TXDATA | OP_TXRXPEND)) {
// select color to blink by message port
switch (LMIC.pendTxPort) {
@ -180,13 +180,13 @@ void ledLoop(void *parameter) {
break;
}
// small blink 10ms on each 1/2sec (not when joining)
LEDState = ((millis() % 500) < 10) ? LED_ON : LED_OFF;
LEDState = ((_millis() % 500) < 10) ? LED_ON : LED_OFF;
// This should not happen so indicate a problem
} else if (LMIC.opmode &
((OP_TXDATA | OP_TXRXPEND | OP_JOINING | OP_REJOIN) == 0)) {
LEDColor = COLOR_RED;
// heartbeat long blink 200ms on each 2 seconds
LEDState = ((millis() % 2000) < 200) ? LED_ON : LED_OFF;
LEDState = ((_millis() % 2000) < 200) ? LED_ON : LED_OFF;
} else
#endif // HAS_LORA
{

View File

@ -540,23 +540,6 @@ void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg,
} // switch
}
/*
// event EV_TXCOMPLETE message handler
void myTxCallback(void *pUserData, int fSuccess) {
uint8_t *const pMsg = (uint8_t *)pUserData;
// LMIC did successful transmit data
if (fSuccess) {
RTCseqnoUp = LMIC.seqnoUp;
RTCseqnoDn = LMIC.seqnoDn;
} else {
// LMIC could not transmit data
// -> error handling yet to come
}
}
*/
const char *getSfName(rps_t rps) {
const char *const t[] = {"FSK", "SF7", "SF8", "SF9",
"SF10", "SF11", "SF12", "SF?"};

View File

@ -124,7 +124,7 @@ void mqtt_client_task(void *param) {
if (mqttClient.connected()) {
char buffer[PAYLOAD_BUFFER_SIZE + 3];
snprintf(buffer, msg.MessageSize + 3, "%s/%u", msg.MessagePort,
snprintf(buffer, msg.MessageSize + 3, "%u/%s", msg.MessagePort,
msg.Message);
if (mqttClient.publish(MQTT_OUTTOPIC, buffer)) {
@ -174,7 +174,7 @@ void mqtt_enqueuedata(MessageBuffer_t *message) {
void mqtt_callback(MQTTClient *client, char topic[], char payload[],
int length) {
if (topic == MQTT_INTOPIC)
if (strcmp(topic, MQTT_INTOPIC) == 0)
rcommand((const uint8_t *)payload, (const uint8_t)length);
}

View File

@ -178,9 +178,9 @@ int do_ota_update() {
client.print("Cache-Control: no-cache\r\n");
client.print("Connection: close\r\n\r\n");
unsigned long timeout = millis();
unsigned long timeout = _millis();
while (client.available() == 0) {
if ((millis() - timeout) > (RESPONSE_TIMEOUT_MS)) {
if ((_millis() - timeout) > (RESPONSE_TIMEOUT_MS)) {
ESP_LOGI(TAG, "Client timeout");
ota_display(3, " E", "client timeout");
goto abort;

View File

@ -6,7 +6,6 @@
#include "payload.h"
#include "corona.h"
#include "macsniff.h"
extern PayloadConvert payload;
#endif

View File

@ -26,7 +26,7 @@ Ticker timesyncer;
void setTimeSyncIRQ() { xTaskNotify(irqHandlerTask, TIMESYNC_IRQ, eSetBits); }
void calibrateTime(void) {
ESP_LOGD(TAG, "[%0.3f] calibrateTime, timeSource == %d", millis() / 1000.0,
ESP_LOGD(TAG, "[%0.3f] calibrateTime, timeSource == %d", _millis() / 1000.0,
timeSource);
time_t t = 0;
uint16_t t_msec = 0;
@ -85,7 +85,7 @@ void IRAM_ATTR setMyTime(uint32_t t_sec, uint16_t t_msec,
vTaskDelay(pdMS_TO_TICKS(1000 - t_msec % 1000));
}
ESP_LOGI(TAG, "[%0.3f] UTC time: %d.%03d sec", millis() / 1000.0,
ESP_LOGI(TAG, "[%0.3f] UTC time: %d.%03d sec", _seconds(),
time_to_set, t_msec % 1000);
// if we have got an external timesource, set RTC time and shift RTC_INT pulse
@ -106,11 +106,11 @@ void IRAM_ATTR setMyTime(uint32_t t_sec, uint16_t t_msec,
timeSource = mytimesource; // set global variable
timesyncer.attach(TIME_SYNC_INTERVAL * 60, setTimeSyncIRQ);
ESP_LOGD(TAG, "[%0.3f] Timesync finished, time was set | source: %c",
millis() / 1000.0, timeSetSymbols[mytimesource]);
_seconds(), timeSetSymbols[mytimesource]);
} else {
timesyncer.attach(TIME_SYNC_INTERVAL_RETRY * 60, setTimeSyncIRQ);
ESP_LOGD(TAG, "[%0.3f] Timesync failed, invalid time fetched | source: %c",
millis() / 1000.0, timeSetSymbols[mytimesource]);
_seconds(), timeSetSymbols[mytimesource]);
}
}

View File

@ -47,7 +47,7 @@ void timesync_request(void) {
// start timesync handshake
else {
ESP_LOGI(TAG, "[%0.3f] Timeserver sync request started, seqNo#%d",
millis() / 1000.0, time_sync_seqNo);
_seconds(), time_sync_seqNo);
xTaskNotifyGive(timeSyncProcTask); // unblock timesync task
}
}
@ -98,14 +98,14 @@ void IRAM_ATTR timesync_processReq(void *taskparameter) {
if (xTaskNotifyWait(0x00, ULONG_MAX, &rcv_seqNo,
pdMS_TO_TICKS(TIME_SYNC_TIMEOUT * 1000)) == pdFALSE) {
ESP_LOGW(TAG, "[d%0.3f] Timesync aborted: timed out",
millis() / 1000.0);
_seconds());
goto Fail; // no timestamp received before timeout
}
// check if we are in handshake with server
if (rcv_seqNo != time_sync_seqNo) {
ESP_LOGW(TAG, "[%0.3f] Timesync aborted: handshake out of sync",
millis() / 1000.0);
_seconds());
goto Fail;
}
@ -166,7 +166,7 @@ void IRAM_ATTR timesync_processReq(void *taskparameter) {
// store incoming timestamps
void timesync_store(uint32_t timestamp, timesync_t timestamp_type) {
ESP_LOGD(TAG, "[%0.3f] seq#%d[%d]: t%d=%d", millis() / 1000.0,
ESP_LOGD(TAG, "[%0.3f] seq#%d[%d]: t%d=%d", _seconds(),
time_sync_seqNo, sample_idx, timestamp_type, timestamp);
timesync_timestamp[sample_idx][timestamp_type] = timestamp;
}
@ -214,10 +214,10 @@ void IRAM_ATTR timesync_serverAnswer(void *pUserData, int flag) {
if (flag != TIME_SYNC_FRAME_LENGTH) {
if (rcv_seqNo == TIME_SYNC_END_FLAG)
ESP_LOGI(TAG, "[%0.3f] Timeserver error: no confident time available",
millis() / 1000.0);
_seconds());
else
ESP_LOGW(TAG, "[%0.3f] Timeserver error: spurious data received",
millis() / 1000.0);
_seconds());
goto Exit; // failure
}
@ -233,13 +233,13 @@ void IRAM_ATTR timesync_serverAnswer(void *pUserData, int flag) {
if (flag != 1) {
ESP_LOGW(TAG, "[%0.3f] Network did not answer time request",
millis() / 1000.0);
_seconds());
goto Exit;
}
// Populate lmic_time_reference
if ((LMIC_getNetworkTimeReference(&lmicTime)) != 1) {
ESP_LOGW(TAG, "[%0.3f] Network time request failed", millis() / 1000.0);
ESP_LOGW(TAG, "[%0.3f] Network time request failed", _seconds());
goto Exit;
}
@ -267,7 +267,7 @@ Finish:
rc = 1;
} else {
ESP_LOGW(TAG, "[%0.3f] Timeserver error: outdated time received",
millis() / 1000.0);
_seconds());
}
Exit: