Skip to content

Commit

Permalink
Add seting and getting BLE history interval for Sensirion Ring Buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
melkati committed Apr 29, 2024
1 parent b373320 commit 6abec33
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
11 changes: 6 additions & 5 deletions CO2_Gadget.ino
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Functions and enum definitions
void reverseButtons(bool reversed); // Defined in CO2_Gadget_Buttons.h
void outputsLoop(); // Defined in CO2_Gadget_Main.h
void publishMQTTLogData(String logData); // Defined in CO2_Gadget_MQTT.h
void putPreferences(); // Defined in CO2_Gadget_Preferences.h
void menuLoop(); // Defined in CO2_Gadget_Menu.h
void reverseButtons(bool reversed); // Defined in CO2_Gadget_Buttons.h
void outputsLoop(); // Defined in CO2_Gadget_Main.h
void publishMQTTLogData(String logData); // Defined in CO2_Gadget_MQTT.h
void putPreferences(); // Defined in CO2_Gadget_Preferences.h
void menuLoop(); // Defined in CO2_Gadget_Menu.h
void setBLEHistoryInterval(uint64_t interval); // Defined in CO2_Gadget_BLE.h

// Define enum for toneBuzzerBeep
enum ToneBuzzerBeep {
Expand Down
15 changes: 15 additions & 0 deletions CO2_Gadget_BLE.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ WifiMultiLibraryWrapper wifi;
DataProvider provider(lib, DataType::T_RH_CO2_ALT, true, true, true, &wifi);
#endif

void setBLEHistoryInterval(uint64_t interval) {
#ifdef SUPPORT_BLE
provider.setHistoryInterval(interval * 1000);
#endif
}

void initBLE() {
#ifdef SUPPORT_BLE
if (activeBLE) {
Expand All @@ -22,9 +28,13 @@ void initBLE() {
return;
} else {
// provider.setSampleIntervalMs(60000); // Set interval for MyAmbiance dataloging at 60 seconds. See https://github.com/melkati/CO2-Gadget/projects/2#card-91517604
setBLEHistoryInterval(60);
provider.begin();
Serial.print("-->[SBLE] Sensirion Gadget BLE Lib initialized with deviceId = ");
Serial.println(provider.getDeviceIdString());
Serial.print("-->[SBLE] History interval set to: ");
Serial.print(provider.getHistoryInterval() / 1000);
Serial.println(" seconds");
// Set initial battery level
provider.setBatteryLevel(batteryLevel);
bleInitialized = true;
Expand Down Expand Up @@ -108,6 +118,11 @@ void BLELoop() {
provider.handleDownload();
delay(3);
if (provider.wifiChanged()) handleBLEwifiChanged();
if (provider.historyIntervalChanged()) {
Serial.print("-->[BLE ] History interval changed to: ");
Serial.print(provider.getHistoryInterval() / 1000);
Serial.println(" seconds");
}
handleFrcRequest();
#endif
}
Expand Down
2 changes: 2 additions & 0 deletions CO2_Gadget_Sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ void initSensors() {
sensors.setCO2AltitudeOffset(altitudeMeters);
// sensors.setAutoSelfCalibration(false); // TO-DO: Implement in CanAirIO Sensors Lib

setBLEHistoryInterval(60);

Serial.printf("-->[SENS] Selected CO2 Sensor: %d\n", selectedCO2Sensor);

if (selectedCO2Sensor == AUTO) {
Expand Down
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ lib_deps =
lennarthennigs/Button2 @ ^1.6.5
https://github.com/melkati/arduino-i2c-scd4x.git#featureset
https://github.com/melkati/canairio_sensorlib.git#fixOffset
https://github.com/melkati/arduino-ble-gadget.git#handle-wifi-settings
https://github.com/melkati/arduino-ble-gadget.git#historyInterval
https://github.com/melkati/Improv-WiFi-Library.git
rlogiacco/Battery Sense @ ^1.1.2
adafruit/Adafruit NeoPixel@^1.10.3
Expand All @@ -74,7 +74,7 @@ build_flags =
'-DWIFI_PW_CREDENTIALS=""'
-D MQTT_BROKER_SERVER="\"192.168.1.145"\"
-D CO2_GADGET_VERSION="\"0.12."\"
-D CO2_GADGET_REV="\"052-development"\"
-D CO2_GADGET_REV="\"053-development"\"
-DCACHE_DIR=".pio/build"
-DBUZZER_PIN=2 ; ESP32 pin GPIO13 connected to piezo buzzer
-DNEOPIXEL_PIN=26 ; Pinnumber for button for down/next and back / exit actions
Expand Down

0 comments on commit 6abec33

Please sign in to comment.