-
Notifications
You must be signed in to change notification settings - Fork 1
/
HomeAutomationCommon.h
149 lines (133 loc) · 5.66 KB
/
HomeAutomationCommon.h
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
Include File for common parameters.
Used in WeatherStation and HomeServer
20200522: V0.1 Test if it works at all
20200522: V0.2 Works with WeatherStation and HomeServer
20200522 V1.0 Stable error handling and messaging
20200627 V1.1 Sensor #5 added
20230115 V1.2 nMaxSensors
20230211 V1.3 rename float to int variable names
20230212 V1.4 sensor capabilities
20230212 V1.5 d do not set iLight to 0 on unused sensors
20230212 V2.0 works with 2 different sensors now
20240101 V2.1 JSON declaration removed in sensors not needed TODO add to ESPHub or in a new common include file
20240102 V2.2 Add light sensor values to ESP NOW Data Structure
20240106 V2.3 Sensor capabilities in ESPNOW struct receive when sensor version > 1
*/
// DELETE THIS INCLUDE YOU DO NOT NEED THIS FILE WHEN USING THE PASSWORDS BELOW
#include "D:\Arduino\HomeAutomationSecrets.h"
#define swBAUD_RATE 57600 // speed for softserial, 115000 often fails
/* ADD YOUR OWN VALUES IF YOU WANT TO USE THIS PROJEKT****************************************************************************
const char *WIFI_SSID = ""
const char *WIFI_PWD = "";
***************************
* ESP Now Settings
**************************
//SSID die der AP eine Zeitlang aufmacht. Damit kann der Sensor mit dem AP Kontakt aufnehmen und seine MAC bekanntgeben.
const char *APSSID = "";
***************************
* Thingspeak Settings
**************************
WiFiClient thingspeak_client;
const char *host = "api.thingspeak.com"; //IP address of the thingspeak server
const char *api_key = ""; //Your own thingspeak api_key
const int httpPort = 80;
***************************
MQTT Settings
**************************
#define SERVER ""
#define SERVERPORT 1883
#define MQTT_USERNAME ""
#define MQTT_KEY ""
#define MQTT_CLIENTD ""
***********************************************************************************************************/
/***************************
* Measurement Variables
**************************/
const float InvalidMeasurement = 999999; // value set when a value was not correctly received via serial and JSON
const int nMaxSensors = 10; // max number of sensors allowed in system it is an array so starts from 0 to < nMaxSensors
// used for ESP Now Data protocol same for sensors and ESPNowHub
// TODO add interface version add sensor capabilities do it when programming a new sensor
struct ESPNOW_DATA_STRUCTURE
{
int iSensorChannel = 99; // default for none received
float fESPNowTempA = -99; // Aussen A
float fESPNowTempB = -99; // Aussen B
float fESPNowHumi = -99;
float fESPNowVolt = -99; // Batterie Sensor
int nVersion = 1; // interface Version 0 w/o version only TempA to Volt, V1: including Light
uint16_t sSensorCapabilities = 0;
int nColorTemp = -99;
int nLux = -99;
int nRed = -99;
int nGreen = -99;
int nBlue = -99;
int nClear = -99;
};
// used for LORA transmition size optimized
enum eDATASOURCE
{
rainSensor,
tempSensor,
humiSensor,
batterySensor
};
struct LORA_DATA_STRUCTURE
{
eDATASOURCE eDataSource;
int iSensorChannel = 99; // default for none received
int iData = 99;
};
// sensor capabilities
const uint16_t TEMPA_ON = 1 << 0; // 1 (0x1)
const uint16_t TEMPB_ON = 1 << 1; // 2 (0x2)
const uint16_t VOLT_ON = 1 << 2; // 4 (0x4);
const uint16_t HUMI_ON = 1 << 3; // 8 (0x8)
const uint16_t LIGHT_ON = 1 << 4; // 16 (0x10)
const uint16_t ATMO_ON = 1 << 5; // 32 (0x20)
const uint16_t RGB_ON = 1 << 6; // 64 (0x40)
const uint16_t OPT2_ON = 1 << 7; // 128 (0x80)
const uint16_t OPT3_ON = 1 << 8; // 256 (0x100)
// used for local storage in ESPNowHub
struct SENSOR_DATA
{
int iSensorChannel = nMaxSensors + 1;
uint16_t sSensorCapabilities = 0;
int iTempA = InvalidMeasurement;
int iTempB = InvalidMeasurement;
int iTempC = InvalidMeasurement;
int iHumi = InvalidMeasurement;
int iVolt = InvalidMeasurement;
int iAtmo = InvalidMeasurement;
int iLight = InvalidMeasurement;
int nVersion = 0; // interface Version 0 w/o version only TempA to Volt, V1: including Light
int nColorTemp = InvalidMeasurement;
int nLux = InvalidMeasurement;
int nRed = InvalidMeasurement;
int nGreen = InvalidMeasurement;
int nBlue = InvalidMeasurement;
int nClear = InvalidMeasurement;
String sMacAddress = "0000000000000000000";
bool bSensorRec = false; // true when valid sensor data received in time frame
// int iSensorCnt = 6; //Counter for timeout no values after some time renamed
bool bSensorRegistered = false; // true when sensor is first time received
int iTimeSinceLastRead; // Minutes count up between sensor readings 0 if a new reading comes in, used for sensor data recieved over ESPNow
};
SENSOR_DATA sSensor[nMaxSensors]; // HomeAutomationCommon.h starts from 0 = local sensor and 1-max are the channels
// Sensor 1: Blau/gelb Balkon, Sensor 2 Blau/Grau, sSensor3: Blau/Rot, sSensor6 Breadboard with light sensor, sSensor7 RainSensor
// Sensor reading timeout
long lSensorValidTime = 0;
// const unsigned long ulOneSecondTimer = 6 * 1000UL; //time in sec
// const int iSensorTimeout = 1; // times interval will make reading invalid 60*x 120 sec. Used for recieving data over serial
/***************************
* Serial Rx variables
**************************/
const char startMarker = '%';
const char endMarker = '$';
const int nMaxRxArray = 256;
/***************************
* JSON definitions
**************************/
// this in now in each file wher JSON is needed
// const size_t capacity = JSON_OBJECT_SIZE(8) + 256;
// StaticJsonDocument<capacity> jsonDocument;