Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
co2ampel
ampel-firmware
Commits
579440cb
Commit
579440cb
authored
Apr 17, 2021
by
Eric Duminil
Browse files
More commands
parent
c65e5fcf
Changes
5
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/co2_sensor.cpp
View file @
579440cb
...
@@ -75,7 +75,11 @@ namespace sensor {
...
@@ -75,7 +75,11 @@ namespace sensor {
sensor_commands
::
defineIntCallback
(
"timer"
,
setTimer
,
" 30 (Sets measurement interval, in s)"
);
sensor_commands
::
defineIntCallback
(
"timer"
,
setTimer
,
" 30 (Sets measurement interval, in s)"
);
sensor_commands
::
defineIntCallback
(
"calibrate"
,
calibrateSensorToSpecificPPM
,
sensor_commands
::
defineIntCallback
(
"calibrate"
,
calibrateSensorToSpecificPPM
,
" 600 (Starts calibration process, to given ppm)"
);
" 600 (Starts calibration process, to given ppm)"
);
sensor_commands
::
defineIntCallback
(
"calibrate!"
,
calibrateSensorRightNow
,
" 600 (Calibrates right now, to given ppm)"
);
sensor_commands
::
defineIntCallback
(
"calibrate!"
,
calibrateSensorRightNow
,
" 600 (Calibrates right now, to given ppm)"
);
sensor_commands
::
defineCallback
(
"reset"
,
[]()
{
ESP
.
restart
();
},
" (Restarts the sensor)"
);
}
}
//NOTE: should timer deviation be used to adjust measurement_timestep?
//NOTE: should timer deviation be used to adjust measurement_timestep?
...
...
ampel-firmware/csv_writer.cpp
View file @
579440cb
...
@@ -127,7 +127,7 @@ namespace csv_writer {
...
@@ -127,7 +127,7 @@ namespace csv_writer {
sensor_commands
::
defineCallback
(
"hello"
,
[]()
{
sensor_commands
::
defineCallback
(
"hello"
,
[]()
{
Serial
.
println
(
"SAY HELLO"
);
Serial
.
println
(
"SAY HELLO"
);
},
" (Say Hello;)"
);
},
" (Say Hello;)"
);
sensor_commands
::
defineCallback
(
"format_filesystem"
,
formatFilesystem
,
" (Deletes the whole filesystem
.
)"
);
sensor_commands
::
defineCallback
(
"format_filesystem"
,
formatFilesystem
,
" (Deletes the whole filesystem)"
);
}
}
File
openOrCreate
()
{
File
openOrCreate
()
{
...
...
ampel-firmware/mqtt.cpp
View file @
579440cb
...
@@ -37,10 +37,8 @@ namespace mqtt {
...
@@ -37,10 +37,8 @@ namespace mqtt {
mqttClient
.
setServer
(
config
::
mqtt_server
,
config
::
mqtt_port
);
mqttClient
.
setServer
(
config
::
mqtt_server
,
config
::
mqtt_port
);
sensor_commands
::
defineIntCallback
(
"mqtt"
,
setMQTTinterval
,
" 60 (Sets MQTT sending interval, in s)"
);
sensor_commands
::
defineIntCallback
(
"mqtt"
,
setMQTTinterval
,
" 60 (Sets MQTT sending interval, in s)"
);
sensor_commands
::
defineCallback
(
"publish"
,
[]()
{
sensor_commands
::
defineCallback
(
"local_ip"
,
sendInfoAboutLocalNetwork
,
Serial
.
println
(
F
(
"Forcing MQTT publish now."
));
" (Sends local IP and SSID via MQTT. Can be useful to find sensor)"
);
last_sent_at
=
-
config
::
sending_interval
;
},
" (Force publish now)"
);
}
}
void
publish
(
const
String
&
timestamp
,
int16_t
co2
,
float
temperature
,
float
humidity
)
{
void
publish
(
const
String
&
timestamp
,
int16_t
co2
,
float
temperature
,
float
humidity
)
{
...
@@ -61,17 +59,6 @@ namespace mqtt {
...
@@ -61,17 +59,6 @@ namespace mqtt {
}
}
}
}
void
sendInfoAboutLocalNetwork
()
{
char
info_topic
[
60
];
// Should be enough for "CO2sensors/ESPd03cc5/info"
snprintf
(
info_topic
,
sizeof
(
info_topic
),
"%s/info"
,
publish_topic
.
c_str
());
char
payload
[
75
];
// Should be enough for info json...
const
char
*
json_info_format
=
PSTR
(
"{
\"
local_ip
\"
:
\"
%s
\"
,
\"
ssid
\"
:
\"
%s
\"
}"
);
snprintf
(
payload
,
sizeof
(
payload
),
json_info_format
,
WiFi
.
localIP
().
toString
().
c_str
(),
WiFi
.
SSID
().
c_str
());
mqttClient
.
publish
(
info_topic
,
payload
);
}
/**
/**
* Allows sensor to be controlled by commands over MQTT
* Allows sensor to be controlled by commands over MQTT
*
*
...
@@ -103,10 +90,6 @@ namespace mqtt {
...
@@ -103,10 +90,6 @@ namespace mqtt {
if
(
messageString
==
"night_mode"
)
{
if
(
messageString
==
"night_mode"
)
{
led_effects
::
toggleNightMode
();
led_effects
::
toggleNightMode
();
}
else
if
(
messageString
==
"local_ip"
)
{
sendInfoAboutLocalNetwork
();
}
else
if
(
messageString
==
"reset"
)
{
ESP
.
restart
();
// softer than ESP.reset()
}
}
}
}
...
@@ -174,4 +157,18 @@ namespace mqtt {
...
@@ -174,4 +157,18 @@ namespace mqtt {
Serial
.
println
(
"s."
);
Serial
.
println
(
"s."
);
led_effects
::
showKITTWheel
(
color
::
green
,
1
);
led_effects
::
showKITTWheel
(
color
::
green
,
1
);
}
}
// It can be hard to find the local IP of a sensor if it isn't connected to Serial port, and if mDNS is disabled.
// If the sensor can be reach by MQTT, it can answer with info about local_ip and ssid.
// The sensor will send the info to "CO2sensors/ESP123456/info".
void
sendInfoAboutLocalNetwork
()
{
char
info_topic
[
60
];
// Should be enough for "CO2sensors/ESP123456/info"
snprintf
(
info_topic
,
sizeof
(
info_topic
),
"%s/info"
,
publish_topic
.
c_str
());
char
payload
[
75
];
// Should be enough for info json...
const
char
*
json_info_format
=
PSTR
(
"{
\"
local_ip
\"
:
\"
%s
\"
,
\"
ssid
\"
:
\"
%s
\"
}"
);
snprintf
(
payload
,
sizeof
(
payload
),
json_info_format
,
WiFi
.
localIP
().
toString
().
c_str
(),
WiFi
.
SSID
().
c_str
());
mqttClient
.
publish
(
info_topic
,
payload
);
}
}
}
ampel-firmware/mqtt.h
View file @
579440cb
...
@@ -18,5 +18,6 @@ namespace mqtt {
...
@@ -18,5 +18,6 @@ namespace mqtt {
void
publishIfTimeHasCome
(
const
String
&
timeStamp
,
const
int16_t
&
co2
,
const
float
&
temp
,
const
float
&
hum
);
void
publishIfTimeHasCome
(
const
String
&
timeStamp
,
const
int16_t
&
co2
,
const
float
&
temp
,
const
float
&
hum
);
void
setMQTTinterval
(
int32_t
sending_interval
);
void
setMQTTinterval
(
int32_t
sending_interval
);
void
sendInfoAboutLocalNetwork
();
}
}
#endif
#endif
ampel-firmware/web_server.cpp
View file @
579440cb
...
@@ -282,9 +282,9 @@ namespace web_server {
...
@@ -282,9 +282,9 @@ namespace web_server {
if
(
!
shouldBeAllowed
())
{
if
(
!
shouldBeAllowed
())
{
return
http
.
requestAuthentication
(
DIGEST_AUTH
);
return
http
.
requestAuthentication
(
DIGEST_AUTH
);
}
}
sensor_commands
::
run
(
http
.
arg
(
"send"
).
c_str
());
http
.
sendHeader
(
"Location"
,
"/"
);
http
.
sendHeader
(
"Location"
,
"/"
);
http
.
send
(
303
);
http
.
send
(
303
);
sensor_commands
::
run
(
http
.
arg
(
"send"
).
c_str
());
}
}
void
handlePageNotFound
()
{
void
handlePageNotFound
()
{
...
...
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