-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from Sensirion/add-device-name-support
Add device name support
- Loading branch information
Showing
8 changed files
with
167 additions
and
20 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
examples/Example14_Alternative_Device_Name/Example14_Alternative_Device_Name.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "Sensirion_Gadget_BLE.h" | ||
#include <string> | ||
|
||
NimBLELibraryWrapper lib; | ||
DataProvider provider(lib, DataType::T_RH_CO2_ALT, false, true); | ||
|
||
uint16_t t = 0; | ||
uint16_t rh = 0; | ||
uint16_t co2 = 0; | ||
uint16_t batteryLevel = 100; | ||
|
||
static int64_t lastMeasurementTimeMs = 0; | ||
static int measurementIntervalMs = 1000; | ||
|
||
static int64_t lastBatteryLevelUpdateMs = 0; | ||
static int batteryLevelUpdateIntervalMs = 60000; | ||
|
||
std::string altDeviceName = "Mock Device"; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
delay(1000); // Wait for Serial monitor to start | ||
|
||
// Enable alternative device name feature. | ||
// Must be enabled before calling begin(). | ||
provider.enableAltDeviceName(); | ||
// Initialize the GadgetBle Library | ||
provider.begin(); | ||
// Set alternative device name that will be used | ||
// by MyAmbience instead of the local device name. | ||
provider.setAltDeviceName(altDeviceName); | ||
|
||
Serial.print("Sensirion GadgetBle Lib initialized with deviceId = "); | ||
Serial.println(provider.getDeviceIdString()); | ||
|
||
// Set initial battery level | ||
provider.setBatteryLevel(batteryLevel); | ||
} | ||
|
||
void loop() { | ||
if (millis() - lastMeasurementTimeMs >= measurementIntervalMs) { | ||
Serial.println("Measurement"); | ||
provider.writeValueToCurrentSample(++t % 50, SignalType::TEMPERATURE_DEGREES_CELSIUS); | ||
provider.writeValueToCurrentSample(++rh % 100, SignalType::RELATIVE_HUMIDITY_PERCENTAGE); | ||
provider.writeValueToCurrentSample(++co2 % 1000, SignalType::CO2_PARTS_PER_MILLION); | ||
provider.commitSample(); | ||
lastMeasurementTimeMs = millis(); | ||
// Provide the sensor values for Tools -> Serial Monitor or Serial Plotter | ||
Serial.print("mockCO2[ppm]:"); | ||
Serial.print(co2); | ||
Serial.print("\t"); | ||
Serial.print("mockTemperature[℃]:"); | ||
Serial.print(t); | ||
Serial.print("\t"); | ||
Serial.print("mockHumidity[%]:"); | ||
Serial.println(rh); | ||
} | ||
if (millis() - lastBatteryLevelUpdateMs >= batteryLevelUpdateIntervalMs) { | ||
lastBatteryLevelUpdateMs = millis(); | ||
provider.setBatteryLevel(--batteryLevel); | ||
Serial.print("Battery Level Update:"); | ||
Serial.println(batteryLevel); | ||
if (batteryLevel == 0) { | ||
batteryLevel = 100; | ||
} | ||
} | ||
|
||
provider.handleDownload(); | ||
delay(3); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
; PlatformIO Project Configuration File | ||
; | ||
; Build options: build flags, source filter | ||
; Upload options: custom upload port, speed and extra flags | ||
; Library options: dependencies, extra library storages | ||
; Advanced options: extra scripting | ||
; | ||
; Please visit documentation for the other options and examples | ||
; https://docs.platformio.org/page/projectconf.html | ||
|
||
[platformio] | ||
src_dir = . | ||
|
||
[env:esp32dev] | ||
platform = espressif32 | ||
board = esp32dev | ||
framework = arduino | ||
upload_port = /dev/ttyUSB* | ||
monitor_speed = 115200 | ||
lib_ldf_mode=deep | ||
|
||
lib_deps = | ||
Sensirion_Unified_Prototyping_Toolkit_Core | ||
h2zero/NimBLE-Arduino@^1.4.0 | ||
|
||
lib_extra_dirs = | ||
${PROJECT_DIR}/../../ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters