Skip to content

Commit

Permalink
version 0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
francc committed Apr 30, 2024
1 parent 16f51c7 commit b37c079
Show file tree
Hide file tree
Showing 17 changed files with 315 additions and 99 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ SensorWatcher is a firmware for the ESP32 family of microcontrollers that automa
- M5Stack Station-BAT
- M5Stack Station-RS485
- M5Stack Tough
- Generic ESP32 board
- Generic ESP32 boards

## ESP32-S3

- Adafruit ESP32-S3 Feather
- Adafruit QT Py ESP32-S3
- M5Stack AtomS3 Lite
- SeeedStudio Xiao ESP32S3
- Generic ESP32-S3 board
- Generic ESP32-S3 boards

## ESP32-C3

- SeeedStudio Xiao ESP32C3
- Generic ESP32-C3 boards

## I2C

Expand Down Expand Up @@ -101,13 +106,21 @@ Most of the code is released under the GPL-3 license. Some libraries are under t

# ChangeLog

## 0.9

- Added support for extended and long-range BLE advertisements for chips that support BT5.

- Changed the format for BT4 node advertisements. If you are using SensorWatcher as BLE nodes with previous releases, please upgrade both sensor and gateway nodes to this release at the same time.

- Do not start the WiFi driver if the SSID is not set. For BLE-only use cases.

## 0.8

- Added support for ESP32-C3 and Xiao ESP32C3.

- Use the hardware USB Serial JTAG when available instead of TinyUSB.

- Use a single buffer istead of two for HTTP requests and responses.
- Use a single buffer instead of two for HTTP requests and responses.

## 0.7

Expand Down
13 changes: 11 additions & 2 deletions esp32c3/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=4
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=0
CONFIG_BT_NIMBLE_HS_FLOW_CTRL=n
CONFIG_BT_NIMBLE_CRYPTO_STACK_MBEDTLS=n
CONFIG_BT_NIMBLE_WHITELIST_SIZE=1

CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT=y
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_2M_PHY=n
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_CODED_PHY=n
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_CODED_PHY=y
CONFIG_BT_NIMBLE_EXT_ADV=y
CONFIG_BT_NIMBLE_MAX_EXT_ADV_INSTANCES=1
CONFIG_BT_NIMBLE_EXT_ADV_MAX_SIZE=1650
CONFIG_BT_NIMBLE_ENABLE_PERIODIC_ADV=y
CONFIG_BT_NIMBLE_PERIODIC_ADV_SYNC_TRANSFER=y
CONFIG_BT_NIMBLE_MAX_PERIODIC_SYNCS=0
CONFIG_BT_NIMBLE_WHITELIST_SIZE=1

CONFIG_BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_NUM=50
CONFIG_BT_CTRL_BLE_SCAN_DUPL=n
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192
Expand Down
13 changes: 11 additions & 2 deletions esp32s3/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=4
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=0
CONFIG_BT_NIMBLE_HS_FLOW_CTRL=n
CONFIG_BT_NIMBLE_CRYPTO_STACK_MBEDTLS=n
CONFIG_BT_NIMBLE_WHITELIST_SIZE=1

CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT=y
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_2M_PHY=n
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_CODED_PHY=n
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_CODED_PHY=y
CONFIG_BT_NIMBLE_EXT_ADV=y
CONFIG_BT_NIMBLE_MAX_EXT_ADV_INSTANCES=1
CONFIG_BT_NIMBLE_EXT_ADV_MAX_SIZE=1650
CONFIG_BT_NIMBLE_ENABLE_PERIODIC_ADV=y
CONFIG_BT_NIMBLE_PERIODIC_ADV_SYNC_TRANSFER=y
CONFIG_BT_NIMBLE_MAX_PERIODIC_SYNCS=0
CONFIG_BT_NIMBLE_WHITELIST_SIZE=1

CONFIG_BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_NUM=50
CONFIG_BT_CTRL_BLE_SCAN_DUPL=n
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192
Expand Down
5 changes: 3 additions & 2 deletions source/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "adc.h"
#include "application.h"
#include "board.h"
#include "enums.h"
#include "measurements.h"
#include "now.h"
Expand Down Expand Up @@ -253,10 +254,10 @@ bool adc_measure()
ok = ok && adc_oneshot_read(handle, channel, &adc_raw) == ESP_OK;
if(cali_handle != NULL) {
ok = ok && adc_cali_raw_to_voltage(cali_handle, adc_raw, &voltage);
measurements_append(wifi.mac, RESOURCE_ADC, 0, 0, 0, 0, 0, gpio, METRIC_DCvoltage, NOW, UNIT_V, voltage * adc.multiplier / 1000.0);
measurements_append(board.id, RESOURCE_ADC, 0, 0, 0, 0, 0, gpio, METRIC_DCvoltage, NOW, UNIT_V, voltage * adc.multiplier / 1000.0);
}
else
measurements_append(wifi.mac, RESOURCE_ADC, 0, 0, 0, 0, 0, gpio, METRIC_ADCvalue, NOW, UNIT_NONE, adc_raw);
measurements_append(board.id, RESOURCE_ADC, 0, 0, 0, 0, 0, gpio, METRIC_ADCvalue, NOW, UNIT_NONE, adc_raw);
}
}

Expand Down
8 changes: 4 additions & 4 deletions source/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,7 @@ void app_main(void)
}

now = esp_timer_get_time();
if(now >= application.next_measurement_time || backends_modified) {
backends_modified = false;
if(now >= application.next_measurement_time) {
ESP_LOGI(__func__, "starting measurements @ %lli", now);
application.last_measurement_time = now;
application.next_measurement_time += application.sampling_period * 1000000L;
Expand Down Expand Up @@ -369,10 +368,10 @@ void app_main(void)
ESP_LOGI(__func__, "finished sending measurements via BLE @ %lli", esp_timer_get_time());
}

if(wifi.status == WIFI_STATUS_ONLINE && measurements_updated && (measurements_count || measurements_full)) {
if(wifi.status == WIFI_STATUS_ONLINE && ((measurements_updated && (measurements_count || measurements_full)) || backends_modified)) {
wifi_measure();
for(uint8_t i = 0; i != BACKENDS_NUM_MAX; i++) {
if(backends[i].uri[0] == 0)
if(backends[i].uri[0] == 0 || (backends_modified && !(backends_modified & 1 << i)))
continue;

ESP_LOGI(__func__, "started sending measurements via WiFi @ %lli", esp_timer_get_time());
Expand Down Expand Up @@ -590,6 +589,7 @@ void app_main(void)
}
ESP_LOGI(__func__, "finished sending measurements via WiFi @ %lli", esp_timer_get_time());
}
backends_modified = 0;
measurements_updated = false;
ready_to_sleep = true;
}
Expand Down
7 changes: 4 additions & 3 deletions source/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
#include <nvs_flash.h>

#include "application.h"
#include "postman.h"
#include "board.h"
#include "enums.h"
#include "measurements.h"
#include "now.h"
#include "postman.h"
#include "schema.h"
#include "wifi.h"

Expand Down Expand Up @@ -223,8 +224,8 @@ uint32_t application_resource_handler(uint32_t method, bp_pack_t *reader, bp_pac
void application_measure()
{
if(application.diagnostics) {
measurements_append(wifi.mac, RESOURCE_APPLICATION, 0, 0, 0, 0, 0, 0, METRIC_UpTime, NOW, UNIT_s, esp_timer_get_time() / 1000000L);
measurements_append(wifi.mac, RESOURCE_APPLICATION, 0, 0, 0, 0, 0, 0, METRIC_MinimumFreeHeap, NOW, UNIT_B, esp_get_minimum_free_heap_size());
measurements_append(board.id, RESOURCE_APPLICATION, 0, 0, 0, 0, 0, 0, METRIC_UpTime, NOW, UNIT_s, esp_timer_get_time() / 1000000L);
measurements_append(board.id, RESOURCE_APPLICATION, 0, 0, 0, 0, 0, 0, METRIC_MinimumFreeHeap, NOW, UNIT_B, esp_get_minimum_free_heap_size());
}
}

2 changes: 1 addition & 1 deletion source/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#define APP_ID "com.movoki.sensor_watcher"
#define APP_NAME "SensorWatcher"
#define APP_VERSION 0x0008
#define APP_VERSION 0x0009

#include "bigpacks.h"

Expand Down
6 changes: 3 additions & 3 deletions source/backends.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
#include "schema.h"

backend_t backends[BACKENDS_NUM_MAX];
bool backends_modified;
bool backends_started;
uint8_t backends_modified;

void backends_init()
{
backends_modified = false;
backends_started = false;
backends_modified = 0;
memset(backends, 0, sizeof(backends));
backends_read_from_nvs();
}
Expand Down Expand Up @@ -371,7 +371,7 @@ uint32_t backends_resource_handler(uint32_t method, bp_pack_t *reader, bp_pack_t
ok = ok && backend_unpack(reader, index);

if(ok) {
backends_modified = true; // to force sending to HTTP backends for status update
backends_modified |= 1 << index; // to force sending to HTTP backends for status update
backends_start();
return backends_write_to_nvs() ? PM_204_Changed : PM_500_Internal_Server_Error;
}
Expand Down
2 changes: 1 addition & 1 deletion source/backends.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ typedef struct {


extern backend_t backends[];
extern bool backends_modified;
extern bool backends_started;
extern uint8_t backends_modified;

void backends_init();
bool backends_read_from_nvs();
Expand Down
Loading

0 comments on commit b37c079

Please sign in to comment.