Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
co2ampel
ampel-firmware
Commits
4ff6b183
Commit
4ff6b183
authored
4 years ago
by
Eric Duminil
Browse files
Options
Download
Email Patches
Plain Diff
Removing lots of stuff
parent
52307d98
Pipeline
#5898
passed with stage
in 2 minutes and 1 second
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
ampel-firmware/ampel-firmware.ino
+2
-128
ampel-firmware/ampel-firmware.ino
ampel-firmware/co2_sensor.cpp
+3
-34
ampel-firmware/co2_sensor.cpp
ampel-firmware/config.public.h
+4
-4
ampel-firmware/config.public.h
ampel-firmware/led_effects.cpp
+1
-1
ampel-firmware/led_effects.cpp
with
10 additions
and
167 deletions
+10
-167
ampel-firmware/ampel-firmware.ino
+
2
-
128
View file @
4ff6b183
...
@@ -55,7 +55,6 @@
...
@@ -55,7 +55,6 @@
* and define your credentials and parameters in 'config.h'.
* and define your credentials and parameters in 'config.h'.
*/
*/
/*****************************************************************
/*****************************************************************
* PreInit *
* PreInit *
*****************************************************************/
*****************************************************************/
...
@@ -67,60 +66,12 @@ void preinit() {
...
@@ -67,60 +66,12 @@ void preinit() {
#endif
#endif
}
}
/*****************************************************************
/*****************************************************************
* Setup *
* Setup *
*****************************************************************/
*****************************************************************/
void
setup
()
{
void
setup
()
{
led_effects
::
setupOnBoardLED
();
led_effects
::
onBoardLEDOff
();
Serial
.
begin
(
BAUDS
);
Serial
.
begin
(
BAUDS
);
pinMode
(
0
,
INPUT
);
// Flash button (used for forced calibration)
led_effects
::
setupRing
();
sensor
::
initialize
();
sensor
::
initialize
();
Serial
.
print
(
F
(
"Sensor ID: "
));
Serial
.
println
(
SENSOR_ID
);
Serial
.
print
(
F
(
"Board : "
));
Serial
.
println
(
BOARD
);
#ifdef AMPEL_WIFI
WiFiConnect
(
SENSOR_ID
);
Serial
.
print
(
F
(
"WiFi - Status: "
));
Serial
.
println
(
WiFi
.
status
());
if
(
WiFi
.
status
()
==
WL_CONNECTED
)
{
# ifdef AMPEL_HTTP
web_server
::
initialize
();
# endif
ntp
::
initialize
();
if
(
MDNS
.
begin
(
SENSOR_ID
.
c_str
()))
{
// Start the mDNS responder for SENSOR_ID.local
MDNS
.
addService
(
"http"
,
"tcp"
,
80
);
Serial
.
println
(
F
(
"mDNS responder started"
));
}
else
{
Serial
.
println
(
F
(
"Error setting up MDNS responder!"
));
}
# ifdef AMPEL_MQTT
mqtt
::
initialize
(
"CO2sensors/"
+
SENSOR_ID
);
# endif
}
#endif
#ifdef AMPEL_CSV
csv_writer
::
initialize
();
#endif
#if defined(AMPEL_LORAWAN) && defined(ESP32)
lorawan
::
initialize
();
#endif
}
}
/*****************************************************************
/*****************************************************************
...
@@ -128,85 +79,8 @@ void setup() {
...
@@ -128,85 +79,8 @@ void setup() {
*****************************************************************/
*****************************************************************/
void
loop
()
{
void
loop
()
{
#if defined(AMPEL_LORAWAN) && defined(ESP32)
//LMIC Library seems to be very sensitive to timing issues, so run it first.
lorawan
::
process
();
if
(
lorawan
::
waiting_for_confirmation
)
{
// If node is waiting for join confirmation from Gateway, nothing else should run.
return
;
}
#endif
//NOTE: Loop should never take more than 1000ms. Split in smaller methods and logic if needed.
//NOTE: Loop should never take more than 1000ms. Split in smaller methods and logic if needed.
//NOTE: Only use millis() for duration comparison, not timestamps comparison. Otherwise, problems happen when millis roll over.
//NOTE: Only use millis() for duration comparison, not timestamps comparison. Otherwise, problems happen when millis roll over.
uint32_t
t0
=
millis
();
// sensor::processData();
int
t
=
3
;
keepServicesAlive
();
// Short press for night mode, Long press for calibration.
checkFlashButton
();
if
(
sensor
::
processData
())
{
#ifdef AMPEL_CSV
csv_writer
::
logIfTimeHasCome
(
sensor
::
timestamp
,
sensor
::
co2
,
sensor
::
temperature
,
sensor
::
humidity
);
#endif
#if defined(AMPEL_WIFI) && defined(AMPEL_MQTT)
mqtt
::
publishIfTimeHasCome
(
sensor
::
timestamp
,
sensor
::
co2
,
sensor
::
temperature
,
sensor
::
humidity
);
#endif
#if defined(AMPEL_LORAWAN) && defined(ESP32)
lorawan
::
preparePayloadIfTimeHasCome
(
sensor
::
co2
,
sensor
::
temperature
,
sensor
::
humidity
);
#endif
}
uint32_t
duration
=
millis
()
-
t0
;
if
(
duration
>
max_loop_duration
)
{
max_loop_duration
=
duration
;
Serial
.
print
(
F
(
"Debug - Max loop duration : "
));
Serial
.
print
(
max_loop_duration
);
Serial
.
println
(
" ms."
);
}
}
/**
* Checks if flash button has been pressed:
* If not, do nothing.
* If short press, toggle LED display.
* If long press, start calibration process.
*/
void
checkFlashButton
()
{
if
(
!
digitalRead
(
0
))
{
// Button has been pressed
led_effects
::
onBoardLEDOn
();
delay
(
300
);
if
(
digitalRead
(
0
))
{
Serial
.
println
(
F
(
"Flash has been pressed for a short time. Should toggle night mode."
));
led_effects
::
toggleNightMode
();
}
else
{
Serial
.
println
(
F
(
"Flash has been pressed for a long time. Keep it pressed for calibration."
));
if
(
led_effects
::
countdownToZero
()
<
0
)
{
sensor
::
startCalibrationProcess
();
}
}
led_effects
::
onBoardLEDOff
();
}
}
void
keepServicesAlive
()
{
#ifdef AMPEL_WIFI
if
(
WiFi
.
status
()
==
WL_CONNECTED
)
{
# if defined(ESP8266)
//NOTE: Sadly, there seems to be a bug in the current MDNS implementation.
// It stops working after 2 minutes. And forcing a restart leads to a memory leak.
MDNS
.
update
();
# endif
ntp
::
update
();
// NTP client has its own timer. It will connect to NTP server every 60s.
# ifdef AMPEL_HTTP
web_server
::
update
();
# endif
# ifdef AMPEL_MQTT
mqtt
::
keepConnection
();
// MQTT client has its own timer. It will keep alive every 15s.
# endif
}
#endif
}
}
This diff is collapsed.
Click to expand it.
ampel-firmware/co2_sensor.cpp
+
3
-
34
View file @
4ff6b183
...
@@ -138,7 +138,7 @@ namespace sensor {
...
@@ -138,7 +138,7 @@ namespace sensor {
*/
*/
if
(
co2
<
2000
)
{
if
(
co2
<
2000
)
{
led_effects
::
displayCO2color
(
co2
);
led_effects
::
displayCO2color
(
co2
);
delay
(
100
);
//
delay(100);
}
else
{
}
else
{
// >= 2000: entire ring blinks red
// >= 2000: entire ring blinks red
led_effects
::
redAlert
();
led_effects
::
redAlert
();
...
@@ -149,42 +149,11 @@ namespace sensor {
...
@@ -149,42 +149,11 @@ namespace sensor {
* Returns true if fresh data is available, for further processing (e.g. MQTT, CSV or LoRa)
* Returns true if fresh data is available, for further processing (e.g. MQTT, CSV or LoRa)
*/
*/
bool
processData
()
{
bool
processData
()
{
bool
freshData
=
scd30
.
dataAvailable
();
if
(
scd30
.
dataAvailable
())
{
if
(
freshData
)
{
// checkTimerDeviation();
timestamp
=
ntp
::
getLocalTime
();
co2
=
scd30
.
getCO2
();
co2
=
scd30
.
getCO2
();
temperature
=
scd30
.
getTemperature
();
temperature
=
scd30
.
getTemperature
();
humidity
=
scd30
.
getHumidity
();
humidity
=
scd30
.
getHumidity
();
}
}
return
0
;
//NOTE: Data is available, but it's sometimes erroneous: the sensor outputs zero ppm but non-zero temperature and non-zero humidity.
if
(
co2
<=
0
)
{
// No measurement yet. Waiting.
led_effects
::
showWaitingLED
(
color
::
blue
);
return
false
;
}
/**
* Fresh data. Log it and send it if needed.
*/
if
(
freshData
)
{
if
(
should_calibrate
)
{
countStableMeasurements
();
}
logToSerial
();
}
if
(
should_calibrate
)
{
if
(
stable_measurements
==
60
)
{
calibrateAndRestart
();
}
led_effects
::
showWaitingLED
(
waiting_color
);
return
false
;
}
displayCO2OnLedRing
();
return
freshData
;
}
}
}
}
This diff is collapsed.
Click to expand it.
ampel-firmware/config.public.h
+
4
-
4
View file @
4ff6b183
...
@@ -8,10 +8,10 @@
...
@@ -8,10 +8,10 @@
*/
*/
// Comment or remove those lines if you want to disable the corresponding services
// Comment or remove those lines if you want to disable the corresponding services
# define AMPEL_WIFI // Should ESP connect to WiFi? It allows the Ampel to get time from an NTP server.
//
# define AMPEL_WIFI // Should ESP connect to WiFi? It allows the Ampel to get time from an NTP server.
# define AMPEL_HTTP // Should HTTP web server be started? (AMPEL_WIFI should be enabled too)
//
# define AMPEL_HTTP // Should HTTP web server be started? (AMPEL_WIFI should be enabled too)
# define AMPEL_MQTT // Should data be sent over MQTT? (AMPEL_WIFI should be enabled too)
//
# define AMPEL_MQTT // Should data be sent over MQTT? (AMPEL_WIFI should be enabled too)
# define AMPEL_CSV // Should data be logged as CSV, on the ESP flash memory?
//
# define AMPEL_CSV // Should data be logged as CSV, on the ESP flash memory?
// # define AMPEL_LORAWAN // Should data be sent over LoRaWAN? (Requires ESP32 + LoRa modem, and "MCCI LoRaWAN LMIC library")
// # define AMPEL_LORAWAN // Should data be sent over LoRaWAN? (Requires ESP32 + LoRa modem, and "MCCI LoRaWAN LMIC library")
/**
/**
...
...
This diff is collapsed.
Click to expand it.
ampel-firmware/led_effects.cpp
+
1
-
1
View file @
4ff6b183
...
@@ -13,7 +13,7 @@ namespace config {
...
@@ -13,7 +13,7 @@ namespace config {
const
int
kitt_tail
=
3
;
// How many dimmer LEDs follow in K.I.T.T. wheel
const
int
kitt_tail
=
3
;
// How many dimmer LEDs follow in K.I.T.T. wheel
const
uint16_t
poor_air_quality_ppm
=
1600
;
// Above this threshold, LED breathing effect is faster.
const
uint16_t
poor_air_quality_ppm
=
1600
;
// Above this threshold, LED breathing effect is faster.
//NOTE: Use a class instead? NightMode could then be another state.
//NOTE: Use a class instead? NightMode could then be another state.
bool
night_mode
=
fals
e
;
bool
night_mode
=
tru
e
;
}
}
#if defined(ESP8266)
#if defined(ESP8266)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets