forked from matthias-bs/BresserWeatherSensorTTN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BresserWeatherSensorTTNCfg.h
213 lines (175 loc) · 7 KB
/
BresserWeatherSensorTTNCfg.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
///////////////////////////////////////////////////////////////////////////////
// BresserWeatherSensorTTNCfg.h
//
// User specific configuration for BresserWeatherSensorTTN.ino
//
// - Enabling or disabling of features
// - Voltage thresholds for power saving
// - Timing configuration
// - Timezone
//
// created: 08/2022
//
//
// MIT License
//
// Copyright (c) 2022 Matthias Prinke
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
//
// History:
//
// 20220819 Created from BresserWeatherSensorTTN.ino
// 20221011 Changed timezone handling
// 20221113 Fixed ADC defines
// 20221117 Enabled FORCE_JOIN_AFTER_SLEEP_TIMEOUT per default
// Added defines for power saving -
// BATTERY_WEAK, BATTERY_LOW, SLEEP_INTERVAL_LONG
// 20221228 Modified DEBUG_PRINTF/DEBUG_PRINTF_TS macros to use
// Arduino logging functions
// 20221230 Added WEATHERSENSOR_DATA_REQUIRED
// 20220112 Removed LMIC_ENABLE_DeviceTimeReq; must be defined in
// ~/Arduino/libraries/MCCI_LoRaWAN_LMIC_library/project_config/
// lmic_project_config.h
// in order to be recognized!!!
// 20230121 Added configuration for TTGO LoRa32 V1
//
// ToDo:
// -
//
///////////////////////////////////////////////////////////////////////////////
#include <vector>
#include <string>
// Enable debug mode (debug messages via serial port)
// Arduino IDE: Tools->Core Debug Level: "Debug|Verbose"
//#define CORE_DEBUG_LEVEL ARDUHAL_LOG_LEVEL_DEBUG
//#define CORE_DEBUG_LEVEL ARDUHAL_LOG_LEVEL_VERBOSE
//--- Select Board ---
#ifndef ARDUINO_TTGO_LoRa32_V1
// Use pinning for LoRaWAN Node
#define LORAWAN_NODE
#endif
//--- Select LoRaWAN Network ---
// The Things Network
#define ARDUINO_LMIC_CFG_NETWORK_TTN 1
// Helium Network
// see mcci-cathena/arduino-lorawan issue #185 "Add Helium EU868 support"
// (https://github.com/mcci-catena/arduino-lorawan/issues/185)
#define ARDUINO_LMIC_CFG_NETWORK_GENERIC 0
// Enable LORAWAN debug mode - this generates dummy weather data and skips weather sensor reception
//#define LORAWAN_DEBUG
// Battery voltage thresholds for energy saving
// If SLEEP_EN is defined and battery voltage is below BATTERY_WEAK [mV], MCU will sleep for SLEEP_INTERVAL_LONG
#define BATTERY_WEAK 3500
// Go to sleep mode immediately after start if battery voltage is below BATTERY_LOW [mV]
#define BATTERY_LOW 3200
// Enable sleep mode - sleep after successful transmission to TTN (recommended!)
#define SLEEP_EN
// If SLEEP_EN is defined, MCU will sleep for SLEEP_INTERVAL seconds after succesful transmission
#define SLEEP_INTERVAL 360
// Long sleep interval, MCU will sleep for SLEEP_INTERVAL_LONG seconds if battery voltage is below BATTERY_WEAK
#define SLEEP_INTERVAL_LONG 900
// RTC to network time sync interval (in minutes)
#define CLOCK_SYNC_INTERVAL 24 * 60
// Force deep sleep after a certain time, even if transmission was not completed
#define FORCE_SLEEP
// Force a new join procedure (instead of re-join) after encountering sleep timeout
#define FORCE_JOIN_AFTER_SLEEP_TIMEOUT
// During initialization (not joined), force deep sleep after SLEEP_TIMEOUT_INITIAL (if enabled)
#define SLEEP_TIMEOUT_INITIAL 1800
// If already joined, force deep sleep after SLEEP_TIMEOUT_JOINED seconds (if enabled)
#define SLEEP_TIMEOUT_JOINED 600
// Additional timeout to be applied after joining if Network Time Request pending
#define SLEEP_TIMEOUT_EXTRA 300
// Timeout for weather sensor data reception (seconds)
#define WEATHERSENSOR_TIMEOUT 180
// If enabled, enter deep sleep mode if receiving weather sensor data was not successful
//#define WEATHERSENSOR_DATA_REQUIRED
// Enable transmission of weather sensor ID
//#define SENSORID_EN
// Enable rain data statistics
#define RAINDATA_EN
// Enable battery / supply voltage measurement
#define ADC_EN
// Enable OneWire temperature measurement
#define ONEWIRE_EN
// Enable BLE temperature/humidity measurement
// Note: BLE requires a lot of program memory!
#define MITHERMOMETER_EN
// Enable Bresser Soil Temperature/Moisture Sensor
#define SOILSENSOR_EN
// ADC for supply/battery voltage measurement
// default: on-board connection to VB on FireBeetle ESP32 (with R10+R11 assembled)
// on-board connection to VBAT on TTGO LoRa32
#ifdef ADC_EN
#if defined(ARDUINO_TTGO_LoRa32_V1)
#define PIN_ADC_IN 35
#else
#define PIN_ADC_IN A0
#endif
//#define PIN_ADC_IN 34
#endif
// Additional ADC pins (default: FireBeetle ESP32)
//#define PIN_ADC0_IN A0
//#define PIN_ADC1_IN A1
//#define PIN_ADC2_IN A2
#ifdef LORAWAN_NODE
#define PIN_ADC3_IN A3
#endif
#ifdef PIN_ADC0_IN
// Voltage divider R1 / (R1 + R2) -> V_meas = V(R1 + R2); V_adc = V(R1)
const float ADC0_DIV = 0.5;
const uint8_t ADC0_SAMPLES = 10;
#endif
#ifdef PIN_ADC1_IN
// Voltage divider R1 / (R1 + R2) -> V_meas = V(R1 + R2); V_adc = V(R1)
const float ADC1_DIV = 0.5;
const uint8_t ADC1_SAMPLES = 10;
#endif
#ifdef PIN_ADC2_IN
// Voltage divider R1 / (R1 + R2) -> V_meas = V(R1 + R2); V_adc = V(R1)
const float ADC2_DIV = 0.5;
const uint8_t ADC2_SAMPLES = 10;
#endif
#ifdef PIN_ADC3_IN
// Voltage divider R1 / (R1 + R2) -> V_meas = V(R1 + R2); V_adc = V(R1)
const float ADC3_DIV = 0.5;
const uint8_t ADC3_SAMPLES = 10;
#endif
#ifdef ONEWIRE_EN
#if defined(ARDUINO_TTGO_LoRa32_V1)
#define PIN_ONEWIRE_BUS 21
#else
#define PIN_ONEWIRE_BUS 5
#endif
#endif
#ifdef ADC_EN
// Voltage divider R1 / (R1 + R2) -> V_meas = V(R1 + R2); V_adc = V(R1)
const float UBATT_DIV = 0.5;
const uint8_t UBATT_SAMPLES = 10;
#endif
#ifdef MITHERMOMETER_EN
// BLE scan time in seconds
const int bleScanTime = 10;
// List of known sensors' BLE addresses
std::vector<std::string> knownBLEAddresses = {"a4:c1:38:b8:1f:7f"};
#endif
// Enter your time zone (https://remotemonitoringsystems.ca/time-zone-abbreviations.php)
const char* TZ_INFO = "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00";