Skip to content

Commit

Permalink
Merge pull request #8096 from s-hadinger/zb_crash_occupancy
Browse files Browse the repository at this point in the history
Fix Zigbee crash with Occupancy sensor (#8089)
  • Loading branch information
arendst authored Apr 8, 2020
2 parents 83122f7 + 5b8e194 commit ef9ffaa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions tasmota/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Add command ``SetOption41 <x>`` to force sending gratuitous ARP every <x> seconds
- Add quick wifi reconnect using saved AP parameters when ``SetOption56 0`` (#3189)
- Fix PWM flickering during wifi connection (#8046)
- Fix Zigbee crash with Occupancy sensor (#8089)

### 8.2.0.2 20200328

Expand Down
1 change: 1 addition & 0 deletions tasmota/xdrv_23_zigbee_2_devices.ino
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ void Z_Devices::setTimer(uint16_t shortaddr, uint16_t groupaddr, uint32_t wait_m
}

// Run timer at each tick
// WARNING: don't set a new timer within a running timer, this causes memory corruption
void Z_Devices::runTimer(void) {
// visit all timers
for (auto it = _deferred.begin(); it != _deferred.end(); it++) {
Expand Down
9 changes: 5 additions & 4 deletions tasmota/xdrv_23_zigbee_8_parsers.ino
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,10 @@ void Z_SendAFInfoRequest(uint16_t shortaddr) {

// Aqara Occupancy behavior: the Aqara device only sends Occupancy: true events every 60 seconds.
// Here we add a timer so if we don't receive a Occupancy event for 90 seconds, we send Occupancy:false
void Z_AqaraOccupancy(uint16_t shortaddr, uint16_t cluster, uint8_t endpoint, const JsonObject *json) {
void Z_AqaraOccupancy(uint16_t shortaddr, uint16_t cluster, uint8_t endpoint, const JsonObject &json) {
static const uint32_t OCCUPANCY_TIMEOUT = 90 * 1000; // 90 s
// Read OCCUPANCY value if any
const JsonVariant &val_endpoint = getCaseInsensitive(*json, PSTR(OCCUPANCY));
const JsonVariant &val_endpoint = getCaseInsensitive(json, PSTR(OCCUPANCY));
if (nullptr != &val_endpoint) {
uint32_t occupancy = strToUInt(val_endpoint);

Expand All @@ -544,8 +544,6 @@ void Z_AqaraOccupancy(uint16_t shortaddr, uint16_t cluster, uint8_t endpoint, co
int32_t Z_PublishAttributes(uint16_t shortaddr, uint16_t groupaddr, uint16_t cluster, uint8_t endpoint, uint32_t value) {
const JsonObject *json = zigbee_devices.jsonGet(shortaddr);
if (json == nullptr) { return 0; } // don't crash if not found
// Post-provess for Aqara Presence Senson
Z_AqaraOccupancy(shortaddr, cluster, endpoint, json);

zigbee_devices.jsonPublishFlush(shortaddr);
return 1;
Expand Down Expand Up @@ -613,6 +611,9 @@ int32_t Z_ReceiveAfIncomingMessage(int32_t res, const class SBuffer &buf) {
zigbee_devices.resetTimersForDevice(srcaddr, 0 /* groupaddr */, Z_CAT_REACHABILITY); // remove any reachability timer already there
zigbee_devices.setReachable(srcaddr, true); // mark device as reachable

// Post-provess for Aqara Presence Senson
Z_AqaraOccupancy(srcaddr, clusterid, srcendpoint, json);

if (defer_attributes) {
// Prepare for publish
if (zigbee_devices.jsonIsConflict(srcaddr, json)) {
Expand Down

0 comments on commit ef9ffaa

Please sign in to comment.