Use of Statistic library and structure

I have a bunch of one wire DS18 temperature sensors that are read every few minutes. I want to calculate some statistics for each sensor using the Statistic library. I am using a struct as follow;

struct sensor { 
  byte address[8];
  String label;
  String application;
  String status;
  String found;
  String currtemp;
  Statistic myStats;
 } DS18B20sensors[] = {
 { { 0x28, 0xff, 0x07, 0x85, 0x83, 0x17, 0x04, 0x24 }, "DS18_01", "Outside",     "Online",  ""     ,   },
 { { 0x28, 0xff, 0xe3, 0x03, 0x00, 0x17, 0x04, 0xb7 }, "DS18_02", "Zone2",       "Online",  ""     ,   },
 { { 0x28, 0xff, 0x17, 0x80, 0x00, 0x17, 0x04, 0x5f }, "DS18_03", "Recirc",      "Online",  ""     ,   },
//etc.
}

I am trying to figure out how to add the myStats capability to this struct. I am trying to avoid having to create multiple separate statistic variables; e.g.
Statistic DS18_01Stats, DS18_02Stats, etc.

When I loop through all of my sensors ideally I could add data something like this;
DS18B20sensors[i].myStats.add(celsius[i]);

But I get a compile error when trying to reference the statistic functions; max, min, count, etc. as follows;
DS18B20sensors[i].myStats.count()

Errors include;
‘myStats’ was not declared in this scope
’Class Statistic’ has no member named 'max’
etc

Thanks in advance for your suggestions

First I’d not use String at all, but especially not for status, found and currtemp these are typically binary datatypes like bool, float or even enum (e.g. status with more than two states).

But about your Statistic - where is the class definition of it?
You should provide as much info you can to prevent people from having to search and guess what you are using.

1 Like

Got it; bool, float, or even enum.
I tried to put the class definition in the Struct;
struct sensor {
byte address[8];
String label;
String application;
String status;
String found;
String currtemp;
Statistic myStats; <<<<====

In this case it’s used like a variable type.
With “definition” I thought of declaration of the class itself and the implementation thereof.

1 Like