config.public.h 9.1 KB
Newer Older
1
2
3
#ifndef CONFIG_H_INCLUDED
#  define CONFIG_H_INCLUDED

4
5
6
7
8
9
10
11
12
13
14
15
/***      _                         _
 *       / \   _ __ ___  _ __   ___| |
 *      / _ \ | '_ ` _ \| '_ \ / _ \ |
 *     / ___ \| | | | | | |_) |  __/ |
 *    /_/ __\_\_| |_| |_| .__/_\___|_|
 *       / ___|___  _ __|_/ _(_) __ _
 *      | |   / _ \| '_ \| |_| |/ _` |
 *      | |__| (_) | | | |  _| | (_| |
 *       \____\___/|_| |_|_| |_|\__, |
 *                              |___/
 ***/

Eric Duminil's avatar
Eric Duminil committed
16
17
// This file is a config template, and can be copied to config.h.
// Please don't save any important password in this template.
Eric Duminil's avatar
Eric Duminil committed
18
19
20
21
22
23
// IMPORTANT: Parameters defined in config.h are only default values, and are applied if:
//   * the ampel is flashed for the first time
//   * or 'reset_config' command is called
//   * or AMPEL_CONFIG_VERSION has been changed.
// Once those default values have been applied, uploading the firmware with a modified config.h will not update the ampel configuration!
// Every parameter can be modified and saved later via the web-config.
24
25
// Some of those parameters can also be modified via commands in the Serial monitor :
//    e.g. 'wifi 0' to turn WiFi off, or 'csv 60' to log data in csv every minute.
Eric Duminil's avatar
Eric Duminil committed
26
27
28
29
30
31
32
33
34
/***
 * AMPEL
 */
// You can rename the Ampel if you want.
// This name will be used for CSV files and the mDNS address.
// You'll get a new CSV file after renaming, which can be convenient, e.g. after moving
// the ampel to another room.
// If left empty, the name will be ESPxxxxxx, where xxxxxx represent the last half of the MAC address.
#  define AMPEL_NAME ""
35

Eric Duminil's avatar
Eric Duminil committed
36
37
38
39
40
// This password will be used for Access Point (without username), and for web-server available at http://local_ip with user 'admin', without quotes.
// If left empty, the password will have to be set during the first configuration, via access point.
// In order to be set successfully, it should have at least 8 characters.
#  define AMPEL_PASSWORD ""

Eric Duminil's avatar
Eric Duminil committed
41
42
43
// AMPEL_CONFIG_VERSION should be defined, and have exactly 3 characters.
// If you modify this string, every parameter saved on the Ampel will be replaced by the ones in config.h.
// AMPEL_CONFIG_VERSION should also be updated if the configuration structure is modified.
Eric Duminil's avatar
Eric Duminil committed
44
45
// The structure of the Ampel configuration has been modified 13 times, so it's called "a13" for now.
#  define AMPEL_CONFIG_VERSION "a13"
Eric Duminil's avatar
Eric Duminil committed
46

47
48
49
50
/**
 * SERVICES
 */

51
// Define the default for corresponding services. They can be enabled/disabled later in the web-config.
Eric Duminil's avatar
Eric Duminil committed
52
#  define AMPEL_WIFI    true   // Should ESP connect to WiFi? Web configuration will not be available when set to false. Use "wifi 1" command to set to true.
53
54
55
#  define AMPEL_MQTT    true   // Should data be sent over MQTT? (AMPEL_WIFI should be enabled too)
#  define AMPEL_CSV     true   // Should data be logged as CSV, on the ESP flash memory?
#  define AMPEL_LORAWAN false  // Should data be sent over LoRaWAN? (Requires ESP32 + LoRa modem, and "MCCI LoRaWAN LMIC library")
56
57
58
59
60

/**
 * WIFI
 */

Eric Duminil's avatar
Eric Duminil committed
61
62
63
// SSID and PASSWORD need to be defined, but can be empty.
#  define WIFI_SSID     ""
#  define WIFI_PASSWORD ""
64
// How long should the Ampel try to connect to WIFI_SSID?
Eric Duminil's avatar
Eric Duminil committed
65
#  define WIFI_TIMEOUT  30 // [s]
66
67
68
// If the Ampel cannot connect to WIFI_SSID, it will start an Access Point for ACCESS_POINT_TIMEOUT seconds.
// If someone connects to this Access Point, the Ampel will stay in this mode until everybody logs out.
// If nobody connects to the Access Point before ACCESS_POINT_TIMEOUT seconds, the Ampel will try to connect WIFI_SSID again.
69
#  define ACCESS_POINT_TIMEOUT  60 // [s]
70
71
72
73
74

/**
 * Sensor
 */

Eric Duminil's avatar
Eric Duminil committed
75
76
// How often should measurement be displayed? Senseair S8 will measure every 4s anyway.
#  define MEASUREMENT_TIMESTEP 60 // [s] Should be at least 4s.
77
78
79

// How often should measurements be appended to CSV ?
// Set to 0 if you want to send values after each measurement
80
// WARNING: Writing too often might damage the ESP memory
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#  define CSV_INTERVAL 300 // [s]

// Residual heat from CO2 sensor seems to be high enough to change the temperature reading. How much should it be offset?
// NOTE: Sign isn't relevant. The returned temperature will always be shifted down.
#  define TEMPERATURE_OFFSET -3 // [K]

// Altitude above sea level
// Used for CO2 calibration
// here: Stuttgart, Schellingstr. 24. (Source: Google Earth)
#  define ALTITUDE_ABOVE_SEA_LEVEL 260 // [m]

// The reference CO2 concentration has to be within the range 400 ppm ≤ cref(CO2) ≤ 2000 ppm.
// Used for CO2 calibration
// here : measured concentration in Stuttgart
#  define ATMOSPHERIC_CO2_CONCENTRATION 425 // [ppm]

// Should the sensor try to calibrate itself?
// Sensirion recommends 7 days of continuous readings with at least 1 hour a day of 'fresh air' for self-calibration to complete.
99
#  define AUTO_CALIBRATE_SENSOR false // [true / false]
100
101
102
103
104
105

/**
 * LEDs
 */

// LED brightness, which can vary between min and max brightness ("LED breathing")
Eric Duminil's avatar
Eric Duminil committed
106
// MAX_BRIGHTNESS must be defined, and should be between 0 and 255.
Eric Duminil's avatar
Eric Duminil committed
107
108
109
// NOTE: LEDs require a decent amount of electricity, so the default is chosen to be relativitely low.
#  define MAX_BRIGHTNESS 80
// MIN_BRIGHTNESS, must be defined, and should be between 0 and MAX_BRIGHTNESS
Eric Duminil's avatar
Eric Duminil committed
110
// If MIN_BRIGHTNESS is set to MAX_BRIGHTNESS, breathing is disabled.
Eric Duminil's avatar
Eric Duminil committed
111
#  define MIN_BRIGHTNESS 40
Eric Duminil's avatar
Eric Duminil committed
112
// How many LEDs in the ring? 12 and 16 are currently supported.
113
#  define LED_COUNT 12
114
115

/**
116
 * MQTT
117
118
119
 */

/*
120
 * If AMPEL_MQTT is enabled, co2ampel will publish data every MQTT_SENDING_INTERVAL seconds.
121
122
123
 * An MQTT subscriber can then get the data from the corresponding broker, either encrypted or unencrypted:
 *
 *  ❯ mosquitto_sub -h 'test.mosquitto.org' -p 8883 -t 'CO2sensors/#' --cafile mosquitto.org.crt -v
124
125
 *  CO2sensors/ESPd03cc5 {"time":"2020-12-13 13:14:37+01", "co2":571, "temp":18.9, "rh":50.9}
 *  CO2sensors/ESPd03cc5 {"time":"2020-12-13 13:14:48+01", "co2":573, "temp":18.9, "rh":50.2}
126
127
128
 *  ...
 *
 *  ❯ mosquitto_sub -h 'test.mosquitto.org' -t 'CO2sensors/#' -v
129
130
 *  CO2sensors/ESPd03cc5 {"time":"2020-12-13 13:15:09+01", "co2":568, "temp":18.9, "rh":50.1}
 *  CO2sensors/ESPd03cc5 {"time":"2020-12-13 13:15:20+01", "co2":572, "temp":18.9, "rh":50.3}
131
132
133
134
135
136
137
138
139
140
141
 *  ...
 */

/*
 * Allow sensor to be configured over MQTT? Very useful for debugging. For example:
 *   mosquitto_pub -h 'test.mosquitto.org' -t 'CO2sensors/ESPe08dc9/control' -m 'timer 30'
 *   mosquitto_pub -h 'test.mosquitto.org' -t 'CO2sensors/ESPe08dc9/control' -m 'calibrate'
 *   mosquitto_pub -h 'test.mosquitto.org' -t 'CO2sensors/ESPe08dc9/control' -m 'reset'
 */
#  define ALLOW_MQTT_COMMANDS false

Eric Duminil's avatar
Eric Duminil committed
142
// How often should measurements be sent to MQTT server?
143
144
// Set to 0 if you want to send values after each measurement
// #  define MQTT_SENDING_INTERVAL MEASUREMENT_TIMESTEP * 5 // [s]
Eric Duminil's avatar
Eric Duminil committed
145
#  define MQTT_SENDING_INTERVAL 300 // [s]
146
147
#  define MQTT_SERVER "test.mosquitto.org"  // MQTT server URL or IP address
#  define MQTT_PORT 8883
Eric Duminil's avatar
Eric Duminil committed
148
#  define MQTT_ENCRYPTED true // Set to false for unencrypted MQTT (e.g. with port 1883).
149
150
#  define MQTT_USER ""
#  define MQTT_PASSWORD ""
Eric Duminil's avatar
Note    
Eric Duminil committed
151
#  define MQTT_TOPIC_PREFIX "CO2sensors/" // ESPxxxxxx will be added to the prefix, so complete topic will be "CO2sensors/ESPxxxxxx". The prefix should probably end with '/'
152

153
154
155
156
/**
 * LoRaWAN
 */

Eric Duminil's avatar
Eric Duminil committed
157
// 1) Requires "MCCI LoRaWAN LMIC library", which will be automatically used with PlatformIO but should be added in "Arduino IDE".
158
159
160
161
// 2) Region and transceiver type should be specified in:
//     * Arduino/libraries/MCCI_LoRaWAN_LMIC_library/project_config/lmic_project_config.h for Arduino IDE
//     * platformio.ini for PlatformIO
//    See https://github.com/mcci-catena/arduino-lmic#configuration for more information
Eric Duminil's avatar
Eric Duminil committed
162
163
// 3) It has been tested with "TTGO ESP32 SX1276 LoRa 868" and will only work with an ESP32 + LoRa modem
// 4) In order to use LoRaWAN, a gateway should be close to the co2ampel, and an account, an application and a device should be registered,
164
//      e.g. on https://www.thethingsindustries.com/docs/integrations/
Eric Duminil's avatar
Note    
Eric Duminil committed
165
//      with "Europe 863-870 MHz (SF9 for RX2 - recommended)", "MAC v1.0.3"
Eric Duminil's avatar
Eric Duminil committed
166
// 5) The corresponding keys should be defined in LORAWAN_DEVICE_EUI, LORAWAN_APPLICATION_EUI and LORAWAN_APPLICATION_KEY
167
// How often should measurements be sent over LoRaWAN?
Eric Duminil's avatar
Notes    
Eric Duminil committed
168
#  define LORAWAN_SENDING_INTERVAL 300 // [s] This value should not be too low. See https://www.thethingsnetwork.org/docs/lorawan/duty-cycle.html#maximum-duty-cycle
Eric Duminil's avatar
Eric Duminil committed
169

170
171
172
173
// WARNING: If AMPEL_LORAWAN is true, you need to modify the 3 following constants
// They are written as hexadecimal strings, and will be parsed in the correct order.

// This EUI must be in big-endian format, so most-significant-byte first.
Eric Duminil's avatar
Eric Duminil committed
174
175
// You can copy the string from TheThingsNetwork as-is, without reversing the bytes.
// For TheThingsNetwork issued EUIs the string should start with "70B3D5..."
176
#  define LORAWAN_DEVICE_EUI      "70B3D57ED004CB17"
Eric Duminil's avatar
Eric Duminil committed
177
// This should also be in big-endian format, and can be copied as is from TheThingsNetwork.
178
#  define LORAWAN_APPLICATION_EUI "0102030405060708"
Eric Duminil's avatar
Eric Duminil committed
179
// This should also be in big-endian format, and can be copied as is from TheThingsNetwork.
180
#  define LORAWAN_APPLICATION_KEY "9D06308E20B974919DA6404E063BE01D"
181

182
183
184
185
186
/**
 * NTP
 */

#  define NTP_SERVER "pool.ntp.org"
Eric Duminil's avatar
Eric Duminil committed
187
188
#  define UTC_OFFSET 1 // [h] +1 for Paris/Berlin, -5 for NYC
#  define DAYLIGHT_SAVING_TIME false // true in summer, false in winter
189
190

#endif