Skip to content

Commit

Permalink
Merge pull request #10 from matthias-bs/feat-device-name
Browse files Browse the repository at this point in the history
Added device name to scan result
  • Loading branch information
matthias-bs committed Apr 25, 2024
2 parents bdb6aec + 5ff90d3 commit 536d9e3
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
|
ps -p "$$"
arduino-cli lib install NimBLE-Arduino@1.4.1
arduino-cli lib install ATC_MiThermometer@0.3.1
arduino-cli lib install ATC_MiThermometer@0.4.1

- name: Install platform
if: ${{ env.run-build == 'true' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void loop() {
if (miThermometer.data[i].valid) {
Serial.println();
Serial.printf("Sensor %d: %s\n", i, knownBLEAddresses[i].c_str());
Serial.printf("Name: %s\n", miThermometer.data[i].name.c_str());
Serial.printf("%.2f°C\n", miThermometer.data[i].temperature/100.0);
Serial.printf("%.2f%%\n", miThermometer.data[i].humidity/100.0);
Serial.printf("%.3fV\n", miThermometer.data[i].batt_voltage/1000.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#endif

// List of known sensors' BLE addresses
std::vector<std::string> knownBLEAddresses = {"a4:c1:38:02:8B:E0", "a4:c1:38:64:8F:10", "a4:c1:38:F3:C1:B4"};
std::vector<std::string> knownBLEAddresses = {"a4:c1:38:b8:1f:7f", "a4:c1:38:02:8B:E0", "a4:c1:38:64:8F:10", "a4:c1:38:F3:C1:B4"};
ATC_MiThermometer miTh(knownBLEAddresses);

MiThData_S miThData[3];
Expand Down Expand Up @@ -44,6 +44,7 @@ void loop() {
if (miThDat.valid) {
count++;
Serial.printf("sensor #%d -> ", i);
Serial.printf("name: %s ; ", miThDat.name.c_str());
Serial.printf("temperature: %.2fC ; ", miThDat.temperature *0.01f );
Serial.printf("humidity: %.2f%% ; ", miThDat.humidity *0.01f );
Serial.printf("voltage: %.3fV ; ", miThDat.batt_voltage*0.001f);
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ATC_MiThermometer
version=0.3.1
version=0.4.1
author=Matthias Prinke <matthias-bs@web.de>
maintainer=Matthias Prinke <matthias-bs@web.de>
sentence=Arduino library for BLE ATC_MiThermometer thermometer/hygrometer sensors.
Expand Down
3 changes: 3 additions & 0 deletions src/ATC_MiThermometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ unsigned ATC_MiThermometer::getData(uint32_t duration) {

log_d("Assigning scan results...");
for (unsigned i=0; i<foundDevices.getCount(); i++) {
log_d("haveName(): %d", foundDevices.getDevice(i).haveName());
log_d("getName(): %s", foundDevices.getDevice(i).getName().c_str());

// Match all devices found against list of known sensors
for (unsigned n = 0; n < _known_sensors.size(); n++) {
Expand All @@ -109,6 +111,7 @@ unsigned ATC_MiThermometer::getData(uint32_t duration) {
int len = foundDevices.getDevice(i).getServiceData().length();
log_d("Length of ServiceData: %d", len);

data[n].name = foundDevices.getDevice(i).getName();
if (len == 15) {
log_d("Custom format");
// Temperature
Expand Down
2 changes: 2 additions & 0 deletions src/ATC_MiThermometer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@

#include <Arduino.h>
#include <NimBLEDevice.h>
#include <string>


// MiThermometer data struct / type
struct MiThData_S {
bool valid; //!< data valid
std::string name; //!< BT device name
int16_t temperature; //!< temperature x 100°C
uint16_t humidity; //!< humidity x 100%
uint16_t batt_voltage; //!< battery voltage [mv]
Expand Down

0 comments on commit 536d9e3

Please sign in to comment.