What would be the best programming approach for the following situation:
- once an hour a controller (will be an Arduino Uno, a Pro Mini or an ESP8266) will receive following information over the hardware serial:
a. integer A (value A)
b. integer B (current time, in minutes)
c. integer C (the current time, in hours)
d. a letter designating the source (either X or Y) - the moving average needs to be calculated for the value A, but distinction needs to be made for the source X or Y
- the result of these moving averages needs to be made available for each of both sources (X and Y) in 2 new variables. These will be used for further action (irrigation system).
- an algorithm is in place to indicate the arrival of a new value; this variable is reset when the new value is being read. There will be no conflict between the two sources because the timing of reception of these values will be about half an hour apart.
Example:
source X sends the values 100, 110, 115 consecutively, per hour, in the first 3 hours of operation. First moving average must be 100, at the second hour: average of 100 and 110 = 105, after the third hour: average of 105 and 115 = 110.
The fourth hour the value 120 is sent, average = 115, the next hour value 125 is sent, average = 120.
Exception: if the difference between the new incoming value and the previous average is higher than a certain percentage (suppose for the example's sake 10%) then a flag must be set until the next value comes in that deviates less than this percentage from the last calculated moving average.
Summary of project: this serves to determine the irrigation needs for a system using remote soil moisture sensors (this is a private project for my gardening needs).