commit
70a37322b5
@ -4,6 +4,10 @@
|
|||||||
#include "cyclic.h"
|
#include "cyclic.h"
|
||||||
#include "qrcode.h"
|
#include "qrcode.h"
|
||||||
|
|
||||||
|
#if (COUNT_ENS)
|
||||||
|
#include "corona.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if (HAS_DISPLAY) == 1
|
#if (HAS_DISPLAY) == 1
|
||||||
#include <OneBitDisplay.h>
|
#include <OneBitDisplay.h>
|
||||||
#elif (HAS_DISPLAY) == 2
|
#elif (HAS_DISPLAY) == 2
|
||||||
|
@ -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 sendprio_t { prio_low, prio_normal, prio_high };
|
||||||
enum timesource_t { _gps, _rtc, _lora, _unsynced };
|
enum timesource_t { _gps, _rtc, _lora, _unsynced };
|
||||||
|
|
||||||
|
@ -10,6 +10,10 @@
|
|||||||
#include "cyclic.h"
|
#include "cyclic.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
|
|
||||||
|
#if (COUNT_ENS)
|
||||||
|
#include "corona.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MAC_SNIFF_WIFI 0
|
#define MAC_SNIFF_WIFI 0
|
||||||
#define MAC_SNIFF_BLE 1
|
#define MAC_SNIFF_BLE 1
|
||||||
#define MAC_SNIFF_BLE_CWA 2
|
#define MAC_SNIFF_BLE_CWA 2
|
||||||
|
@ -8,7 +8,10 @@
|
|||||||
#include "lorawan.h"
|
#include "lorawan.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "sdcard.h"
|
#include "sdcard.h"
|
||||||
|
|
||||||
|
#if (COUNT_ENS)
|
||||||
#include "corona.h"
|
#include "corona.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
extern Ticker sendTimer;
|
extern Ticker sendTimer;
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
#ifndef _SENSOR_H
|
#ifndef _SENSOR_H
|
||||||
#define _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_mask(uint8_t sensor_no);
|
||||||
uint8_t * sensor_read(uint8_t sensor);
|
uint8_t *sensor_read(uint8_t sensor);
|
||||||
void sensor_init(void);
|
void sensor_init(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -228,7 +228,7 @@ void updateState(void) {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* Update every STATE_SAVE_PERIOD minutes */
|
/* Update every STATE_SAVE_PERIOD minutes */
|
||||||
if ((stateUpdateCounter * STATE_SAVE_PERIOD) < millis()) {
|
if ((stateUpdateCounter * STATE_SAVE_PERIOD) < _millis()) {
|
||||||
update = true;
|
update = true;
|
||||||
stateUpdateCounter++;
|
stateUpdateCounter++;
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ bool cwa_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cwa_mac_add(uint16_t hashedmac) {
|
void cwa_mac_add(uint16_t hashedmac) {
|
||||||
cwaSeenNotifiers[hashedmac] = millis(); // hash last seen at ....
|
cwaSeenNotifiers[hashedmac] = _millis(); // hash last seen at ....
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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",
|
ESP_LOGD(TAG, "IRQhandler %d bytes left | Taskstate = %d",
|
||||||
uxTaskGetStackHighWaterMark(irqHandlerTask),
|
uxTaskGetStackHighWaterMark(irqHandlerTask),
|
||||||
eTaskGetState(irqHandlerTask));
|
eTaskGetState(irqHandlerTask));
|
||||||
@ -130,15 +133,7 @@ void doHousekeeping() {
|
|||||||
|
|
||||||
} // doHousekeeping()
|
} // doHousekeeping()
|
||||||
|
|
||||||
// uptime counter 64bit to prevent millis() rollover after 49 days
|
uint64_t uptime() { return _millis(); }
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t getFreeRAM() {
|
uint32_t getFreeRAM() {
|
||||||
#ifndef BOARD_HAS_PSRAM
|
#ifndef BOARD_HAS_PSRAM
|
||||||
|
@ -67,7 +67,7 @@ void dp_setup(int contrast) {
|
|||||||
MY_DISPLAY_INVERT, USE_HW_I2C, MY_DISPLAY_SDA,
|
MY_DISPLAY_INVERT, USE_HW_I2C, MY_DISPLAY_SDA,
|
||||||
MY_DISPLAY_SCL, MY_DISPLAY_RST,
|
MY_DISPLAY_SCL, MY_DISPLAY_RST,
|
||||||
OLED_FREQUENCY); // use standard I2C bus at 400Khz
|
OLED_FREQUENCY); // use standard I2C bus at 400Khz
|
||||||
_ASSERT (rc != OLED_NOT_FOUND);
|
_ASSERT(rc != OLED_NOT_FOUND);
|
||||||
|
|
||||||
// set display buffer
|
// set display buffer
|
||||||
obdSetBackBuffer(&ssoled, displaybuf);
|
obdSetBackBuffer(&ssoled, displaybuf);
|
||||||
@ -94,7 +94,7 @@ void dp_init(bool verbose) {
|
|||||||
#if (HAS_DISPLAY) == 1 // i2c
|
#if (HAS_DISPLAY) == 1 // i2c
|
||||||
// block i2c bus access
|
// block i2c bus access
|
||||||
if (!I2C_MUTEX_LOCK())
|
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 {
|
else {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ void dp_refresh(bool nextPage) {
|
|||||||
|
|
||||||
// block i2c bus access
|
// block i2c bus access
|
||||||
if (!I2C_MUTEX_LOCK())
|
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 {
|
else {
|
||||||
// set display on/off according to current device configuration
|
// set display on/off according to current device configuration
|
||||||
if (DisplayIsOn != cfg.screenon) {
|
if (DisplayIsOn != cfg.screenon) {
|
||||||
@ -265,10 +265,12 @@ void dp_drawPage(time_t t, bool nextpage) {
|
|||||||
else
|
else
|
||||||
dp_printf("WIFI:off");
|
dp_printf("WIFI:off");
|
||||||
if (cfg.blescan)
|
if (cfg.blescan)
|
||||||
if (!cfg.enscount)
|
#if (COUNT_ENS)
|
||||||
dp_printf("BLTH:%-5d", macs_ble);
|
if (cfg.enscount)
|
||||||
else
|
|
||||||
dp_printf(" CWA:%-5d", cwa_report());
|
dp_printf(" CWA:%-5d", cwa_report());
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
dp_printf("BLTH:%-5d", macs_ble);
|
||||||
else
|
else
|
||||||
dp_printf(" BLTH:off");
|
dp_printf(" BLTH:off");
|
||||||
#elif ((WIFICOUNTER) && (!BLECOUNTER))
|
#elif ((WIFICOUNTER) && (!BLECOUNTER))
|
||||||
@ -277,11 +279,13 @@ void dp_drawPage(time_t t, bool nextpage) {
|
|||||||
else
|
else
|
||||||
dp_printf("WIFI:off");
|
dp_printf("WIFI:off");
|
||||||
#elif ((!WIFICOUNTER) && (BLECOUNTER))
|
#elif ((!WIFICOUNTER) && (BLECOUNTER))
|
||||||
if (cfg.blescan) {
|
if (cfg.blescan)
|
||||||
dp_printf("BLTH:%-5d", macs_ble);
|
dp_printf("BLTH:%-5d", macs_ble);
|
||||||
if (cfg.enscount)
|
#if (COUNT_ENS)
|
||||||
dp_printf("(CWA:%d)", cwa_report());
|
if (cfg.enscount)
|
||||||
} else
|
dp_printf("(CWA:%d)", cwa_report());
|
||||||
|
else
|
||||||
|
#endif
|
||||||
dp_printf("BLTH:off");
|
dp_printf("BLTH:off");
|
||||||
#else
|
#else
|
||||||
dp_printf("Sniffer disabled");
|
dp_printf("Sniffer disabled");
|
||||||
@ -596,7 +600,7 @@ void dp_shutdown(void) {
|
|||||||
#if (HAS_DISPLAY) == 1
|
#if (HAS_DISPLAY) == 1
|
||||||
// block i2c bus access
|
// block i2c bus access
|
||||||
if (!I2C_MUTEX_LOCK())
|
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 {
|
else {
|
||||||
cfg.screenon = 0;
|
cfg.screenon = 0;
|
||||||
obdPower(&ssoled, false);
|
obdPower(&ssoled, false);
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
#define RTC_INT GPIO_NUM_0 //
|
#define RTC_INT GPIO_NUM_0 //
|
||||||
|
|
||||||
// Settings for IF482 interface
|
// 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
|
// Settings for DCF77 interface
|
||||||
//#define HAS_DCF77 GPIO_NUM_14 // JP8 #13
|
//#define HAS_DCF77 GPIO_NUM_14 // JP8 #13
|
||||||
|
@ -55,8 +55,10 @@
|
|||||||
#define SDS_TX 19 // connect to RX on the SDS011
|
#define SDS_TX 19 // connect to RX on the SDS011
|
||||||
#define SDS_RX 23 // connect to TX on the SDS011
|
#define SDS_RX 23 // connect to TX on the SDS011
|
||||||
|
|
||||||
// user defined sensors
|
// up to three user defined sensors (if connected)
|
||||||
#define HAS_SENSORS 1 // comment out if device has user defined sensors
|
//#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_sx1276_radio 1 // select LoRa chip
|
||||||
//#define CFG_sx1272_radio 1 // select LoRa chip
|
//#define CFG_sx1272_radio 1 // select LoRa chip
|
||||||
|
@ -31,18 +31,18 @@
|
|||||||
#define HAS_ANTENNA_SWITCH (21) // pin for switching wifi antenna (P12)
|
#define HAS_ANTENNA_SWITCH (21) // pin for switching wifi antenna (P12)
|
||||||
#define WIFI_ANTENNA 0 // 0 = internal, 1 = external
|
#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 HAS_GPS 1
|
||||||
//#define GPS_I2C GPIO_NUM_25, GPIO_NUM_26 // SDA (P22), SCL (P21)
|
//#define GPS_I2C GPIO_NUM_25, GPIO_NUM_26 // SDA (P22), SCL (P21)
|
||||||
//#define GPS_ADDR 0x10
|
//#define GPS_ADDR 0x10
|
||||||
|
|
||||||
// uncomment this only if your LoPy runs on a EXPANSION BOARD
|
// 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 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 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 HAS_BUTTON (13) // user button on expansion board
|
||||||
#define BUTTON_PULLUP 1 // Button need pullup instead of default pulldown
|
//#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_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 2 // voltage divider 1MOhm/1MOhm -> expansion board 3.0
|
||||||
//#define BAT_VOLTAGE_DIVIDER 4 // voltage divider 115kOhm/56kOhm -> expansion board 2.0
|
//#define BAT_VOLTAGE_DIVIDER 4 // voltage divider 115kOhm/56kOhm -> expansion board 2.0
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -25,9 +25,6 @@
|
|||||||
#define SDCARD_MISO MISO
|
#define SDCARD_MISO MISO
|
||||||
#define SDCARD_SCLK SCK
|
#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 CFG_sx1276_radio 1 // select LoRa chip
|
||||||
#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
|
#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
|
||||||
|
|
||||||
|
@ -28,9 +28,6 @@
|
|||||||
#define SDCARD_MISO MISO
|
#define SDCARD_MISO MISO
|
||||||
#define SDCARD_SCLK SCK
|
#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 CFG_sx1276_radio 1 // select LoRa chip
|
||||||
#define BOARD_HAS_PSRAM // use if board has external PSRAM
|
#define BOARD_HAS_PSRAM // use if board has external PSRAM
|
||||||
#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
|
#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
|
||||||
|
@ -20,9 +20,6 @@
|
|||||||
#define HAS_BME680 GPIO_NUM_23, GPIO_NUM_22 // SDA, SCL
|
#define HAS_BME680 GPIO_NUM_23, GPIO_NUM_22 // SDA, SCL
|
||||||
#define BME680_ADDR BME680_I2C_ADDR_PRIMARY // connect SDIO of BME680 to GND
|
#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 HAS_LED 13 // ESP32 GPIO12 (pin22) On Board LED
|
||||||
//#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
|
//#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
|
//#define HAS_RGB_LED SmartLed rgb_led(LED_WS2812, 1, GPIO_NUM_13) // ESP32 GPIO13 (pin13) On Board Shield WS2812B RGB LED
|
||||||
|
@ -39,9 +39,6 @@
|
|||||||
#define MY_DISPLAY_RST NOT_A_PIN
|
#define MY_DISPLAY_RST NOT_A_PIN
|
||||||
//#define MY_DISPLAY_FLIP 1 // use if display is rotated
|
//#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
|
//#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -52,9 +52,6 @@ Reset -> reset device
|
|||||||
//#define HAS_BME680 SDA, SCL
|
//#define HAS_BME680 SDA, SCL
|
||||||
//#define BME680_ADDR BME680_I2C_ADDR_PRIMARY // !! connect SDIO of BME680 to GND !!
|
//#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
|
//#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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
|
I2C_MUTEX_UNLOCK(); // release i2c bus access
|
||||||
return ret;
|
return ret;
|
||||||
} else {
|
} 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;
|
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
|
I2C_MUTEX_UNLOCK(); // release i2c bus access
|
||||||
return ret ? ret : 0xFF;
|
return ret ? ret : 0xFF;
|
||||||
} else {
|
} 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;
|
return 0xFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
src/led.cpp
14
src/led.cpp
@ -9,7 +9,7 @@ led_states previousLEDState =
|
|||||||
TaskHandle_t ledLoopTask;
|
TaskHandle_t ledLoopTask;
|
||||||
|
|
||||||
uint16_t LEDColor = COLOR_NONE, LEDBlinkDuration = 0; // state machine variables
|
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
|
#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)
|
#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
|
||||||
LEDColor = set_color; // set color for RGB LED
|
LEDColor = set_color; // set color for RGB LED
|
||||||
LEDBlinkDuration = set_blinkduration; // duration
|
LEDBlinkDuration = set_blinkduration; // duration
|
||||||
LEDBlinkStarted = millis(); // Time Start here
|
LEDBlinkStarted = _millis(); // Time Start here
|
||||||
LEDState = LED_ON; // Let main set LED on
|
LEDState = LED_ON; // Let main set LED on
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -145,8 +145,8 @@ void ledLoop(void *parameter) {
|
|||||||
// Custom blink running always have priority other LoRaWAN led
|
// Custom blink running always have priority other LoRaWAN led
|
||||||
// management
|
// management
|
||||||
if (LEDBlinkStarted && LEDBlinkDuration) {
|
if (LEDBlinkStarted && LEDBlinkDuration) {
|
||||||
// Custom blink is finished, let this order, avoid millis() overflow
|
// Custom blink is finished, let this order, avoid _millis() overflow
|
||||||
if ((millis() - LEDBlinkStarted) >= LEDBlinkDuration) {
|
if ((_millis() - LEDBlinkStarted) >= LEDBlinkDuration) {
|
||||||
// Led becomes off, and stop blink
|
// Led becomes off, and stop blink
|
||||||
LEDState = LED_OFF;
|
LEDState = LED_OFF;
|
||||||
LEDBlinkStarted = 0;
|
LEDBlinkStarted = 0;
|
||||||
@ -165,7 +165,7 @@ void ledLoop(void *parameter) {
|
|||||||
LEDColor = COLOR_YELLOW;
|
LEDColor = COLOR_YELLOW;
|
||||||
// quick blink 20ms on each 1/5 second
|
// quick blink 20ms on each 1/5 second
|
||||||
LEDState =
|
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)) {
|
} else if (LMIC.opmode & (OP_TXDATA | OP_TXRXPEND)) {
|
||||||
// select color to blink by message port
|
// select color to blink by message port
|
||||||
switch (LMIC.pendTxPort) {
|
switch (LMIC.pendTxPort) {
|
||||||
@ -180,13 +180,13 @@ void ledLoop(void *parameter) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// small blink 10ms on each 1/2sec (not when joining)
|
// 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
|
// This should not happen so indicate a problem
|
||||||
} else if (LMIC.opmode &
|
} else if (LMIC.opmode &
|
||||||
((OP_TXDATA | OP_TXRXPEND | OP_JOINING | OP_REJOIN) == 0)) {
|
((OP_TXDATA | OP_TXRXPEND | OP_JOINING | OP_REJOIN) == 0)) {
|
||||||
LEDColor = COLOR_RED;
|
LEDColor = COLOR_RED;
|
||||||
// heartbeat long blink 200ms on each 2 seconds
|
// 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
|
} else
|
||||||
#endif // HAS_LORA
|
#endif // HAS_LORA
|
||||||
{
|
{
|
||||||
|
@ -540,23 +540,6 @@ void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg,
|
|||||||
} // switch
|
} // 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 *getSfName(rps_t rps) {
|
||||||
const char *const t[] = {"FSK", "SF7", "SF8", "SF9",
|
const char *const t[] = {"FSK", "SF7", "SF8", "SF9",
|
||||||
"SF10", "SF11", "SF12", "SF?"};
|
"SF10", "SF11", "SF12", "SF?"};
|
||||||
|
@ -124,7 +124,7 @@ void mqtt_client_task(void *param) {
|
|||||||
if (mqttClient.connected()) {
|
if (mqttClient.connected()) {
|
||||||
|
|
||||||
char buffer[PAYLOAD_BUFFER_SIZE + 3];
|
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);
|
msg.Message);
|
||||||
|
|
||||||
if (mqttClient.publish(MQTT_OUTTOPIC, buffer)) {
|
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[],
|
void mqtt_callback(MQTTClient *client, char topic[], char payload[],
|
||||||
int length) {
|
int length) {
|
||||||
if (topic == MQTT_INTOPIC)
|
if (strcmp(topic, MQTT_INTOPIC) == 0)
|
||||||
rcommand((const uint8_t *)payload, (const uint8_t)length);
|
rcommand((const uint8_t *)payload, (const uint8_t)length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,9 +178,9 @@ int do_ota_update() {
|
|||||||
client.print("Cache-Control: no-cache\r\n");
|
client.print("Cache-Control: no-cache\r\n");
|
||||||
client.print("Connection: close\r\n\r\n");
|
client.print("Connection: close\r\n\r\n");
|
||||||
|
|
||||||
unsigned long timeout = millis();
|
unsigned long timeout = _millis();
|
||||||
while (client.available() == 0) {
|
while (client.available() == 0) {
|
||||||
if ((millis() - timeout) > (RESPONSE_TIMEOUT_MS)) {
|
if ((_millis() - timeout) > (RESPONSE_TIMEOUT_MS)) {
|
||||||
ESP_LOGI(TAG, "Client timeout");
|
ESP_LOGI(TAG, "Client timeout");
|
||||||
ota_display(3, " E", "client timeout");
|
ota_display(3, " E", "client timeout");
|
||||||
goto abort;
|
goto abort;
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include "payload.h"
|
#include "payload.h"
|
||||||
#include "corona.h"
|
#include "corona.h"
|
||||||
#include "macsniff.h"
|
#include "macsniff.h"
|
||||||
|
|
||||||
extern PayloadConvert payload;
|
extern PayloadConvert payload;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ Ticker timesyncer;
|
|||||||
void setTimeSyncIRQ() { xTaskNotify(irqHandlerTask, TIMESYNC_IRQ, eSetBits); }
|
void setTimeSyncIRQ() { xTaskNotify(irqHandlerTask, TIMESYNC_IRQ, eSetBits); }
|
||||||
|
|
||||||
void calibrateTime(void) {
|
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);
|
timeSource);
|
||||||
time_t t = 0;
|
time_t t = 0;
|
||||||
uint16_t t_msec = 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));
|
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);
|
time_to_set, t_msec % 1000);
|
||||||
|
|
||||||
// if we have got an external timesource, set RTC time and shift RTC_INT pulse
|
// 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
|
timeSource = mytimesource; // set global variable
|
||||||
timesyncer.attach(TIME_SYNC_INTERVAL * 60, setTimeSyncIRQ);
|
timesyncer.attach(TIME_SYNC_INTERVAL * 60, setTimeSyncIRQ);
|
||||||
ESP_LOGD(TAG, "[%0.3f] Timesync finished, time was set | source: %c",
|
ESP_LOGD(TAG, "[%0.3f] Timesync finished, time was set | source: %c",
|
||||||
millis() / 1000.0, timeSetSymbols[mytimesource]);
|
_seconds(), timeSetSymbols[mytimesource]);
|
||||||
} else {
|
} else {
|
||||||
timesyncer.attach(TIME_SYNC_INTERVAL_RETRY * 60, setTimeSyncIRQ);
|
timesyncer.attach(TIME_SYNC_INTERVAL_RETRY * 60, setTimeSyncIRQ);
|
||||||
ESP_LOGD(TAG, "[%0.3f] Timesync failed, invalid time fetched | source: %c",
|
ESP_LOGD(TAG, "[%0.3f] Timesync failed, invalid time fetched | source: %c",
|
||||||
millis() / 1000.0, timeSetSymbols[mytimesource]);
|
_seconds(), timeSetSymbols[mytimesource]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ void timesync_request(void) {
|
|||||||
// start timesync handshake
|
// start timesync handshake
|
||||||
else {
|
else {
|
||||||
ESP_LOGI(TAG, "[%0.3f] Timeserver sync request started, seqNo#%d",
|
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
|
xTaskNotifyGive(timeSyncProcTask); // unblock timesync task
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,14 +98,14 @@ void IRAM_ATTR timesync_processReq(void *taskparameter) {
|
|||||||
if (xTaskNotifyWait(0x00, ULONG_MAX, &rcv_seqNo,
|
if (xTaskNotifyWait(0x00, ULONG_MAX, &rcv_seqNo,
|
||||||
pdMS_TO_TICKS(TIME_SYNC_TIMEOUT * 1000)) == pdFALSE) {
|
pdMS_TO_TICKS(TIME_SYNC_TIMEOUT * 1000)) == pdFALSE) {
|
||||||
ESP_LOGW(TAG, "[d%0.3f] Timesync aborted: timed out",
|
ESP_LOGW(TAG, "[d%0.3f] Timesync aborted: timed out",
|
||||||
millis() / 1000.0);
|
_seconds());
|
||||||
goto Fail; // no timestamp received before timeout
|
goto Fail; // no timestamp received before timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we are in handshake with server
|
// check if we are in handshake with server
|
||||||
if (rcv_seqNo != time_sync_seqNo) {
|
if (rcv_seqNo != time_sync_seqNo) {
|
||||||
ESP_LOGW(TAG, "[%0.3f] Timesync aborted: handshake out of sync",
|
ESP_LOGW(TAG, "[%0.3f] Timesync aborted: handshake out of sync",
|
||||||
millis() / 1000.0);
|
_seconds());
|
||||||
goto Fail;
|
goto Fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ void IRAM_ATTR timesync_processReq(void *taskparameter) {
|
|||||||
|
|
||||||
// store incoming timestamps
|
// store incoming timestamps
|
||||||
void timesync_store(uint32_t timestamp, timesync_t timestamp_type) {
|
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);
|
time_sync_seqNo, sample_idx, timestamp_type, timestamp);
|
||||||
timesync_timestamp[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 (flag != TIME_SYNC_FRAME_LENGTH) {
|
||||||
if (rcv_seqNo == TIME_SYNC_END_FLAG)
|
if (rcv_seqNo == TIME_SYNC_END_FLAG)
|
||||||
ESP_LOGI(TAG, "[%0.3f] Timeserver error: no confident time available",
|
ESP_LOGI(TAG, "[%0.3f] Timeserver error: no confident time available",
|
||||||
millis() / 1000.0);
|
_seconds());
|
||||||
else
|
else
|
||||||
ESP_LOGW(TAG, "[%0.3f] Timeserver error: spurious data received",
|
ESP_LOGW(TAG, "[%0.3f] Timeserver error: spurious data received",
|
||||||
millis() / 1000.0);
|
_seconds());
|
||||||
goto Exit; // failure
|
goto Exit; // failure
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,13 +233,13 @@ void IRAM_ATTR timesync_serverAnswer(void *pUserData, int flag) {
|
|||||||
|
|
||||||
if (flag != 1) {
|
if (flag != 1) {
|
||||||
ESP_LOGW(TAG, "[%0.3f] Network did not answer time request",
|
ESP_LOGW(TAG, "[%0.3f] Network did not answer time request",
|
||||||
millis() / 1000.0);
|
_seconds());
|
||||||
goto Exit;
|
goto Exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate lmic_time_reference
|
// Populate lmic_time_reference
|
||||||
if ((LMIC_getNetworkTimeReference(&lmicTime)) != 1) {
|
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;
|
goto Exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,7 +267,7 @@ Finish:
|
|||||||
rc = 1;
|
rc = 1;
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGW(TAG, "[%0.3f] Timeserver error: outdated time received",
|
ESP_LOGW(TAG, "[%0.3f] Timeserver error: outdated time received",
|
||||||
millis() / 1000.0);
|
_seconds());
|
||||||
}
|
}
|
||||||
|
|
||||||
Exit:
|
Exit:
|
||||||
|
Loading…
Reference in New Issue
Block a user