Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reed switch and counter #8

Merged
merged 9 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ void loop() {
Serial.printf("%.3fV\n", miThermometer.data[i].batt_voltage/1000.0);
Serial.printf("%d%%\n", miThermometer.data[i].batt_level);
Serial.printf("%ddBm\n", miThermometer.data[i].rssi);
Serial.printf("Measurement Count: %d\n", miThermometer.data[i].count);
// Print boolean flags
Serial.printf("Reed Switch State: %s\n", miThermometer.data[i].reedSwitchState ? "Open" : "Closed");
Serial.printf("GPIO TRG Output: %s\n", miThermometer.data[i].gpioTrgOutput ? "High" : "Low");
Serial.printf("Control Parameters: %s\n", miThermometer.data[i].controlParameters ? "Set" : "Not Set");
Serial.printf("Temperature Trigger Event: %s\n", miThermometer.data[i].tempTriggerEvent ? "Triggered" : "Not Triggered");
Serial.printf("Humidity Trigger Event: %s\n", miThermometer.data[i].humiTriggerEvent ? "Triggered" : "Not Triggered");
Serial.println();
}
}
Expand Down
14 changes: 13 additions & 1 deletion src/ATC_MiThermometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,19 @@ unsigned ATC_MiThermometer::getData(uint32_t duration) {
data[n].batt_voltage = (volt_msb << 8) | volt_lsb;

// Battery state [%]
data[n].batt_level = foundDevices.getDevice(i).getServiceData().c_str()[12];
data[n].batt_level = foundDevices.getDevice(i).getServiceData().c_str()[12];

// Count
data[n].count = foundDevices.getDevice(i).getServiceData().c_str()[13];

//Flags
uint8_t flagsByte = foundDevices.getDevice(i).getServiceData().c_str()[14];
data[n].reedSwitchState = flagsByte & 0x01; // Extract bit 0 (Reed Switch)
data[n].gpioTrgOutput = (flagsByte >> 1) & 0x01; // Extract bit 1 (GPIO_TRG pin output)
data[n].controlParameters = (flagsByte >> 2) & 0x01; // Extract bit 2 (Control parameters)
data[n].tempTriggerEvent = (flagsByte >> 3) & 0x01; // Extract bit 3 (Temperature trigger event)
data[n].humiTriggerEvent = (flagsByte >> 4) & 0x01; // Extract bit 4 (Humidity trigger event)

}
else if (len == 13) {
log_d("ATC1441 format");
Expand Down
7 changes: 7 additions & 0 deletions src/ATC_MiThermometer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ struct MiThData_S {
uint16_t batt_voltage; //!< battery voltage [mv]
uint8_t batt_level; //!< battery level [%]
int16_t rssi; //!< RSSI [dBm]
uint8_t count; //!< measurement count
bool reedSwitchState;
bool gpioTrgOutput;
bool controlParameters;
bool tempTriggerEvent;
bool humiTriggerEvent;

};

typedef struct MiThData_S MiThData_t; //!< Shortcut for struct MiThData_S
Expand Down
Loading