Skip to content

Commit

Permalink
Merge pull request #14 from aattww/dev
Browse files Browse the repository at this point in the history
## v1.1.3 (2020-10-14)

* Fixed number of last seen nodes zeroing after 2^16 minutes. [#12](#12)
  • Loading branch information
aattww committed Oct 14, 2020
2 parents 8cf1176 + a9f4033 commit 265b10c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ Start logging measurements to a MySQL database ([*save_modbus_to_db.py*](save_mo

# Version history

## v1.1.3 (2020-10-14)

* Fixed number of last seen nodes zeroing after 2^16 minutes. [#12](https://github.com/aattww/sensors/issues/12)

## v1.1.2 (2020-06-07)

* Fixed 23K256 SRAM handler transactions. [#8](https://github.com/aattww/sensors/issues/8)
Expand Down
13 changes: 8 additions & 5 deletions SensorsGateway/SensorsGateway.ino
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@


#define MAJOR_VERSION 1
#define MINOR_VERSION 5
#define MINOR_VERSION 6

#include <SimpleModbusAsync.h>
#include <RH_RF95.h>
Expand Down Expand Up @@ -719,6 +719,9 @@ void updateLastReceived() {

uint8_t tempBuffer[5];

// Cast to 16 bits so that the following calculations work (otherwise seen nodes zero after 2^16 minutes)
uint16_t currentTime_16 = (uint16_t)currentTime;

// Iterate through all IDs
for (uint8_t i = 1; i <= MAX_NR_OF_NODES; i++) {
// The first 5 bytes has all the data we need here
Expand All @@ -730,15 +733,15 @@ void updateLastReceived() {
// Calculate nodes which have been seen during the last...
uint16_t lastReceived = (tempBuffer[1] << 8) | tempBuffer[2];
// ... hour
if ((currentTime - lastReceived) <= 60) {
if ((currentTime_16 - lastReceived) <= 60) {
gwMetaData.nodesDuringLastHour++;
}
// ... 12 hours
if ((currentTime - lastReceived) <= 720) {
if ((currentTime_16 - lastReceived) <= 720) {
gwMetaData.nodesDuringLast12Hours++;
}
// ... 24 hours
if ((currentTime - lastReceived) <= 1440) {
if ((currentTime_16 - lastReceived) <= 1440) {
gwMetaData.nodesDuringLast24Hours++;
}

Expand All @@ -753,7 +756,7 @@ void updateLastReceived() {

// Delete nodes not seen for a while
if (deleteOldNodes != 0) {
if ((currentTime - lastReceived) > deleteOldNodes) {
if ((currentTime_16 - lastReceived) > deleteOldNodes) {
memoryHandler.deleteNode(i);
}
}
Expand Down

0 comments on commit 265b10c

Please sign in to comment.