Undo merge
This commit is contained in:
1 parent
d9404b1a32
commit
7bdff00161
60 files changed
+1911
-1679
No files matched your search
@@ -4,15 +4,22 @@
|
||||
function Converter(decoded, port) {
|
||||
|
||||
var converted = decoded;
|
||||
var pax = 0;
|
||||
|
||||
if (port === 1) {
|
||||
converted.pax = converted.ble + converted.wifi;
|
||||
if('wifi' in converted){
|
||||
pax += converted.wifi
|
||||
}
|
||||
|
||||
if('ble' in converted){
|
||||
pax += converted.ble
|
||||
}
|
||||
converted.pax = pax;
|
||||
}
|
||||
|
||||
if (port === 2) {
|
||||
converted.voltage /= 1000;
|
||||
}
|
||||
|
||||
|
||||
return converted;
|
||||
}
|
||||
@@ -5,12 +5,24 @@ function Decoder(bytes, port) {
|
||||
|
||||
var decoded = {};
|
||||
|
||||
if (bytes.length === 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (port === 1) {
|
||||
// only counter data, no gps
|
||||
// only wifi counter data, no gps
|
||||
if (bytes.length === 2) {
|
||||
return decode(bytes, [uint16], ['wifi']);
|
||||
}
|
||||
// wifi + ble counter data, no gps
|
||||
if (bytes.length === 4) {
|
||||
return decode(bytes, [uint16, uint16], ['wifi', 'ble']);
|
||||
}
|
||||
// combined counter and gps data
|
||||
// combined wifi counter and gps data
|
||||
if (bytes.length === 15) {
|
||||
return decode(bytes, [uint16, latLng, latLng, uint8, hdop, uint16], ['wifi', 'latitude', 'longitude', 'sats', 'hdop', 'altitude']);
|
||||
}
|
||||
// combined wifi + ble counter and gps data
|
||||
if (bytes.length === 17) {
|
||||
return decode(bytes, [uint16, uint16, latLng, latLng, uint8, hdop, uint16], ['wifi', 'ble', 'latitude', 'longitude', 'sats', 'hdop', 'altitude']);
|
||||
}
|
||||
@@ -46,6 +58,11 @@ function Decoder(bytes, port) {
|
||||
return decode(bytes, [float, uint16, ufloat, ufloat], ['temperature', 'pressure', 'humidity', 'air']);
|
||||
}
|
||||
|
||||
if (port === 8) {
|
||||
// battery voltage
|
||||
return decode(bytes, [uint16], ['voltage']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,8 +7,11 @@ function Decoder(bytes, port) {
|
||||
if (port === 1) {
|
||||
var i = 0;
|
||||
|
||||
decoded.wifi = (bytes[i++] << 8) | bytes[i++];
|
||||
decoded.ble = (bytes[i++] << 8) | bytes[i++];
|
||||
if (bytes.length >= 2) {
|
||||
decoded.wifi = (bytes[i++] << 8) | bytes[i++];}
|
||||
|
||||
if (bytes.length >= 4) {
|
||||
decoded.ble = (bytes[i++] << 8) | bytes[i++];}
|
||||
|
||||
if (bytes.length > 4) {
|
||||
decoded.latitude = ((bytes[i++] << 24) | (bytes[i++] << 16) | (bytes[i++] << 8) | bytes[i++]);
|
||||
|
||||
+14
-3
@@ -13,6 +13,7 @@ https://github.com/nkolban/esp32-snippets/tree/master/BLE/scanner
|
||||
#include <esp_bt_main.h>
|
||||
#include <esp_gap_ble_api.h>
|
||||
#include <esp_blufi_api.h> // needed for BLE_ADDR types, do not remove
|
||||
#include <esp_coexist.h>
|
||||
|
||||
#define BT_BD_ADDR_HEX(addr) \
|
||||
addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
|
||||
@@ -243,9 +244,16 @@ esp_err_t register_ble_callback(void) {
|
||||
|
||||
} // register_ble_callback
|
||||
|
||||
#endif // BLECOUNTER
|
||||
|
||||
void start_BLEscan(void) {
|
||||
#ifdef BLECOUNTER
|
||||
ESP_LOGI(TAG, "Initializing bluetooth scanner ...");
|
||||
|
||||
ESP_ERROR_CHECK(esp_coex_preference_set(
|
||||
(esp_coex_prefer_t)
|
||||
ESP_COEX_PREFER_BALANCE)); // configure Wifi/BT coexist lib
|
||||
|
||||
// Initialize BT controller to allocate task and other resource.
|
||||
btStart();
|
||||
ESP_ERROR_CHECK(esp_bluedroid_init());
|
||||
@@ -255,15 +263,18 @@ void start_BLEscan(void) {
|
||||
ESP_ERROR_CHECK(register_ble_callback());
|
||||
|
||||
ESP_LOGI(TAG, "Bluetooth scanner started");
|
||||
#endif // BLECOUNTER
|
||||
} // start_BLEscan
|
||||
|
||||
void stop_BLEscan(void) {
|
||||
#ifdef BLECOUNTER
|
||||
ESP_LOGI(TAG, "Shutting down bluetooth scanner ...");
|
||||
ESP_ERROR_CHECK(esp_ble_gap_register_callback(NULL));
|
||||
ESP_ERROR_CHECK(esp_bluedroid_disable());
|
||||
ESP_ERROR_CHECK(esp_bluedroid_deinit());
|
||||
btStop(); // disable & deinit bt_controller
|
||||
btStop(); // disable bt_controller
|
||||
ESP_ERROR_CHECK(esp_coex_preference_set((
|
||||
esp_coex_prefer_t)ESP_COEX_PREFER_WIFI)); // configure Wifi/BT coexist lib
|
||||
ESP_LOGI(TAG, "Bluetooth scanner stopped");
|
||||
} // stop_BLEscan
|
||||
|
||||
#endif // BLECOUNTER
|
||||
} // stop_BLEscan
|
||||
+132
-139
@@ -8,82 +8,97 @@ static const char TAG[] = "main";
|
||||
bmeStatus_t bme_status;
|
||||
TaskHandle_t BmeTask;
|
||||
|
||||
float bme_offset = (float) BME_TEMP_OFFSET;
|
||||
bsec_virtual_sensor_t sensorList[10] = {
|
||||
BSEC_OUTPUT_RAW_TEMPERATURE,
|
||||
BSEC_OUTPUT_RAW_PRESSURE,
|
||||
BSEC_OUTPUT_RAW_HUMIDITY,
|
||||
BSEC_OUTPUT_RAW_GAS,
|
||||
BSEC_OUTPUT_IAQ,
|
||||
BSEC_OUTPUT_STATIC_IAQ,
|
||||
BSEC_OUTPUT_CO2_EQUIVALENT,
|
||||
BSEC_OUTPUT_BREATH_VOC_EQUIVALENT,
|
||||
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE,
|
||||
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
|
||||
};
|
||||
|
||||
// --- Bosch BSEC library configuration ---
|
||||
// 3,3V supply voltage; 3s max time between sensor_control calls; 4 days
|
||||
// calibration. Change this const if not applicable for your application (see
|
||||
// BME680 datasheet)
|
||||
const uint8_t bsec_config_iaq[454] = {
|
||||
1, 7, 4, 1, 61, 0, 0, 0, 0, 0, 0, 0, 174, 1, 0,
|
||||
0, 48, 0, 1, 0, 137, 65, 0, 63, 205, 204, 204, 62, 0, 0,
|
||||
64, 63, 205, 204, 204, 62, 0, 0, 225, 68, 0, 192, 168, 71, 64,
|
||||
49, 119, 76, 0, 0, 0, 0, 0, 80, 5, 95, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 28, 0, 2, 0, 0, 244, 1, 225, 0, 25, 0,
|
||||
0, 128, 64, 0, 0, 32, 65, 144, 1, 0, 0, 112, 65, 0, 0,
|
||||
0, 63, 16, 0, 3, 0, 10, 215, 163, 60, 10, 215, 35, 59, 10,
|
||||
215, 35, 59, 9, 0, 5, 0, 0, 0, 0, 0, 1, 88, 0, 9,
|
||||
0, 229, 208, 34, 62, 0, 0, 0, 0, 0, 0, 0, 0, 218, 27,
|
||||
156, 62, 225, 11, 67, 64, 0, 0, 160, 64, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 94, 75, 72, 189, 93, 254, 159, 64, 66, 62, 160, 191,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 33, 31, 180, 190, 138, 176, 97,
|
||||
64, 65, 241, 99, 190, 0, 0, 0, 0, 0, 0, 0, 0, 167, 121,
|
||||
71, 61, 165, 189, 41, 192, 184, 30, 189, 64, 12, 0, 10, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 229, 0, 254, 0, 2, 1, 5, 48,
|
||||
117, 100, 0, 44, 1, 112, 23, 151, 7, 132, 3, 197, 0, 92, 4,
|
||||
144, 1, 64, 1, 64, 1, 144, 1, 48, 117, 48, 117, 48, 117, 48,
|
||||
117, 100, 0, 100, 0, 100, 0, 48, 117, 48, 117, 48, 117, 100, 0,
|
||||
100, 0, 48, 117, 48, 117, 100, 0, 100, 0, 100, 0, 100, 0, 48,
|
||||
117, 48, 117, 48, 117, 100, 0, 100, 0, 100, 0, 48, 117, 48, 117,
|
||||
100, 0, 100, 0, 44, 1, 44, 1, 44, 1, 44, 1, 44, 1, 44,
|
||||
1, 44, 1, 44, 1, 44, 1, 44, 1, 44, 1, 44, 1, 44, 1,
|
||||
44, 1, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8,
|
||||
7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7,
|
||||
112, 23, 112, 23, 112, 23, 112, 23, 112, 23, 112, 23, 112, 23, 112,
|
||||
23, 112, 23, 112, 23, 112, 23, 112, 23, 112, 23, 112, 23, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 220, 5, 220, 5, 220, 5, 255, 255, 255,
|
||||
255, 255, 255, 220, 5, 220, 5, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 44, 1, 0, 0, 0, 0,
|
||||
239, 79, 0, 0};
|
||||
uint8_t bsecstate_buffer[BSEC_MAX_STATE_BLOB_SIZE] = {0};
|
||||
uint16_t stateUpdateCounter = 0;
|
||||
|
||||
Bsec iaqSensor;
|
||||
|
||||
// initialize BME680 sensor
|
||||
int bme_init(void) {
|
||||
|
||||
// struct bme680_dev gas_sensor;
|
||||
Wire.begin(HAS_BME, 400000); // I2C connect to BME680 sensor with 400 KHz
|
||||
// return = 0 -> error / return = 1 -> success
|
||||
|
||||
// Call to the function which initializes the BSEC library
|
||||
// Switch on low-power mode and provide no temperature offset
|
||||
// block i2c bus access
|
||||
if (xSemaphoreTake(I2Caccess, (DISPLAYREFRESH_MS / portTICK_PERIOD_MS)) ==
|
||||
pdTRUE) {
|
||||
|
||||
Wire.begin(HAS_BME);
|
||||
iaqSensor.begin(BME_ADDR, Wire);
|
||||
|
||||
ESP_LOGI(TAG, "BSEC v%d.%d.%d.%d", iaqSensor.version.major,
|
||||
iaqSensor.version.minor, iaqSensor.version.major_bugfix,
|
||||
iaqSensor.version.minor_bugfix);
|
||||
|
||||
iaqSensor.setConfig(bsec_config_iaq);
|
||||
|
||||
if (checkIaqSensorStatus())
|
||||
ESP_LOGI(TAG, "BME680 sensor found and initialized");
|
||||
else {
|
||||
ESP_LOGE(TAG, "BME680 sensor not found");
|
||||
goto error;
|
||||
}
|
||||
|
||||
loadState();
|
||||
|
||||
iaqSensor.setTemperatureOffset((float)BME_TEMP_OFFSET);
|
||||
iaqSensor.updateSubscription(sensorList, 10, BSEC_SAMPLE_RATE_LP);
|
||||
|
||||
if (checkIaqSensorStatus())
|
||||
ESP_LOGI(TAG, "BSEC subscription succesful");
|
||||
else {
|
||||
ESP_LOGE(TAG, "BSEC subscription error");
|
||||
goto error;
|
||||
}
|
||||
|
||||
return_values_init ret =
|
||||
bsec_iot_init(BSEC_SAMPLE_RATE_LP, bme_offset, i2c_write, i2c_read,
|
||||
user_delay_ms, state_load, config_load);
|
||||
|
||||
if ((int)ret.bme680_status) {
|
||||
ESP_LOGE(TAG, "Could not initialize BME680, error %d",
|
||||
(int)ret.bme680_status);
|
||||
} else if ((int)ret.bsec_status) {
|
||||
ESP_LOGE(TAG, "Could not initialize BSEC library, error %d",
|
||||
(int)ret.bsec_status);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "BME680 sensor found and initialized");
|
||||
return 1;
|
||||
ESP_LOGE(TAG, "I2c bus busy - BME680 initialization error");
|
||||
goto error;
|
||||
}
|
||||
|
||||
xSemaphoreGive(I2Caccess); // release i2c bus access
|
||||
return 1;
|
||||
|
||||
error:
|
||||
xSemaphoreGive(I2Caccess); // release i2c bus access
|
||||
return 0;
|
||||
}
|
||||
|
||||
void output_ready(int64_t timestamp, float iaq, uint8_t iaq_accuracy,
|
||||
float temperature, float humidity, float pressure,
|
||||
float raw_temperature, float raw_humidity, float gas,
|
||||
bsec_library_return_t bsec_status, float static_iaq,
|
||||
float co2_equivalent, float breath_voc_equivalent) {
|
||||
} // bme_init()
|
||||
|
||||
bme_status.temperature = temperature;
|
||||
bme_status.humidity = humidity;
|
||||
bme_status.pressure = (pressure / 100.0); // conversion Pa -> hPa
|
||||
bme_status.iaq = iaq;
|
||||
}
|
||||
// Helper function definitions
|
||||
int checkIaqSensorStatus(void) {
|
||||
int rslt = 1; // true = 1 = no error, false = 0 = error
|
||||
|
||||
if (iaqSensor.status != BSEC_OK) {
|
||||
rslt = 0;
|
||||
if (iaqSensor.status < BSEC_OK)
|
||||
ESP_LOGE(TAG, "BSEC error %d", iaqSensor.status);
|
||||
else
|
||||
ESP_LOGW(TAG, "BSEC warning %d", iaqSensor.status);
|
||||
}
|
||||
|
||||
if (iaqSensor.bme680Status != BME680_OK) {
|
||||
rslt = 0;
|
||||
if (iaqSensor.bme680Status < BME680_OK)
|
||||
ESP_LOGE(TAG, "BME680 error %d", iaqSensor.bme680Status);
|
||||
else
|
||||
ESP_LOGW(TAG, "BME680 warning %d", iaqSensor.bme680Status);
|
||||
}
|
||||
|
||||
return rslt;
|
||||
} // checkIaqSensorStatus()
|
||||
|
||||
// loop function which reads and processes data based on sensor settings
|
||||
void bme_loop(void *pvParameters) {
|
||||
@@ -91,90 +106,68 @@ void bme_loop(void *pvParameters) {
|
||||
configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
|
||||
|
||||
#ifdef HAS_BME
|
||||
// State is saved every 10.000 samples, which means every 10.000 * 3 secs =
|
||||
// 500 minutes
|
||||
bsec_iot_loop(user_delay_ms, get_timestamp_us, output_ready, state_save,
|
||||
10000);
|
||||
// block i2c bus access
|
||||
while (xSemaphoreTake(I2Caccess, portMAX_DELAY) == pdTRUE) {
|
||||
|
||||
if (iaqSensor.run()) { // If new data is available
|
||||
bme_status.raw_temperature = iaqSensor.rawTemperature;
|
||||
bme_status.raw_humidity = iaqSensor.rawHumidity;
|
||||
bme_status.temperature = iaqSensor.temperature;
|
||||
bme_status.humidity = iaqSensor.humidity;
|
||||
bme_status.pressure =
|
||||
(iaqSensor.pressure / 100.0); // conversion Pa -> hPa
|
||||
bme_status.iaq = iaqSensor.iaqEstimate;
|
||||
bme_status.iaq_accuracy = iaqSensor.iaqAccuracy;
|
||||
bme_status.gas = iaqSensor.gasResistance;
|
||||
updateState();
|
||||
}
|
||||
xSemaphoreGive(I2Caccess); // release i2c bus access
|
||||
|
||||
} // while
|
||||
#endif
|
||||
ESP_LOGE(TAG, "BME task ended");
|
||||
vTaskDelete(BmeTask); // should never be reached
|
||||
|
||||
} // bme_loop()
|
||||
|
||||
int8_t i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data,
|
||||
uint16_t len) {
|
||||
int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
|
||||
uint16_t i;
|
||||
void loadState(void) {
|
||||
if (cfg.bsecstate[BSEC_MAX_STATE_BLOB_SIZE] == BSEC_MAX_STATE_BLOB_SIZE) {
|
||||
// Existing state in NVS stored
|
||||
ESP_LOGI(TAG, "restoring BSEC state from NVRAM");
|
||||
memcpy(bsecstate_buffer, cfg.bsecstate, BSEC_MAX_STATE_BLOB_SIZE);
|
||||
iaqSensor.setState(bsecstate_buffer);
|
||||
checkIaqSensorStatus();
|
||||
} else // no state stored
|
||||
ESP_LOGI(TAG,
|
||||
"no BSEC state stored in NVRAM, starting sensor with defaults");
|
||||
}
|
||||
|
||||
Wire.beginTransmission(dev_id);
|
||||
Wire.write(reg_addr);
|
||||
rslt = Wire.endTransmission();
|
||||
void updateState(void) {
|
||||
bool update = false;
|
||||
|
||||
Wire.requestFrom((int)dev_id, (int)len);
|
||||
for (i = 0; (i < len) && Wire.available(); i++) {
|
||||
reg_data[i] = Wire.read();
|
||||
if (stateUpdateCounter == 0) {
|
||||
// first state update when IAQ accuracy is >= 1
|
||||
if (iaqSensor.iaqAccuracy >= 1) {
|
||||
update = true;
|
||||
stateUpdateCounter++;
|
||||
}
|
||||
} else {
|
||||
|
||||
/* Update every STATE_SAVE_PERIOD minutes */
|
||||
if ((stateUpdateCounter * STATE_SAVE_PERIOD) < millis()) {
|
||||
update = true;
|
||||
stateUpdateCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
int8_t i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data,
|
||||
uint16_t len) {
|
||||
int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
|
||||
uint16_t i;
|
||||
|
||||
Wire.beginTransmission(dev_id);
|
||||
Wire.write(reg_addr);
|
||||
for (i = 0; i < len; i++) {
|
||||
Wire.write(reg_data[i]);
|
||||
if (update) {
|
||||
iaqSensor.getState(bsecstate_buffer);
|
||||
checkIaqSensorStatus();
|
||||
memcpy(cfg.bsecstate, bsecstate_buffer, BSEC_MAX_STATE_BLOB_SIZE);
|
||||
cfg.bsecstate[BSEC_MAX_STATE_BLOB_SIZE] = BSEC_MAX_STATE_BLOB_SIZE;
|
||||
ESP_LOGI(TAG, "saving BSEC state to NVRAM");
|
||||
saveConfig();
|
||||
}
|
||||
rslt = Wire.endTransmission();
|
||||
|
||||
return rslt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Load previous library state from non-volatile memory
|
||||
*
|
||||
* @param[in,out] state_buffer buffer to hold the loaded state string
|
||||
* @param[in] n_buffer size of the allocated state buffer
|
||||
*
|
||||
* @return number of bytes copied to state_buffer
|
||||
*/
|
||||
uint32_t state_load(uint8_t *state_buffer, uint32_t n_buffer) {
|
||||
// ...
|
||||
// Load a previous library state from non-volatile memory, if available.
|
||||
//
|
||||
// Return zero if loading was unsuccessful or no state was available,
|
||||
// otherwise return length of loaded state string.
|
||||
// ...
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Save library state to non-volatile memory
|
||||
*
|
||||
* @param[in] state_buffer buffer holding the state to be stored
|
||||
* @param[in] length length of the state string to be stored
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void state_save(const uint8_t *state_buffer, uint32_t length) {
|
||||
// ...
|
||||
// Save the string some form of non-volatile memory, if possible.
|
||||
// ...
|
||||
}
|
||||
|
||||
uint32_t config_load(uint8_t *config_buffer, uint32_t n_buffer) {
|
||||
|
||||
// Load a library config from non-volatile memory, if available.
|
||||
// Return zero if loading was unsuccessful or no config was available,
|
||||
// otherwise return length of loaded config string.
|
||||
|
||||
memcpy(config_buffer, bsec_config_iaq, sizeof(bsec_config_iaq));
|
||||
return sizeof(bsec_config_iaq);
|
||||
}
|
||||
|
||||
void user_delay_ms(uint32_t period) { vTaskDelay(period / portTICK_PERIOD_MS); }
|
||||
|
||||
int64_t get_timestamp_us() { return (int64_t)millis() * 1000; }
|
||||
|
||||
#endif // HAS_BME
|
||||
+20
-4
@@ -25,13 +25,15 @@ void defaultConfig() {
|
||||
cfg.blescantime =
|
||||
BLESCANINTERVAL /
|
||||
10; // BT channel scan cycle [seconds/100], default 1 (= 10ms)
|
||||
cfg.blescan = 1; // 0=disabled, 1=enabled
|
||||
cfg.blescan = 0; // 0=disabled, 1=enabled
|
||||
cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4)
|
||||
cfg.vendorfilter = 1; // 0=disabled, 1=enabled
|
||||
cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%)
|
||||
cfg.monitormode = 0; // 0=disabled, 1=enabled
|
||||
cfg.runmode = 0; // 0=normal, 1=update
|
||||
cfg.payloadmask = 0xFF; // all payload switched on
|
||||
cfg.bsecstate[BSEC_MAX_STATE_BLOB_SIZE] = {
|
||||
0}; // init BSEC state for BME680 sensor
|
||||
|
||||
strncpy(cfg.version, PROGVERSION, sizeof(cfg.version) - 1);
|
||||
}
|
||||
@@ -77,8 +79,15 @@ void saveConfig() {
|
||||
int8_t flash8 = 0;
|
||||
int16_t flash16 = 0;
|
||||
size_t required_size;
|
||||
uint8_t bsecstate_buffer[BSEC_MAX_STATE_BLOB_SIZE + 1];
|
||||
char storedversion[10];
|
||||
|
||||
if (nvs_get_blob(my_handle, "bsecstate", bsecstate_buffer,
|
||||
&required_size) != ESP_OK ||
|
||||
memcmp(bsecstate_buffer, cfg.bsecstate, BSEC_MAX_STATE_BLOB_SIZE + 1) != 0)
|
||||
nvs_set_blob(my_handle, "bsecstate", cfg.bsecstate,
|
||||
BSEC_MAX_STATE_BLOB_SIZE + 1);
|
||||
|
||||
if (nvs_get_str(my_handle, "version", storedversion, &required_size) !=
|
||||
ESP_OK ||
|
||||
strcmp(storedversion, cfg.version) != 0)
|
||||
@@ -202,7 +211,14 @@ void loadConfig() {
|
||||
migrateVersion();
|
||||
}
|
||||
|
||||
// overwrite defaults with valid values from NVRAM
|
||||
// populate pre set defaults with current values from NVRAM
|
||||
|
||||
if (nvs_get_blob(my_handle, "bsecstate", NULL, &required_size) == ESP_OK) {
|
||||
nvs_get_blob(my_handle, "bsecstate", cfg.bsecstate, &required_size);
|
||||
ESP_LOGI(TAG, "bsecstate = %d",
|
||||
cfg.bsecstate[BSEC_MAX_STATE_BLOB_SIZE]);
|
||||
};
|
||||
|
||||
if (nvs_get_i8(my_handle, "lorasf", &flash8) == ESP_OK) {
|
||||
cfg.lorasf = flash8;
|
||||
ESP_LOGI(TAG, "lorasf = %d", flash8);
|
||||
@@ -317,9 +333,9 @@ void loadConfig() {
|
||||
|
||||
if (nvs_get_i8(my_handle, "payloadmask", &flash8) == ESP_OK) {
|
||||
cfg.payloadmask = flash8;
|
||||
ESP_LOGI(TAG, "payloadmask = %u", flash8);
|
||||
ESP_LOGI(TAG, "payloadmask = %d", flash8);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "payloadmask set to default %u", cfg.payloadmask);
|
||||
ESP_LOGI(TAG, "payloadmask set to default %d", cfg.payloadmask);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
|
||||
+58
-19
@@ -26,48 +26,73 @@ void doHousekeeping() {
|
||||
// time sync once per TIME_SYNC_INTERVAL
|
||||
#ifdef TIME_SYNC_INTERVAL
|
||||
if (millis() >= nextTimeSync) {
|
||||
nextTimeSync = millis() + TIME_SYNC_INTERVAL *
|
||||
60000; // set up next time sync period
|
||||
nextTimeSync =
|
||||
millis() + TIME_SYNC_INTERVAL * 60000; // set up next time sync period
|
||||
do_timesync();
|
||||
}
|
||||
#endif
|
||||
|
||||
// task storage debugging //
|
||||
ESP_LOGD(TAG, "Wifiloop %d bytes left",
|
||||
uxTaskGetStackHighWaterMark(wifiSwitchTask));
|
||||
ESP_LOGD(TAG, "IRQhandler %d bytes left",
|
||||
uxTaskGetStackHighWaterMark(irqHandlerTask));
|
||||
ESP_LOGD(TAG, "Wifiloop %d bytes left | Taskstate = %d",
|
||||
uxTaskGetStackHighWaterMark(wifiSwitchTask),
|
||||
eTaskGetState(wifiSwitchTask));
|
||||
ESP_LOGD(TAG, "IRQhandler %d bytes left | Taskstate = %d",
|
||||
uxTaskGetStackHighWaterMark(irqHandlerTask),
|
||||
eTaskGetState(irqHandlerTask));
|
||||
#ifdef HAS_GPS
|
||||
ESP_LOGD(TAG, "Gpsloop %d bytes left", uxTaskGetStackHighWaterMark(GpsTask));
|
||||
ESP_LOGD(TAG, "Gpsloop %d bytes left | Taskstate = %d",
|
||||
uxTaskGetStackHighWaterMark(GpsTask), eTaskGetState(GpsTask));
|
||||
#endif
|
||||
#ifdef HAS_BME
|
||||
ESP_LOGD(TAG, "Bmeloop %d bytes left", uxTaskGetStackHighWaterMark(BmeTask));
|
||||
ESP_LOGD(TAG, "Bmeloop %d bytes left | Taskstate = %d",
|
||||
uxTaskGetStackHighWaterMark(BmeTask), eTaskGetState(BmeTask));
|
||||
#endif
|
||||
|
||||
#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
|
||||
ESP_LOGD(TAG, "LEDloop %d bytes left",
|
||||
uxTaskGetStackHighWaterMark(ledLoopTask));
|
||||
ESP_LOGD(TAG, "LEDloop %d bytes left | Taskstate = %d",
|
||||
uxTaskGetStackHighWaterMark(ledLoopTask),
|
||||
eTaskGetState(ledLoopTask));
|
||||
#endif
|
||||
|
||||
// read battery voltage into global variable
|
||||
#ifdef HAS_BATTERY_PROBE
|
||||
batt_voltage = read_voltage();
|
||||
ESP_LOGI(TAG, "Measured Voltage: %dmV", batt_voltage);
|
||||
ESP_LOGI(TAG, "Voltage: %dmV", batt_voltage);
|
||||
#endif
|
||||
|
||||
// check free memory
|
||||
if (esp_get_minimum_free_heap_size() <= MEM_LOW) {
|
||||
// display BME sensor data
|
||||
#ifdef HAS_BME
|
||||
ESP_LOGI(TAG, "BME680 Temp: %.2f°C | IAQ: %.2f | IAQacc: %d",
|
||||
bme_status.temperature, bme_status.iaq, bme_status.iaq_accuracy);
|
||||
#endif
|
||||
|
||||
// check free heap memory
|
||||
if (ESP.getMinFreeHeap() <= 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());
|
||||
ESP.getMinFreeHeap(), ESP.getFreeHeap());
|
||||
SendPayload(COUNTERPORT); // send data before clearing counters
|
||||
reset_counters(); // clear macs container and reset all counters
|
||||
get_salt(); // get new salt for salting hashes
|
||||
reset_counters(); // clear macs container and reset all counters
|
||||
get_salt(); // get new salt for salting hashes
|
||||
|
||||
if (esp_get_minimum_free_heap_size() <= MEM_LOW) // check again
|
||||
do_reset(); // memory leak, reset device
|
||||
if (ESP.getMinFreeHeap() <= MEM_LOW) // check again
|
||||
do_reset(); // memory leak, reset device
|
||||
}
|
||||
|
||||
// check free PSRAM memory
|
||||
#ifdef BOARD_HAS_PSRAM
|
||||
if (ESP.getMinFreePsram() <= MEM_LOW) {
|
||||
ESP_LOGI(TAG, "PSRAM full, counter cleared");
|
||||
SendPayload(COUNTERPORT); // send data before clearing counters
|
||||
reset_counters(); // clear macs container and reset all counters
|
||||
get_salt(); // get new salt for salting hashes
|
||||
|
||||
if (ESP.getMinFreePsram() <= MEM_LOW) // check again
|
||||
do_reset(); // memory leak, reset device
|
||||
}
|
||||
#endif
|
||||
|
||||
} // doHousekeeping()
|
||||
|
||||
// uptime counter 64bit to prevent millis() rollover after 49 days
|
||||
@@ -80,6 +105,14 @@ uint64_t uptime() {
|
||||
return (uint64_t)high32 << 32 | low32;
|
||||
}
|
||||
|
||||
uint32_t getFreeRAM() {
|
||||
#ifndef BOARD_HAS_PSRAM
|
||||
return ESP.getFreeHeap();
|
||||
#else
|
||||
return ESP.getFreePsram();
|
||||
#endif
|
||||
}
|
||||
|
||||
void reset_counters() {
|
||||
macs.clear(); // clear all macs container
|
||||
macs_total = 0; // reset all counters
|
||||
@@ -89,7 +122,8 @@ void reset_counters() {
|
||||
|
||||
void do_timesync() {
|
||||
#ifdef TIME_SYNC_INTERVAL
|
||||
// sync time & date if we have valid gps time
|
||||
|
||||
// sync time & date by GPS if we have valid gps time
|
||||
#ifdef HAS_GPS
|
||||
if (gps.time.isValid()) {
|
||||
setTime(gps.time.hour(), gps.time.minute(), gps.time.second(),
|
||||
@@ -101,9 +135,14 @@ void do_timesync() {
|
||||
ESP_LOGI(TAG, "No valid GPS time");
|
||||
}
|
||||
#endif // HAS_GPS
|
||||
|
||||
// sync time by LoRa Network if network supports DevTimeReq
|
||||
#ifdef LMIC_ENABLE_DeviceTimeReq
|
||||
// Schedule a network time request at the next possible time
|
||||
LMIC_requestNetworkTime(user_request_network_time_callback, &userUTCTime);
|
||||
ESP_LOGI(TAG, "Network time request scheduled");
|
||||
#endif
|
||||
|
||||
#endif // TIME_SYNC_INTERVAL
|
||||
} // do_timesync()
|
||||
|
||||
|
||||
+75
-70
@@ -43,14 +43,14 @@ void init_display(const char *Productname, const char *Version) {
|
||||
u8x8.draw2x2String(0, 0, Productname);
|
||||
u8x8.setInverseFont(0);
|
||||
u8x8.draw2x2String(2, 2, Productname);
|
||||
vTaskDelay(1500 / portTICK_PERIOD_MS);
|
||||
delay(1500);
|
||||
u8x8.clear();
|
||||
u8x8.setFlipMode(1);
|
||||
u8x8.setInverseFont(1);
|
||||
u8x8.draw2x2String(0, 0, Productname);
|
||||
u8x8.setInverseFont(0);
|
||||
u8x8.draw2x2String(2, 2, Productname);
|
||||
vTaskDelay(1500 / portTICK_PERIOD_MS);
|
||||
delay(1500);
|
||||
|
||||
u8x8.setFlipMode(0);
|
||||
u8x8.clear();
|
||||
@@ -81,7 +81,7 @@ void init_display(const char *Productname, const char *Version) {
|
||||
DisplayKey(buf, 8, true);
|
||||
#endif // HAS_LORA
|
||||
|
||||
vTaskDelay(3000 / portTICK_PERIOD_MS);
|
||||
delay(3000);
|
||||
u8x8.clear();
|
||||
u8x8.setPowerSave(!cfg.screenon); // set display off if disabled
|
||||
u8x8.draw2x2String(0, 0, "PAX:0");
|
||||
@@ -98,99 +98,104 @@ void init_display(const char *Productname, const char *Version) {
|
||||
|
||||
void refreshtheDisplay() {
|
||||
|
||||
// set display on/off according to current device configuration
|
||||
if (DisplayState != cfg.screenon) {
|
||||
DisplayState = cfg.screenon;
|
||||
u8x8.setPowerSave(!cfg.screenon);
|
||||
}
|
||||
// block i2c bus access
|
||||
if (xSemaphoreTake(I2Caccess, (DISPLAYREFRESH_MS / portTICK_PERIOD_MS)) ==
|
||||
pdTRUE) {
|
||||
|
||||
// if display is switched off we don't refresh it and save time
|
||||
if (!DisplayState)
|
||||
return;
|
||||
// set display on/off according to current device configuration
|
||||
if (DisplayState != cfg.screenon) {
|
||||
DisplayState = cfg.screenon;
|
||||
u8x8.setPowerSave(!cfg.screenon);
|
||||
}
|
||||
|
||||
uint8_t msgWaiting;
|
||||
char buff[16]; // 16 chars line buffer
|
||||
// if display is switched off we don't refresh it and save time
|
||||
if (!DisplayState)
|
||||
return;
|
||||
|
||||
// update counter (lines 0-1)
|
||||
snprintf(
|
||||
buff, sizeof(buff), "PAX:%-4d",
|
||||
(int)macs.size()); // convert 16-bit MAC counter to decimal counter value
|
||||
u8x8.draw2x2String(0, 0,
|
||||
buff); // display number on unique macs total Wifi + BLE
|
||||
uint8_t msgWaiting;
|
||||
char buff[16]; // 16 chars line buffer
|
||||
|
||||
// update counter (lines 0-1)
|
||||
snprintf(
|
||||
buff, sizeof(buff), "PAX:%-4d",
|
||||
(int)
|
||||
macs.size()); // convert 16-bit MAC counter to decimal counter value
|
||||
u8x8.draw2x2String(0, 0,
|
||||
buff); // display number on unique macs total Wifi + BLE
|
||||
|
||||
// update Battery status (line 2)
|
||||
#ifdef HAS_BATTERY_PROBE
|
||||
u8x8.setCursor(0, 2);
|
||||
u8x8.printf(batt_voltage > 4000 ? "B:USB " : "B:%.1fV",
|
||||
batt_voltage / 1000.0);
|
||||
u8x8.setCursor(0, 2);
|
||||
u8x8.printf("B:%.1fV", batt_voltage / 1000.0);
|
||||
#endif
|
||||
|
||||
// update GPS status (line 2)
|
||||
#ifdef HAS_GPS
|
||||
u8x8.setCursor(9, 2);
|
||||
if (!gps.location.isValid()) // if no fix then display Sats value inverse
|
||||
{
|
||||
u8x8.setInverseFont(1);
|
||||
u8x8.printf("Sats:%.2d", gps.satellites.value());
|
||||
u8x8.setInverseFont(0);
|
||||
} else
|
||||
u8x8.printf("Sats:%.2d", gps.satellites.value());
|
||||
u8x8.setCursor(9, 2);
|
||||
if (!gps.location.isValid()) // if no fix then display Sats value inverse
|
||||
{
|
||||
u8x8.setInverseFont(1);
|
||||
u8x8.printf("Sats:%.2d", gps.satellites.value());
|
||||
u8x8.setInverseFont(0);
|
||||
} else
|
||||
u8x8.printf("Sats:%.2d", gps.satellites.value());
|
||||
#endif
|
||||
|
||||
// update bluetooth counter + LoRa SF (line 3)
|
||||
// update bluetooth counter + LoRa SF (line 3)
|
||||
#ifdef BLECOUNTER
|
||||
u8x8.setCursor(0, 3);
|
||||
if (cfg.blescan)
|
||||
u8x8.printf("BLTH:%-4d", macs_ble);
|
||||
else
|
||||
u8x8.printf("%s", "BLTH:off");
|
||||
u8x8.setCursor(0, 3);
|
||||
if (cfg.blescan)
|
||||
u8x8.printf("BLTH:%-4d", macs_ble);
|
||||
else
|
||||
u8x8.printf("%s", "BLTH:off");
|
||||
#endif
|
||||
|
||||
#ifdef HAS_LORA
|
||||
u8x8.setCursor(11, 3);
|
||||
u8x8.printf("SF:");
|
||||
if (cfg.adrmode) // if ADR=on then display SF value inverse
|
||||
u8x8.setInverseFont(1);
|
||||
u8x8.printf("%c%c", lora_datarate[LMIC.datarate * 2],
|
||||
lora_datarate[LMIC.datarate * 2 + 1]);
|
||||
if (cfg.adrmode) // switch off inverse if it was turned on
|
||||
u8x8.setInverseFont(0);
|
||||
u8x8.setCursor(11, 3);
|
||||
u8x8.printf("SF:");
|
||||
if (cfg.adrmode) // if ADR=on then display SF value inverse
|
||||
u8x8.setInverseFont(1);
|
||||
u8x8.printf("%c%c", lora_datarate[LMIC.datarate * 2],
|
||||
lora_datarate[LMIC.datarate * 2 + 1]);
|
||||
if (cfg.adrmode) // switch off inverse if it was turned on
|
||||
u8x8.setInverseFont(0);
|
||||
#endif // HAS_LORA
|
||||
|
||||
// update wifi counter + channel display (line 4)
|
||||
u8x8.setCursor(0, 4);
|
||||
u8x8.printf("WIFI:%-4d", macs_wifi);
|
||||
u8x8.setCursor(11, 4);
|
||||
u8x8.printf("ch:%02d", channel);
|
||||
// update wifi counter + channel display (line 4)
|
||||
u8x8.setCursor(0, 4);
|
||||
u8x8.printf("WIFI:%-4d", macs_wifi);
|
||||
u8x8.setCursor(11, 4);
|
||||
u8x8.printf("ch:%02d", channel);
|
||||
|
||||
// update RSSI limiter status & free memory display (line 5)
|
||||
u8x8.setCursor(0, 5);
|
||||
u8x8.printf(!cfg.rssilimit ? "RLIM:off " : "RLIM:%-4d", cfg.rssilimit);
|
||||
u8x8.setCursor(10, 5);
|
||||
u8x8.printf("%4dKB", ESP.getFreeHeap() / 1024);
|
||||
// update RSSI limiter status & free memory display (line 5)
|
||||
u8x8.setCursor(0, 5);
|
||||
u8x8.printf(!cfg.rssilimit ? "RLIM:off " : "RLIM:%-4d", cfg.rssilimit);
|
||||
u8x8.setCursor(10, 5);
|
||||
u8x8.printf("%4dKB", getFreeRAM() / 1024);
|
||||
|
||||
#ifdef HAS_LORA
|
||||
// update LoRa status display (line 6)
|
||||
u8x8.setCursor(0, 6);
|
||||
u8x8.printf("%-16s", display_line6);
|
||||
// update LoRa status display (line 6)
|
||||
u8x8.setCursor(0, 6);
|
||||
u8x8.printf("%-16s", display_line6);
|
||||
|
||||
// update LMiC event display (line 7)
|
||||
u8x8.setCursor(0, 7);
|
||||
u8x8.printf("%-14s", display_line7);
|
||||
// update LMiC event display (line 7)
|
||||
u8x8.setCursor(0, 7);
|
||||
u8x8.printf("%-14s", display_line7);
|
||||
|
||||
// update LoRa send queue display (line 7)
|
||||
msgWaiting = uxQueueMessagesWaiting(LoraSendQueue);
|
||||
if (msgWaiting) {
|
||||
sprintf(buff, "%2d", msgWaiting);
|
||||
u8x8.setCursor(14, 7);
|
||||
u8x8.setInverseFont(1);
|
||||
u8x8.printf("%-2s", msgWaiting == SEND_QUEUE_SIZE ? "<>" : buff);
|
||||
u8x8.setInverseFont(0);
|
||||
} else
|
||||
u8x8.printf(" ");
|
||||
// update LoRa send queue display (line 7)
|
||||
msgWaiting = uxQueueMessagesWaiting(LoraSendQueue);
|
||||
if (msgWaiting) {
|
||||
sprintf(buff, "%2d", msgWaiting);
|
||||
u8x8.setCursor(14, 7);
|
||||
u8x8.printf("%-2s", msgWaiting == SEND_QUEUE_SIZE ? "<>" : buff);
|
||||
} else
|
||||
u8x8.printf(" ");
|
||||
|
||||
#endif // HAS_LORA
|
||||
|
||||
xSemaphoreGive(I2Caccess); // release i2c bus access
|
||||
}
|
||||
|
||||
} // refreshDisplay()
|
||||
|
||||
#endif // HAS_DISPLAY
|
||||
+2
-2
@@ -70,12 +70,12 @@ void gps_loop(void *pvParameters) {
|
||||
Wire.requestFrom(GPS_ADDR, 32); // caution: this is a blocking call
|
||||
while (Wire.available()) {
|
||||
gps.encode(Wire.read());
|
||||
vTaskDelay(2 / portTICK_PERIOD_MS); // 2ms delay according L76 datasheet
|
||||
delay(2); // 2ms delay according L76 datasheet
|
||||
}
|
||||
#endif
|
||||
} // if
|
||||
|
||||
vTaskDelay(2 / portTICK_PERIOD_MS); // yield to CPU
|
||||
delay(2); // yield to CPU
|
||||
|
||||
} // end of infinite loop
|
||||
|
||||
|
||||
+1
-1
@@ -17,8 +17,8 @@
|
||||
|
||||
// enable only if device has these sensors, otherwise comment these lines
|
||||
// BME680 sensor on I2C bus
|
||||
// don't forget to connect SDIO of BME680 to GND for selecting i2c addr 0x76
|
||||
#define HAS_BME GPIO_NUM_21, GPIO_NUM_22 // SDA, SCL
|
||||
#define BME_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
|
||||
|
||||
+5
-12
@@ -12,24 +12,17 @@
|
||||
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
|
||||
#define CFG_sx1276_radio 1
|
||||
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
|
||||
#define HAS_LED (25) // white LED on board
|
||||
#define HAS_BUTTON (0) // button "PROG" on board
|
||||
#define HAS_LED LED_BUILTIN // white LED on board
|
||||
#define HAS_BUTTON KEY_BUILTIN // button "PROG" on board
|
||||
|
||||
// Pins for I2C interface of OLED Display
|
||||
#define MY_OLED_SDA (4)
|
||||
#define MY_OLED_SCL (15)
|
||||
#define MY_OLED_RST (16)
|
||||
#define MY_OLED_SDA OLED_SDA
|
||||
#define MY_OLED_SCL OLED_SCL
|
||||
#define MY_OLED_RST OLED_RST
|
||||
|
||||
// Pins for LORA chip SPI interface come from board file, we need some
|
||||
// additional definitions for LMIC
|
||||
#define LORA_IO1 (33)
|
||||
#define LORA_IO2 LMIC_UNUSED_PIN
|
||||
#define LORA_SCK (5)
|
||||
#define LORA_MOSI (27)
|
||||
#define LORA_MISO (19)
|
||||
#define LORA_CS (18)
|
||||
#define LORA_RST (14)
|
||||
#define LORA_IRQ (26)
|
||||
|
||||
|
||||
#endif
|
||||
+5
-11
@@ -14,23 +14,17 @@
|
||||
#define CFG_sx1276_radio 1
|
||||
|
||||
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
|
||||
#define HAS_LED (25) // white LED on board
|
||||
#define HAS_BUTTON (0) // button "PROG" on board
|
||||
#define HAS_LED LED_BUILTIN // white LED on board
|
||||
#define HAS_BUTTON KEY_BUILTIN // button "PROG" on board
|
||||
|
||||
// Pins for I2C interface of OLED Display
|
||||
#define MY_OLED_SDA (4)
|
||||
#define MY_OLED_SCL (15)
|
||||
#define MY_OLED_RST (16)
|
||||
#define MY_OLED_SDA OLED_SDA
|
||||
#define MY_OLED_SCL OLED_SCL
|
||||
#define MY_OLED_RST OLED_RST
|
||||
|
||||
// Pins for LORA chip SPI interface come from board file, we need some
|
||||
// additional definitions for LMIC
|
||||
#define LORA_IO1 (35)
|
||||
#define LORA_IO2 (34)
|
||||
#define LORA_SCK (5)
|
||||
#define LORA_MOSI (27)
|
||||
#define LORA_MISO (19)
|
||||
#define LORA_CS (18)
|
||||
#define LORA_RST (14)
|
||||
#define LORA_IRQ (26)
|
||||
|
||||
#endif
|
||||
@@ -7,9 +7,8 @@
|
||||
|
||||
// Hardware related definitions for lolin32lite (without LoRa shield)
|
||||
|
||||
#define CFG_sx1272_radio 1 // dummy
|
||||
|
||||
#define HAS_LED (5) // on board LED on GPIO5
|
||||
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
|
||||
#define CFG_sx1272_radio 1 // dummy
|
||||
#define HAS_LED LED_BUILTIN // on board LED on GPIO5
|
||||
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
|
||||
|
||||
#endif
|
||||
+35
-46
@@ -1,46 +1,35 @@
|
||||
// clang-format off
|
||||
|
||||
#ifndef _LOPY_H
|
||||
#define _LOPY_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Hardware related definitions for Pycom LoPy Board (NOT LoPy4)
|
||||
|
||||
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
|
||||
#define CFG_sx1272_radio 1
|
||||
#define HAS_LED NOT_A_PIN // LoPy4 has no on board mono LED, we use on board RGB LED
|
||||
#define HAS_RGB_LED (0) // WS2812B RGB LED on GPIO0
|
||||
|
||||
// Pins for LORA chip SPI interface come from board file, we need some
|
||||
// additional definitions for LMIC
|
||||
#define LORA_SCK 5 // GPIO5 - SX1276 SCK
|
||||
#define LORA_MISO 19 // GPIO19 - SX1276 MISO
|
||||
#define LORA_MOSI 27 // GPIO27 - SX1276 MOSI
|
||||
#define LORA_CS 17 // GPIO17 - SX1276 CS
|
||||
#define LORA_RST 18 // GPIO18 - SX1276 RST
|
||||
#define LORA_IRQ 23 // GPIO23 - SX1276 IO0
|
||||
#define LORA_IO0 LORA_IRQ // alias
|
||||
#define LORA_IO1 LORA_IRQ // tied by diode to IO0
|
||||
#define LORA_IO2 LORA_IRQ // tied by diode to IO0
|
||||
|
||||
|
||||
// select WIFI antenna (internal = onboard / external = u.fl socket)
|
||||
#define HAS_ANTENNA_SWITCH (16) // pin for switching wifi antenna
|
||||
#define WIFI_ANTENNA 0 // 0 = internal, 1 = external
|
||||
|
||||
// uncomment this only if your LoPy runs 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 HAS_BATTERY_PROBE ADC1_GPIO39_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7
|
||||
//#define BATT_FACTOR 2 // voltage divider 1MOhm/1MOhm -> expansion board 3.0
|
||||
//#define BATT_FACTOR 4 // voltage divider 115kOhm/56kOhm -> expansion board 2.0
|
||||
|
||||
#endif
|
||||
// clang-format off
|
||||
|
||||
#ifndef _LOPY_H
|
||||
#define _LOPY_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Hardware related definitions for Pycom LoPy Board (NOT LoPy4)
|
||||
|
||||
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
|
||||
#define CFG_sx1272_radio 1
|
||||
#define HAS_LED NOT_A_PIN // LoPy4 has no on board mono LED, we use on board RGB LED
|
||||
#define HAS_RGB_LED (0) // WS2812B RGB LED on GPIO0
|
||||
|
||||
// Note: Pins for LORA chip SPI interface come from board file pins_arduino.h
|
||||
|
||||
// select WIFI antenna (internal = onboard / external = u.fl socket)
|
||||
#define HAS_ANTENNA_SWITCH (16) // pin for switching wifi antenna
|
||||
#define WIFI_ANTENNA 0 // 0 = internal, 1 = external
|
||||
|
||||
// uncomment this only if your LoPy runs 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 HAS_BATTERY_PROBE ADC1_GPIO39_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7
|
||||
//#define BATT_FACTOR 2 // voltage divider 1MOhm/1MOhm -> expansion board 3.0
|
||||
//#define BATT_FACTOR 4 // voltage divider 115kOhm/56kOhm -> expansion board 2.0
|
||||
|
||||
#endif
|
||||
+43
-53
@@ -1,54 +1,44 @@
|
||||
// clang-format off
|
||||
|
||||
#ifndef _LOPY4_H
|
||||
#define _LOPY4_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Hardware related definitions for Pycom LoPy4 Board
|
||||
|
||||
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
|
||||
|
||||
#define HAS_SPI 1 // comment out if device shall not send data via SPI
|
||||
// pin definitions for local wired SPI slave interface
|
||||
#define SPI_MOSI GPIO_NUM_22
|
||||
#define SPI_MISO GPIO_NUM_33
|
||||
#define SPI_SCLK GPIO_NUM_26
|
||||
#define SPI_CS GPIO_NUM_36
|
||||
|
||||
#define CFG_sx1276_radio 1
|
||||
//#define HAS_LED NOT_A_PIN // LoPy4 has no on board mono LED, we use on board RGB LED
|
||||
#define HAS_RGB_LED (0) // WS2812B RGB LED on GPIO0 (P2)
|
||||
#define BOARD_HAS_PSRAM // use extra 4MB extern RAM
|
||||
|
||||
// Pins for LORA chip SPI interface come from board file, we need some
|
||||
// additional definitions for LMIC
|
||||
#define LORA_SCK 5 // GPIO5 - SX1276 SCK
|
||||
#define LORA_MISO 19 // GPIO19 - SX1276 MISO
|
||||
#define LORA_MOSI 27 // GPIO27 - SX1276 MOSI
|
||||
#define LORA_CS 18 // GPIO18 - SX1276 CS
|
||||
#define LORA_IRQ 23 // GPIO23 - SX1276 IO0
|
||||
#define LORA_IO0 LORA_IRQ // alias
|
||||
#define LORA_IO1 LORA_IRQ // tied by diode to IO0
|
||||
#define LORA_IO2 LORA_IRQ // tied by diode to IO0
|
||||
#define LORA_RST NOT_A_PIN
|
||||
|
||||
// select WIFI antenna (internal = onboard / external = u.fl socket)
|
||||
#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
|
||||
//#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 HAS_BATTERY_PROBE ADC1_GPIO39_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7
|
||||
#define BATT_FACTOR 2 // voltage divider 1MOhm/1MOhm -> expansion board 3.0
|
||||
//#define BATT_FACTOR 4 // voltage divider 115kOhm/56kOhm -> expansion board 2.0
|
||||
|
||||
// clang-format off
|
||||
|
||||
#ifndef _LOPY4_H
|
||||
#define _LOPY4_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Hardware related definitions for Pycom LoPy4 Board
|
||||
|
||||
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
|
||||
|
||||
//#defin HAS_SPI 1 // comment out if device shall not send data via SPI
|
||||
// pin definitions for local wired SPI slave interface
|
||||
//#define SPI_MOSI GPIO_NUM_22
|
||||
//#define SPI_MISO GPIO_NUM_33
|
||||
//#define SPI_SCLK GPIO_NUM_26
|
||||
//#define SPI_CS GPIO_NUM_36
|
||||
|
||||
#define CFG_sx1276_radio 1
|
||||
//#define HAS_LED NOT_A_PIN // LoPy4 has no on board mono LED, we use on board RGB LED
|
||||
#define HAS_RGB_LED (0) // WS2812B RGB LED on GPIO0 (P2)
|
||||
#define BOARD_HAS_PSRAM // use extra 4MB extern RAM
|
||||
|
||||
// Note: Pins for LORA chip SPI interface come from board file pins_arduino.h
|
||||
|
||||
// select WIFI antenna (internal = onboard / external = u.fl socket)
|
||||
#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
|
||||
//#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 HAS_BATTERY_PROBE ADC1_GPIO39_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7
|
||||
#define BATT_FACTOR 2 // voltage divider 1MOhm/1MOhm -> expansion board 3.0
|
||||
//#define BATT_FACTOR 4 // voltage divider 115kOhm/56kOhm -> expansion board 2.0
|
||||
|
||||
#endif
|
||||
+1
-3
@@ -11,11 +11,9 @@
|
||||
// disable brownout detection (avoid unexpected reset on some boards)
|
||||
#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
|
||||
|
||||
// enable only if device has these sensors, otherwise comment these lines
|
||||
// BME680 sensor on I2C bus
|
||||
// Octopus32 has a pre-populated BME680 on i2c addr 0x76
|
||||
#define HAS_BME GPIO_NUM_23, GPIO_NUM_22 // SDA, SCL
|
||||
//#define HAS_BME 0x76
|
||||
#define BME_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
|
||||
|
||||
@@ -6,41 +6,37 @@
|
||||
#include <stdint.h>
|
||||
|
||||
// Hardware related definitions for TTGO T-Beam board
|
||||
// (only) for older T-Beam version T22_V05 eternal wiring LORA_IO1 to GPIO33 is needed!
|
||||
//
|
||||
// pinouts taken from http://tinymicros.com/wiki/TTGO_T-Beam
|
||||
//
|
||||
// enable only if device has these sensors, otherwise comment these lines
|
||||
// BME680 sensor on I2C bus
|
||||
// don't forget to connect SDIO of BME680 to GND for selecting i2c addr 0x76
|
||||
//
|
||||
//#define HAS_BME GPIO_NUM_21, GPIO_NUM_22 // SDA, SCL
|
||||
|
||||
#define HAS_LED GPIO_NUM_14 // on board green LED
|
||||
|
||||
// user defined sensors
|
||||
//#define HAS_SENSORS 1 // comment out if device has user defined sensors
|
||||
#define HAS_LED GPIO_NUM_14 // on board green LED, only new version TTGO-BEAM V07
|
||||
//#define HAS_LED GPIO_NUM_21 // on board green LED, only old verison TTGO-BEAM V05
|
||||
|
||||
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
|
||||
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC
|
||||
#define BOARD_HAS_PSRAM // use extra 4MB external RAM
|
||||
|
||||
//#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
|
||||
|
||||
#define HAS_BUTTON GPIO_NUM_39 // on board button "SW5"
|
||||
|
||||
#define HAS_BUTTON GPIO_NUM_39 // on board button (next to reset)
|
||||
#define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7
|
||||
#define BATT_FACTOR 2 // voltage divider 100k/100k on board
|
||||
#define HAS_GPS 1 // use on board GPS
|
||||
#define GPS_SERIAL 9600, SERIAL_8N1, GPIO_NUM_12, GPIO_NUM_15 // UBlox NEO 6M or 7M with default configuration
|
||||
|
||||
// Pins for LORA chip SPI interface, reset line and interrupt lines
|
||||
#define LORA_SCK (5)
|
||||
#define LORA_CS (18)
|
||||
#define LORA_MISO (19)
|
||||
#define LORA_MOSI (27)
|
||||
#define LORA_RST (23)
|
||||
#define LORA_IRQ (26)
|
||||
#define LORA_IO1 (33) // for T-Beam T22_V05 and T22_V07, for other versions use ttgobeam_old.h
|
||||
#define LORA_IO2 (32)
|
||||
// enable only if device has these sensors, otherwise comment these lines
|
||||
// BME680 sensor on I2C bus
|
||||
//#define HAS_BME GPIO_NUM_21, GPIO_NUM_22 // SDA, SCL
|
||||
//#define BME_ADDR BME680_I2C_ADDR_PRIMARY // connect SDIO of BME680 to GND
|
||||
|
||||
// display (if connected)
|
||||
//#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C
|
||||
//#define MY_OLED_SDA (21)
|
||||
//#define MY_OLED_SCL (22)
|
||||
//#define MY_OLED_RST U8X8_PIN_NONE
|
||||
//#define 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
|
||||
@@ -1,45 +0,0 @@
|
||||
// clang-format off
|
||||
|
||||
#ifndef _TTGOBEAM_H
|
||||
#define _TTGOBEAM_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Hardware related definitions for TTGO T-Beam board
|
||||
|
||||
// enable only if device has these sensors, otherwise comment these lines
|
||||
// BME680 sensor on I2C bus
|
||||
// attention: Pin21 is also LED! set HAS_LED to NOT_A_PIN if using BME280
|
||||
// don't forget to connect SDIO of BME680 to GND for selecting i2c addr 0x76
|
||||
//#define HAS_BME GPIO_NUM_21, GPIO_NUM_22 // SDA, SCL
|
||||
//#define HAS_LED NOT_A_PIN // on board green LED
|
||||
|
||||
#define HAS_LED GPIO_NUM_21 // on board green LED
|
||||
|
||||
// user defined sensors
|
||||
//#define HAS_SENSORS 1 // comment out if device has user defined sensors
|
||||
|
||||
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
|
||||
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC
|
||||
#define BOARD_HAS_PSRAM // use extra 4MB external RAM
|
||||
|
||||
//#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
|
||||
|
||||
#define HAS_BUTTON GPIO_NUM_39 // on board button "BOOT" (next to reset button)
|
||||
|
||||
#define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7
|
||||
#define BATT_FACTOR 2 // voltage divider 100k/100k on board
|
||||
#define HAS_GPS 1 // use on board GPS
|
||||
#define GPS_SERIAL 9600, SERIAL_8N1, GPIO_NUM_12, GPIO_NUM_15 // UBlox NEO 6M or 7M with default configuration
|
||||
|
||||
// Pins for LORA chip SPI interface, reset line and interrupt lines
|
||||
#define LORA_SCK (5)
|
||||
#define LORA_CS (18)
|
||||
#define LORA_MISO (19)
|
||||
#define LORA_MOSI (27)
|
||||
#define LORA_RST LMIC_UNUSED_PIN
|
||||
#define LORA_IRQ (26)
|
||||
#define LORA_IO1 (32) // !! NEEDS EXTERNAL WIRING !!
|
||||
#define LORA_IO2 LMIC_UNUSED_PIN
|
||||
|
||||
#endif
|
||||
+7
-12
@@ -12,22 +12,17 @@
|
||||
|
||||
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board
|
||||
//#define DISPLAY_FLIP 1 // uncomment this for rotated display
|
||||
#define HAS_LED (2) // white LED on board
|
||||
#define HAS_LED LED_BUILTIN
|
||||
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
|
||||
#define HAS_BUTTON (0) // button "PRG" on board
|
||||
#define HAS_BUTTON KEY_BUILTIN
|
||||
|
||||
// Pins for I2C interface of OLED Display
|
||||
#define MY_OLED_SDA (4)
|
||||
#define MY_OLED_SCL (15)
|
||||
#define MY_OLED_RST (16)
|
||||
#define MY_OLED_SDA OLED_SDA
|
||||
#define MY_OLED_SCL OLED_SCL
|
||||
#define MY_OLED_RST OLED_RST
|
||||
|
||||
// Pins for LORA chip SPI interface, reset line and interrupt lines
|
||||
#define LORA_SCK (5)
|
||||
#define LORA_CS (18)
|
||||
#define LORA_MISO (19)
|
||||
#define LORA_MOSI (27)
|
||||
#define LORA_RST (14)
|
||||
#define LORA_IRQ (26)
|
||||
// Pins for LORA chip SPI interface come from board file, we need some
|
||||
// additional definitions for LMIC
|
||||
#define LORA_IO1 (33)
|
||||
#define LORA_IO2 LMIC_UNUSED_PIN
|
||||
|
||||
|
||||
+4
-8
@@ -18,17 +18,13 @@
|
||||
#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
|
||||
|
||||
// Pins for I2C interface of OLED Display
|
||||
#define MY_OLED_SDA (21)
|
||||
#define MY_OLED_SCL (22)
|
||||
#define MY_OLED_SDA OLED_SDA
|
||||
#define MY_OLED_SCL OLED_SCL
|
||||
#define MY_OLED_RST U8X8_PIN_NONE
|
||||
|
||||
// Pins for LORA chip SPI interface, reset line and interrupt lines
|
||||
#define LORA_SCK (5)
|
||||
#define LORA_CS (18)
|
||||
#define LORA_MISO (19)
|
||||
#define LORA_MOSI (27)
|
||||
// Pins for LORA chip SPI interface come from board file, we need some
|
||||
// additional definitions for LMIC
|
||||
#define LORA_RST LMIC_UNUSED_PIN
|
||||
#define LORA_IRQ (26)
|
||||
#define LORA_IO1 (33)
|
||||
#define LORA_IO2 LMIC_UNUSED_PIN
|
||||
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ void IRAM_ATTR SendCycleIRQ() {
|
||||
|
||||
#ifdef HAS_DISPLAY
|
||||
void IRAM_ATTR DisplayIRQ() {
|
||||
xTaskNotifyFromISR(irqHandlerTask, DISPLAY_IRQ, eSetBits, NULL);
|
||||
xTaskNotifyFromISR(irqHandlerTask, DISPLAY_IRQ, eSetBits, NULL);
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -190,7 +190,7 @@ void ledLoop(void *parameter) {
|
||||
previousLEDState = LEDState;
|
||||
}
|
||||
// give yield to CPU
|
||||
vTaskDelay(2 / portTICK_PERIOD_MS);
|
||||
delay(2);
|
||||
} // while(1)
|
||||
vTaskDelete(ledLoopTask); // shoud never be reached
|
||||
}; // ledloop()
|
||||
|
||||
+5
-3
@@ -22,7 +22,7 @@
|
||||
//#define LMIC_USE_INTERRUPTS
|
||||
|
||||
//time sync via LoRaWAN network, is not yet supported by TTN (LoRaWAN spec v1.0.3)
|
||||
#define LMIC_ENABLE_DeviceTimeReq 1
|
||||
//#define LMIC_ENABLE_DeviceTimeReq 1
|
||||
|
||||
// 16 μs per tick
|
||||
// LMIC requires ticks to be 15.5μs - 100 μs long
|
||||
@@ -34,7 +34,7 @@
|
||||
// faster or slower. This causes the transceiver to be earlier switched on,
|
||||
// so consuming more power. You may sharpen (reduce) this value if you are
|
||||
// limited on battery.
|
||||
#define CLOCK_ERROR_PROCENTAGE 20
|
||||
#define CLOCK_ERROR_PROCENTAGE 3
|
||||
|
||||
// Set this to 1 to enable some basic debug output (using printf) about
|
||||
// RF settings used during transmission and reception. Set to 2 to
|
||||
@@ -89,10 +89,12 @@
|
||||
// implementation is optimized for speed on 32-bit processors using
|
||||
// fairly big lookup tables, but it takes up big amounts of flash on the
|
||||
// AVR architecture.
|
||||
#define USE_ORIGINAL_AES
|
||||
//#define USE_ORIGINAL_AES
|
||||
//
|
||||
// This selects the AES implementation written by Ideetroon for their
|
||||
// own LoRaWAN library. It also uses lookup tables, but smaller
|
||||
// byte-oriented ones, making it use a lot less flash space (but it is
|
||||
// also about twice as slow as the original).
|
||||
// #define USE_IDEETRON_AES
|
||||
//
|
||||
#define USE_MBEDTLS_AES
|
||||
@@ -222,13 +222,6 @@ void onEvent(ev_t ev) {
|
||||
: PSTR("TX_COMPLETE"));
|
||||
sprintf(display_line6, " "); // clear previous lmic status
|
||||
|
||||
// if (LMIC.dataLen) {
|
||||
// ESP_LOGI(TAG, "Received %d bytes of payload, RSSI %d SNR %d",
|
||||
// LMIC.dataLen, (signed char)LMIC.rssi, (signed
|
||||
// char)LMIC.snr);
|
||||
// sprintf(display_line6, "RSSI %d SNR %d", (signed char)LMIC.rssi,
|
||||
// (signed char)LMIC.snr);
|
||||
|
||||
if (LMIC.dataLen) {
|
||||
ESP_LOGI(TAG, "Received %d bytes of payload, RSSI -%d SNR %d",
|
||||
LMIC.dataLen, LMIC.rssi, LMIC.snr / 4);
|
||||
|
||||
+2
-1
@@ -119,7 +119,8 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
|
||||
"%d Bytes left",
|
||||
added ? "new " : "known",
|
||||
sniff_type == MAC_SNIFF_WIFI ? "WiFi" : "BLTH", rssi, buff,
|
||||
hashedmac, macs_wifi, macs_ble, ESP.getFreeHeap());
|
||||
hashedmac, macs_wifi, macs_ble, getFreeRAM());
|
||||
|
||||
#ifdef VENDORFILTER
|
||||
} else {
|
||||
// Very noisy
|
||||
|
||||
+73
-38
@@ -35,9 +35,14 @@ IDLE 0 0 ESP32 arduino scheduler -> runs wifi sniffer
|
||||
looptask 1 1 arduino core -> runs the LMIC LoRa stack
|
||||
irqhandler 1 1 executes tasks triggered by irq
|
||||
gpsloop 1 2 reads data from GPS via serial or i2c
|
||||
bmeloop 1 2 reads data from BME sensor via i2c
|
||||
bmeloop 1 1 reads data from BME sensor via i2c
|
||||
IDLE 1 0 ESP32 arduino scheduler
|
||||
|
||||
Low priority numbers denote low priority tasks.
|
||||
|
||||
Tasks using i2c bus all must have same priority, because using mutex semaphore
|
||||
(irqhandler, bmeloop)
|
||||
|
||||
ESP32 hardware timers
|
||||
==========================
|
||||
0 Trigger display refresh
|
||||
@@ -55,12 +60,14 @@ char display_line6[16], display_line7[16]; // display buffers
|
||||
uint8_t volatile channel = 0; // channel rotation counter
|
||||
uint16_t volatile macs_total = 0, macs_wifi = 0, macs_ble = 0,
|
||||
batt_voltage = 0; // globals for display
|
||||
|
||||
hw_timer_t *channelSwitch = NULL, *sendCycle = NULL, *homeCycle = NULL,
|
||||
*displaytimer = NULL; // irq tasks
|
||||
TaskHandle_t irqHandlerTask, wifiSwitchTask;
|
||||
SemaphoreHandle_t I2Caccess;
|
||||
|
||||
std::set<uint16_t> macs; // container holding unique MAC adress hashes
|
||||
// container holding unique MAC address hashes with Memory Alloctor using PSRAM,
|
||||
// if present
|
||||
std::set<uint16_t, std::less<uint16_t>, Mallocator<uint16_t>> macs;
|
||||
|
||||
// initialize payload encoder
|
||||
PayloadConvert payload(PAYLOAD_BUFFER_SIZE);
|
||||
@@ -75,6 +82,14 @@ void setup() {
|
||||
|
||||
char features[100] = "";
|
||||
|
||||
if (I2Caccess == NULL) // Check that semaphore has not already been created
|
||||
{
|
||||
I2Caccess = xSemaphoreCreateMutex(); // Create a mutex semaphore we will use
|
||||
// to manage the i2c bus
|
||||
if ((I2Caccess) != NULL)
|
||||
xSemaphoreGive((I2Caccess)); // Flag the i2c bus available for use
|
||||
}
|
||||
|
||||
// disable brownout detection
|
||||
#ifdef DISABLE_BROWNOUT
|
||||
// register with brownout is at address DR_REG_RTCCNTL_BASE + 0xd4
|
||||
@@ -105,8 +120,17 @@ void setup() {
|
||||
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());
|
||||
ESP_LOGI(TAG, "Free RAM: %d bytes", ESP.getFreeHeap());
|
||||
ESP_LOGI(TAG, "Internal Total heap %d, internal Free Heap %d",
|
||||
ESP.getHeapSize(), ESP.getFreeHeap());
|
||||
#ifdef BOARD_HAS_PSRAM
|
||||
ESP_LOGI(TAG, "SPIRam Total heap %d, SPIRam Free Heap %d", ESP.getPsramSize(),
|
||||
ESP.getFreePsram());
|
||||
#endif
|
||||
ESP_LOGI(TAG, "ChipRevision %d, Cpu Freq %d, SDK Version %s",
|
||||
ESP.getChipRevision(), ESP.getCpuFreqMHz(), ESP.getSdkVersion());
|
||||
ESP_LOGI(TAG, "Flash Size %d, Flash Speed %d", ESP.getFlashChipSize(),
|
||||
ESP.getFlashChipSpeed());
|
||||
ESP_LOGI(TAG, "Wifi/BT software coexist version: %s", esp_coex_version_get());
|
||||
|
||||
#ifdef HAS_GPS
|
||||
ESP_LOGI(TAG, "TinyGPS+ v%s", TinyGPSPlus::libraryVersion());
|
||||
@@ -117,6 +141,12 @@ void setup() {
|
||||
// read (and initialize on first run) runtime settings from NVRAM
|
||||
loadConfig(); // includes initialize if necessary
|
||||
|
||||
#ifdef BOARD_HAS_PSRAM
|
||||
assert(psramFound());
|
||||
ESP_LOGI(TAG, "PSRAM found and initialized");
|
||||
strcat_P(features, " PSRAM");
|
||||
#endif
|
||||
|
||||
// initialize leds
|
||||
#if (HAS_LED != NOT_A_PIN)
|
||||
pinMode(HAS_LED, OUTPUT);
|
||||
@@ -148,13 +178,6 @@ void setup() {
|
||||
antenna_select(cfg.wifiant);
|
||||
#endif
|
||||
|
||||
// switch off bluetooth, if not compiled
|
||||
#ifdef BLECOUNTER
|
||||
strcat_P(features, " BLE");
|
||||
#else
|
||||
bool btstop = btStop();
|
||||
#endif
|
||||
|
||||
// initialize battery status
|
||||
#ifdef HAS_BATTERY_PROBE
|
||||
strcat_P(features, " BATT");
|
||||
@@ -172,7 +195,27 @@ void setup() {
|
||||
}
|
||||
#endif
|
||||
|
||||
// initialize button
|
||||
// start BLE scan callback if BLE function is enabled in NVRAM configuration
|
||||
// or switch off bluetooth, if not compiled
|
||||
#ifdef BLECOUNTER
|
||||
strcat_P(features, " BLE");
|
||||
if (cfg.blescan) {
|
||||
ESP_LOGI(TAG, "Starting Bluetooth...");
|
||||
start_BLEscan();
|
||||
} else
|
||||
btStop();
|
||||
#else
|
||||
// remove bluetooth stack to gain more free memory
|
||||
ESP_ERROR_CHECK(esp_bluedroid_disable());
|
||||
ESP_ERROR_CHECK(esp_bluedroid_deinit());
|
||||
btStop();
|
||||
ESP_ERROR_CHECK(esp_bt_controller_deinit());
|
||||
ESP_ERROR_CHECK(esp_bt_mem_release(ESP_BT_MODE_BTDM));
|
||||
ESP_ERROR_CHECK(esp_coex_preference_set((
|
||||
esp_coex_prefer_t)ESP_COEX_PREFER_WIFI)); // configure Wifi/BT coexist lib
|
||||
#endif
|
||||
|
||||
// initialize button
|
||||
#ifdef HAS_BUTTON
|
||||
strcat_P(features, " BTN_");
|
||||
#ifdef BUTTON_PULLUP
|
||||
@@ -201,21 +244,6 @@ void setup() {
|
||||
}
|
||||
#endif
|
||||
|
||||
// initialize bme
|
||||
#ifdef HAS_BME
|
||||
strcat_P(features, " BME");
|
||||
if (bme_init()) {
|
||||
ESP_LOGI(TAG, "Starting BMEloop...");
|
||||
xTaskCreatePinnedToCore(bme_loop, // task function
|
||||
"bmeloop", // name of task
|
||||
4096, // stack size of task
|
||||
(void *)1, // parameter of the task
|
||||
2, // priority of the task
|
||||
&BmeTask, // task handle
|
||||
1); // CPU core
|
||||
}
|
||||
#endif
|
||||
|
||||
// initialize sensors
|
||||
#ifdef HAS_SENSORS
|
||||
strcat_P(features, " SENS");
|
||||
@@ -290,14 +318,6 @@ void setup() {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// start BLE scan callback if BLE function is enabled in NVRAM configuration
|
||||
#ifdef BLECOUNTER
|
||||
if (cfg.blescan) {
|
||||
ESP_LOGI(TAG, "Starting Bluetooth...");
|
||||
start_BLEscan();
|
||||
}
|
||||
#endif
|
||||
|
||||
// start wifi in monitor mode and start channel rotation task on core 0
|
||||
ESP_LOGI(TAG, "Starting Wifi...");
|
||||
wifi_sniffer_init();
|
||||
@@ -310,7 +330,7 @@ void setup() {
|
||||
ESP_LOGI(TAG, "Starting IRQ Handler...");
|
||||
xTaskCreatePinnedToCore(irqHandler, // task function
|
||||
"irqhandler", // name of task
|
||||
2048, // stack size of task
|
||||
4096, // stack size of task
|
||||
(void *)1, // parameter of the task
|
||||
1, // priority of the task
|
||||
&irqHandlerTask, // task handle
|
||||
@@ -326,6 +346,21 @@ void setup() {
|
||||
&wifiSwitchTask, // task handle
|
||||
0); // CPU core
|
||||
|
||||
// initialize bme
|
||||
#ifdef HAS_BME
|
||||
strcat_P(features, " BME");
|
||||
if (bme_init()) {
|
||||
ESP_LOGI(TAG, "Starting BMEloop...");
|
||||
xTaskCreatePinnedToCore(bme_loop, // task function
|
||||
"bmeloop", // name of task
|
||||
2048, // stack size of task
|
||||
(void *)1, // parameter of the task
|
||||
1, // priority of the task
|
||||
&BmeTask, // task handle
|
||||
1); // CPU core
|
||||
}
|
||||
#endif
|
||||
|
||||
// start timer triggered interrupts
|
||||
ESP_LOGI(TAG, "Starting Interrupts...");
|
||||
#ifdef HAS_DISPLAY
|
||||
@@ -352,7 +387,7 @@ void loop() {
|
||||
#ifdef HAS_LORA
|
||||
os_runloop_once(); // execute lmic scheduled jobs and events
|
||||
#endif
|
||||
vTaskDelay(2 / portTICK_PERIOD_MS); // yield to CPU
|
||||
delay(2); // yield to CPU
|
||||
}
|
||||
|
||||
vTaskDelete(NULL); // shoud never be reached
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*******************************************************************************
|
||||
*
|
||||
* ttn-esp32 - The Things Network device library for ESP-IDF / SX127x
|
||||
*
|
||||
* Copyright (c) 2018 Manuel Bleichenbacher
|
||||
*
|
||||
* Licensed under MIT License
|
||||
* https://opensource.org/licenses/MIT
|
||||
*
|
||||
* AES encryption using ESP32's hardware AES unit.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "mbedtls/aes.h"
|
||||
#include "lmic/oslmic.h"
|
||||
|
||||
#if defined(USE_MBEDTLS_AES)
|
||||
|
||||
void lmic_aes_encrypt(u1_t *data, u1_t *key)
|
||||
{
|
||||
mbedtls_aes_context ctx;
|
||||
mbedtls_aes_init(&ctx);
|
||||
mbedtls_aes_setkey_enc(&ctx, key, 128);
|
||||
mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT, data, data);
|
||||
mbedtls_aes_free(&ctx);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
+3
-3
@@ -77,7 +77,7 @@ void start_ota_update() {
|
||||
while (i--) {
|
||||
ESP_LOGI(TAG, "Trying to connect to %s, attempt %u of %u", WIFI_SSID,
|
||||
WIFI_MAX_TRY - i, WIFI_MAX_TRY);
|
||||
vTaskDelay(10000 / portTICK_PERIOD_MS); // wait for stable connect
|
||||
delay(10000); // wait for stable connect
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
// we now have wifi connection and try to do an OTA over wifi update
|
||||
ESP_LOGI(TAG, "Connected to %s", WIFI_SSID);
|
||||
@@ -98,13 +98,13 @@ void start_ota_update() {
|
||||
// wifi did not connect
|
||||
ESP_LOGI(TAG, "Could not connect to %s", WIFI_SSID);
|
||||
display(1, " E", "no WiFi connect");
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
delay(5000);
|
||||
|
||||
end:
|
||||
switch_LED(LED_OFF);
|
||||
ESP_LOGI(TAG, "Rebooting to %s firmware", (ret == 0) ? "new" : "current");
|
||||
display(5, "**", ""); // mark line rebooting
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
delay(5000);
|
||||
ESP.restart();
|
||||
|
||||
} // start_ota_update
|
||||
|
||||
+3
-2
@@ -15,7 +15,7 @@
|
||||
|
||||
// Set this to include BLE counting and vendor filter functions
|
||||
#define VENDORFILTER 1 // comment out if you want to count things, not people
|
||||
#define BLECOUNTER 1 // comment out if you don't want BLE count, saves power & memory
|
||||
#define BLECOUNTER 1 // activate if you want to use BLE count, at expense of memory
|
||||
|
||||
// BLE scan parameters
|
||||
#define BLESCANTIME 0 // [seconds] scan duration, 0 means infinite [default], see note below
|
||||
@@ -72,9 +72,10 @@
|
||||
|
||||
// Settings for BME680 environmental sensor (if present)
|
||||
#define BME_TEMP_OFFSET 5.0f // Offset sensor on chip temp <-> ambient temp [default = 5°C]
|
||||
#define STATE_SAVE_PERIOD UINT32_C(360 * 60 * 1000) // update every 360 minutes = 4 times a day
|
||||
|
||||
// OTA settings
|
||||
//#define USE_OTA 1 // Comment out to disable OTA update
|
||||
#define USE_OTA 1 // Comment out to disable OTA update
|
||||
#define WIFI_MAX_TRY 5 // maximum number of wifi connect attempts for OTA update [default = 20]
|
||||
#define OTA_MAX_TRY 5 // maximum number of attempts for OTA download and write to flash [default = 3]
|
||||
#define OTA_MIN_BATT 3600 // minimum battery level for OTA [millivolt]
|
||||
|
||||
+22
-21
@@ -18,11 +18,9 @@ uint8_t *PayloadConvert::getBuffer(void) { return buffer; }
|
||||
|
||||
#if PAYLOAD_ENCODER == 1
|
||||
|
||||
void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
|
||||
buffer[cursor++] = highByte(value1);
|
||||
buffer[cursor++] = lowByte(value1);
|
||||
buffer[cursor++] = highByte(value2);
|
||||
buffer[cursor++] = lowByte(value2);
|
||||
void PayloadConvert::addCount(uint16_t value, uint8_t snifftype) {
|
||||
buffer[cursor++] = highByte(value);
|
||||
buffer[cursor++] = lowByte(value);
|
||||
}
|
||||
|
||||
void PayloadConvert::addAlarm(int8_t rssi, uint8_t msg) {
|
||||
@@ -135,10 +133,7 @@ void PayloadConvert::addButton(uint8_t value) {
|
||||
|
||||
#elif PAYLOAD_ENCODER == 2
|
||||
|
||||
void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
|
||||
writeUint16(value1);
|
||||
writeUint16(value2);
|
||||
}
|
||||
void PayloadConvert::addCount(uint16_t value, uint8_t snifftype) { writeUint16(value); }
|
||||
|
||||
void PayloadConvert::addAlarm(int8_t rssi, uint8_t msg) {
|
||||
writeUint8(rssi);
|
||||
@@ -286,21 +281,27 @@ void PayloadConvert::writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f,
|
||||
|
||||
#elif (PAYLOAD_ENCODER == 3 || PAYLOAD_ENCODER == 4)
|
||||
|
||||
void PayloadConvert::addCount(uint16_t value1, uint16_t value2) {
|
||||
void PayloadConvert::addCount(uint16_t value, uint8_t snifftype) {
|
||||
switch(snifftype) {
|
||||
case MAC_SNIFF_WIFI:
|
||||
#if (PAYLOAD_ENCODER == 3)
|
||||
buffer[cursor++] = LPP_COUNT_WIFI_CHANNEL;
|
||||
buffer[cursor++] = LPP_COUNT_WIFI_CHANNEL;
|
||||
#endif
|
||||
buffer[cursor++] =
|
||||
LPP_LUMINOSITY; // workaround since cayenne has no data type meter
|
||||
buffer[cursor++] = highByte(value1);
|
||||
buffer[cursor++] = lowByte(value1);
|
||||
buffer[cursor++] =
|
||||
LPP_LUMINOSITY; // workaround since cayenne has no data type meter
|
||||
buffer[cursor++] = highByte(value);
|
||||
buffer[cursor++] = lowByte(value);
|
||||
break;
|
||||
case MAC_SNIFF_BLE:
|
||||
#if (PAYLOAD_ENCODER == 3)
|
||||
buffer[cursor++] = LPP_COUNT_BLE_CHANNEL;
|
||||
buffer[cursor++] = LPP_COUNT_BLE_CHANNEL;
|
||||
#endif
|
||||
buffer[cursor++] =
|
||||
LPP_LUMINOSITY; // workaround since cayenne has no data type meter
|
||||
buffer[cursor++] = highByte(value2);
|
||||
buffer[cursor++] = lowByte(value2);
|
||||
buffer[cursor++] =
|
||||
LPP_LUMINOSITY; // workaround since cayenne has no data type meter
|
||||
buffer[cursor++] = highByte(value);
|
||||
buffer[cursor++] = lowByte(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PayloadConvert::addAlarm(int8_t rssi, uint8_t msg) {
|
||||
@@ -317,7 +318,7 @@ void PayloadConvert::addAlarm(int8_t rssi, uint8_t msg) {
|
||||
}
|
||||
|
||||
void PayloadConvert::addVoltage(uint16_t value) {
|
||||
uint16_t volt = value / 10;
|
||||
uint16_t volt = value / 10;
|
||||
#if (PAYLOAD_ENCODER == 3)
|
||||
buffer[cursor++] = LPP_BATT_CHANNEL;
|
||||
#endif
|
||||
|
||||
+2
-6
@@ -9,7 +9,7 @@ static const char TAG[] = "main";
|
||||
void do_reset() {
|
||||
ESP_LOGI(TAG, "Remote command: restart device");
|
||||
LMIC_shutdown();
|
||||
vTaskDelay(3000 / portTICK_PERIOD_MS);
|
||||
delay(3000);
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
@@ -79,13 +79,11 @@ void set_blescantime(uint8_t val[]) {
|
||||
cfg.blescantime = val[0];
|
||||
ESP_LOGI(TAG, "Remote command: set BLE scan time to %.1f seconds",
|
||||
cfg.blescantime / float(100));
|
||||
#ifdef BLECOUNTER
|
||||
// stop & restart BLE scan task to apply new parameter
|
||||
if (cfg.blescan) {
|
||||
stop_BLEscan();
|
||||
start_BLEscan();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_countmode(uint8_t val[]) {
|
||||
@@ -193,14 +191,12 @@ void set_loraadr(uint8_t val[]) {
|
||||
void set_blescan(uint8_t val[]) {
|
||||
ESP_LOGI(TAG, "Remote command: set BLE scanner to %s", val[0] ? "on" : "off");
|
||||
cfg.blescan = val[0] ? 1 : 0;
|
||||
#ifdef BLECOUNTER
|
||||
if (cfg.blescan)
|
||||
start_BLEscan();
|
||||
else {
|
||||
macs_ble = 0; // clear BLE counter
|
||||
stop_BLEscan();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_wifiant(uint8_t val[]) {
|
||||
@@ -249,7 +245,7 @@ void get_status(uint8_t val[]) {
|
||||
#endif
|
||||
payload.reset();
|
||||
payload.addStatus(voltage, uptime() / 1000, temperatureRead(),
|
||||
ESP.getFreeHeap(), rtc_get_reset_reason(0),
|
||||
getFreeRAM(), rtc_get_reset_reason(0),
|
||||
rtc_get_reset_reason(1));
|
||||
SendPayload(STATUSPORT);
|
||||
};
|
||||
|
||||
+15
-1
@@ -40,7 +40,21 @@ void sendCounter() {
|
||||
|
||||
case COUNT_DATA:
|
||||
payload.reset();
|
||||
payload.addCount(macs_wifi, cfg.blescan ? macs_ble : 0);
|
||||
payload.addCount(macs_wifi, MAC_SNIFF_WIFI);
|
||||
if (cfg.blescan)
|
||||
payload.addCount(macs_ble, MAC_SNIFF_BLE);
|
||||
|
||||
#ifdef HAS_GPS
|
||||
if (gps.location.isValid()) { // send GPS position only if we have a fix
|
||||
gps_read();
|
||||
payload.addGPS(gps_status);
|
||||
} else {
|
||||
ESP_LOGD(
|
||||
TAG,
|
||||
"No valid GPS position. GPS data not appended to counter data.");
|
||||
}
|
||||
#endif
|
||||
|
||||
SendPayload(COUNTERPORT);
|
||||
// clear counter if not in cumulative counter mode
|
||||
if (cfg.countermode != 1) {
|
||||
|
||||
@@ -31,6 +31,8 @@ uint8_t sensor_mask(uint8_t sensor_no) {
|
||||
return (uint8_t)MEMS_DATA;
|
||||
case 7:
|
||||
return (uint8_t)ALARM_DATA;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -87,8 +87,7 @@ void spi_slave_task(void *param) {
|
||||
// wait until spi master clocks out the data, and read results in rx buffer
|
||||
ESP_LOGI(TAG, "Prepared SPI transaction for %zu byte(s)", transaction_size);
|
||||
ESP_LOG_BUFFER_HEXDUMP(TAG, txbuf, transaction_size, ESP_LOG_DEBUG);
|
||||
esp_err_t ret =
|
||||
spi_slave_transmit(HSPI_HOST, &spi_transaction, portMAX_DELAY);
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(spi_slave_transmit(HSPI_HOST, &spi_transaction, portMAX_DELAY));
|
||||
ESP_LOG_BUFFER_HEXDUMP(TAG, rxbuf, transaction_size, ESP_LOG_DEBUG);
|
||||
ESP_LOGI(TAG, "Transaction finished with size %zu bits",
|
||||
spi_transaction.trans_len);
|
||||
|
||||
+7
-2
@@ -1,6 +1,8 @@
|
||||
// Basic Config
|
||||
#include "globals.h"
|
||||
#include "wifiscan.h"
|
||||
#include <esp_coexist.h>
|
||||
#include "coexist_internal.h"
|
||||
|
||||
// Local logging tag
|
||||
static const char TAG[] = "wifi";
|
||||
@@ -27,7 +29,7 @@ typedef struct {
|
||||
// using IRAM_:ATTR here to speed up callback function
|
||||
IRAM_ATTR void wifi_sniffer_packet_handler(void *buff,
|
||||
wifi_promiscuous_pkt_type_t type) {
|
||||
|
||||
|
||||
const wifi_promiscuous_pkt_t *ppkt = (wifi_promiscuous_pkt_t *)buff;
|
||||
const wifi_ieee80211_packet_t *ipkt =
|
||||
(wifi_ieee80211_packet_t *)ppkt->payload;
|
||||
@@ -49,6 +51,9 @@ void wifi_sniffer_init(void) {
|
||||
// .filter_mask = WIFI_PROMIS_FILTER_MASK_MGMT}; // only MGMT frames
|
||||
.filter_mask = WIFI_PROMIS_FILTER_MASK_ALL}; // we use all frames
|
||||
|
||||
ESP_ERROR_CHECK(esp_coex_preference_set(
|
||||
ESP_COEX_PREFER_BALANCE)); // configure Wifi/BT coexist lib
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg)); // configure Wifi with cfg
|
||||
ESP_ERROR_CHECK(
|
||||
esp_wifi_set_country(&wifi_country)); // set locales for RF and channels
|
||||
@@ -69,7 +74,7 @@ void switchWifiChannel(void *parameter) {
|
||||
channel =
|
||||
(channel % WIFI_CHANNEL_MAX) + 1; // rotate channel 1..WIFI_CHANNEL_MAX
|
||||
esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
|
||||
ESP_LOGD(TAG, "Wifi set channel %d", channel);
|
||||
//ESP_LOGD(TAG, "Wifi set channel %d", channel);
|
||||
}
|
||||
vTaskDelete(NULL); // shoud never be reached
|
||||
}
|
||||
Reference in new issue
Block a user