-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathglobals.cpp
More file actions
121 lines (101 loc) · 4.6 KB
/
globals.cpp
File metadata and controls
121 lines (101 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "globals.h"
#include "config.h"
#include <SimpleMap.h>
//i created 12 of each sensor object in case we added lots more sensors via device_features
//amusingly, this barely ate into memory at all
//since many I2C sensors only permit two sensors per I2C bus, you could reduce the size of these object arrays
//and so i've dropped some of these down to 2
Adafruit_ADT7410 adt7410[4];
DHT* dht[4];
Adafruit_AHTX0 AHT[2];
SFE_BMP180 BMP180[2];
BME680_Class BME680[2];
Adafruit_BMP085 BMP085d[2];
Generic_LM75 LM75[2];
Adafruit_BMP280 BMP280[2];
#include <IRremoteESP8266.h>
IRsend irsend(ci[IR_PIN]);
Adafruit_INA219* ina219;
Adafruit_VL53L0X lox[4];
Adafruit_FRAM_I2C fram;
//SEND DATA TO A REMOTE SERVER TO STORE IN A DATABASE----------------------------------------------------
// ---------- Non-blocking sendRemoteData() state machine -------------
//
// Usage:
// startRemoteTask(datastring, mode, fRAMordinal);
// // call runRemoteTask() frequently from loop()
// ---------------------------------------------------------------------
// Configurable timings (tweak as desired)
const unsigned long CONNECT_RETRY_SPACING_MS = 200; // spacing between connect attempts (non-blocking)
const unsigned long CONNECT_TIMEOUT_MS = 5000; // per-connection wait for server (was ~10s, shortened)
const unsigned long REPLY_AVAIL_TIMEOUT_MS = 10000; // wait for first byte from server
const unsigned long MAX_RESPONSE_SIZE = 32 * 1024UL; // safety cap to avoid runaway memory use
uint16_t framIndexAddress = 0;
uint16_t currentRecordCount = 0;
WiFiClient clientGet;
WiFiUDP ntpUDP; //i guess i need this for time lookup
NTPClient timeClient(ntpUDP, "pool.ntp.org");
bool localSource = false; //turns true when a local edit to the data is done. at that point we have to send local upstream to the server
byte justDeviceJson = 1;
unsigned long connectionFailureTime = 0;
unsigned long lastDataLogTime = 0;
unsigned long localChangeTime = 0;
unsigned long lastPoll = 0;
int pinTotal = 12;
String pinList[12]; //just a list of pins
String pinName[12]; //for friendly names
String ipAddress;
String ipAddressAffectingChange;
int changeSourceId = 0;
String deviceName = "";
String architecture = "";
String additionalSensorInfo; //we keep it stored in a delimited string just the way it came from the server and unpack it periodically to get the data necessary to read sensors
float measuredVoltage = 0;
float measuredAmpage = 0;
bool canSleep = false;
bool deferredCanSleep = false;
long latencySum = 0;
long latencyCount = 0;
bool offlineMode = false;
unsigned long lastOfflineLog = 0;
uint8_t lastRecordSize = 0;
unsigned long lastOfflineReconnectAttemptTime = 0;
bool haveReconnected = true; //we need to start reconnected in case we reboot and there are stored FRAM records
uint16_t fRAMRecordsSkipped = 0;
uint32_t lastRtcSyncTime = 0;
uint32_t wifiOnTime = 0;
uint8_t outputMode = 0;
String responseBuffer = "";
unsigned long lastPet = 0;
int currentWifiIndex = 0;
//https://github.com/spacehuhn/SimpleMap
SimpleMap<String, int> *pinMap = new SimpleMap<String, int>([](String &a, String &b) -> int {
if (a == b) return 0; // a and b are equal
else if (a > b) return 1; // a is bigger than b
else return -1; // a is smaller than b
});
SimpleMap<String, int> *sensorObjectCursor = new SimpleMap<String, int>([](String &a, String &b) -> int {
if (a == b) return 0; // a and b are equal
else if (a > b) return 1; // a is bigger than b
else return -1; // a is smaller than b
});
uint32_t moxeeRebootTimes[] = {0,0,0,0,0,0,0,0,0,0,0};
int moxeeRebootCount = 0;
int timeOffset = 0;
long lastCommandId = 0;
char * deferredCommand = "";
bool onePinAtATimeMode = false; //used when the server starts gzipping data and we can't make sense of it
char requestNonJsonPinInfo = 1; //use to get much more compressed data double-delimited data from data.php if 1, otherwise if 0 it requests JSON
int pinCursor = -1;
bool connectionFailureMode = true; //when we're in connectionFailureMode, we check connection much more than ci[POLLING_GRANULARITY]. otherwise, we check it every ci[POLLING_GRANULARITY]
int knownMoxeePhase = -1; //-1 is unknown. 0 is stupid "show battery level", 1 is operational
int moxeePhaseChangeCount = 0;
uint32_t lastCommandLogId = 0;
byte parsedSerialData[64];
bool slaveUnpetted = true;
uint8_t lastSlavePowerMode = 0;
uint32_t lastSlaveMillis = 0;
bool resendSlavePinInfo = false;
uint32_t millisAtPossibleReboot = 0;
String possibleEndingMessage;
ESP8266WebServer server(80); //Server on port 80