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
1575b514
Commit
1575b514
authored
Feb 10, 2022
by
Eric Duminil
Browse files
Is lorawan active?
parent
07ebc466
Pipeline
#5777
passed with stage
in 2 minutes and 15 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/ampel-firmware.h
View file @
1575b514
...
...
@@ -21,9 +21,7 @@
# endif
#endif
#ifdef AMPEL_LORAWAN
# include "lorawan.h"
#endif
#include
"lorawan.h"
#include
"util.h"
#include
"ntp.h"
...
...
ampel-firmware/ampel-firmware.ino
View file @
1575b514
...
...
@@ -122,8 +122,10 @@ void setup() {
# endif
#endif
#if defined(AMPEL_LORAWAN) && defined(ESP32)
lorawan
::
initialize
();
#if defined(ESP32)
if
(
config
::
lorawan_active
())
{
lorawan
::
initialize
();
}
#endif
}
...
...
@@ -138,13 +140,15 @@ void checkSerialInput();
* Main 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
;
#if defined(ESP32)
if
(
config
::
lorawan_active
())
{
//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.
...
...
@@ -170,8 +174,10 @@ void loop() {
}
#endif
#if defined(AMPEL_LORAWAN) && defined(ESP32)
lorawan
::
preparePayloadIfTimeHasCome
(
sensor
::
co2
,
sensor
::
temperature
,
sensor
::
humidity
);
#if defined(ESP32)
if
(
config
::
lorawan_active
())
{
lorawan
::
preparePayloadIfTimeHasCome
(
sensor
::
co2
,
sensor
::
temperature
,
sensor
::
humidity
);
}
#endif
}
...
...
ampel-firmware/lorawan.cpp
View file @
1575b514
#include
"lorawan.h"
#if
defined(AMPEL_LORAWAN) &&
defined(ESP32)
#if defined(ESP32)
#include
"led_effects.h"
#include
"sensor_console.h"
...
...
ampel-firmware/lorawan.h
View file @
1575b514
...
...
@@ -3,7 +3,7 @@
#include
"config.h"
# if
defined(AMPEL_LORAWAN) &&
defined(ESP32)
# if defined(ESP32)
#include
<stdint.h>
// For uint32_t & uint16_t
...
...
ampel-firmware/web_config.cpp
View file @
1575b514
...
...
@@ -67,6 +67,7 @@ namespace web_config {
/**
* LED
*/
//NOTE: Could also be optional : for LED 0 / 1
ParameterGroup
ledParams
=
ParameterGroup
(
"LED"
,
"LED"
);
IntTParameter
<
uint8_t
>
maxBrightnessParam
=
...
...
@@ -81,10 +82,6 @@ namespace web_config {
// # define HTTP_USER "co2ampel"
// # define HTTP_PASSWORD "my_password"
// WARNING: If AMPEL_LORAWAN is enabled, you need to modify the 3 following constants!
// This EUI must be in little-endian format, so least-significant-byte first.
// When copying an EUI from ttnctl output, this means to reverse the bytes.
/**
* CSV
*/
...
...
@@ -134,13 +131,10 @@ namespace web_config {
CheckboxTParameter
dstParam
=
Builder
<
CheckboxTParameter
>
(
"dst"
).
label
(
"Daylight Saving Time?"
).
defaultValue
(
false
).
build
();
/**
* LED
*/
/**
* LoRa & Stuff
*/
#if defined(ESP32)
OptionalParameterGroup
loraParams
=
OptionalParameterGroup
(
"LoRaWan"
,
"LoRaWan"
,
AMPEL_LORAWAN
);
IntTParameter
<
uint16_t
>
loraTimestepParam
=
Builder
<
IntTParameter
<
uint16_t
>>
(
"lora_timestep"
).
label
(
"LoRa timestep"
).
defaultValue
(
...
...
@@ -152,6 +146,7 @@ namespace web_config {
Builder
<
TextTParameter
<
17
>>
(
"app_eui"
).
label
(
"App EUI"
).
defaultValue
(
"00EA07..."
).
build
();
TextTParameter
<
32
>
appKeyParam
=
Builder
<
TextTParameter
<
32
>>
(
"app_key"
).
label
(
"App key"
).
defaultValue
(
"81CCFE..."
).
build
();
#endif
OptionalGroupHtmlFormatProvider
optionalGroupHtmlFormatProvider
;
...
...
@@ -202,18 +197,21 @@ namespace web_config {
mqttParams
.
addItem
(
&
mqttEncryptionParam
);
mqttParams
.
addItem
(
&
mqttCommandsParam
);
//TODO: Only for
ESP32
#if defined(
ESP32
)
loraParams
.
addItem
(
&
loraTimestepParam
);
loraParams
.
addItem
(
&
deviceEUIParam
);
loraParams
.
addItem
(
&
appEUIParam
);
loraParams
.
addItem
(
&
appKeyParam
);
#endif
iotWebConf
->
addParameterGroup
(
&
co2Params
);
iotWebConf
->
addParameterGroup
(
&
ledParams
);
iotWebConf
->
addParameterGroup
(
&
timeParams
);
iotWebConf
->
addParameterGroup
(
&
csvParams
);
iotWebConf
->
addParameterGroup
(
&
mqttParams
);
#if defined(ESP32)
iotWebConf
->
addParameterGroup
(
&
loraParams
);
#endif
sensor_console
::
defineCommand
(
"reset_config"
,
[]()
{
Serial
.
println
(
F
(
"Resetting config..."
));
...
...
@@ -304,4 +302,11 @@ namespace config {
uint16_t
&
mqtt_sending_interval
=
web_config
::
mqttTimestepParam
.
value
();
bool
&
mqtt_encryption
=
web_config
::
mqttEncryptionParam
.
value
();
bool
&
allow_mqtt_commands
=
web_config
::
mqttCommandsParam
.
value
();
// LORAWAN
#if defined(ESP32)
bool
lorawan_active
()
{
return
web_config
::
loraParams
.
isActive
();
}
#endif
}
ampel-firmware/web_config.h
View file @
1575b514
...
...
@@ -40,6 +40,11 @@ namespace config {
extern
uint16_t
&
mqtt_sending_interval
;
// [s]
extern
bool
&
mqtt_encryption
;
// [true / false]
extern
bool
&
allow_mqtt_commands
;
// [true / false]
// LORAWAN
#if defined(ESP32)
bool
lorawan_active
();
// also defined for ESP8266, and set to false
#endif
}
namespace
web_config
{
...
...
ampel-firmware/web_server.cpp
View file @
1575b514
...
...
@@ -9,9 +9,7 @@
#include
"sensor_console.h"
#include
"csv_writer.h"
#include
"mqtt.h"
#ifdef AMPEL_LORAWAN
# include "lorawan.h"
#endif
#include
"lorawan.h"
#include
<IotWebConf.h>
#include
<IotWebConfUsing.h>
// This loads aliases for easier class names.
...
...
@@ -106,7 +104,7 @@ namespace web_server {
"<tr><td>Connected?</td><td>%s</td></tr>
\n
"
"<tr><td>Last publish</td><td>%s</td></tr>
\n
"
"<tr><td>Timestep</td><td>%5d s</td></tr>
\n
"
#if
defined(AMPEL_LORAWAN) &&
defined(ESP32)
#if defined(ESP32)
"<tr><th colspan='2'>LoRaWAN</th></tr>
\n
"
"<tr><td>Connected?</td><td>%s</td></tr>
\n
"
"<tr><td>Frequency</td><td>%s MHz</td></tr>
\n
"
...
...
@@ -227,7 +225,7 @@ namespace web_server {
sensor
::
humidity
,
sensor
::
timestamp
,
config
::
measurement_timestep
,
csv_writer
::
last_successful_write
,
config
::
csv_interval
,
csv_writer
::
getAvailableSpace
()
/
1024
,
mqtt
::
connected
?
"Yes"
:
"No"
,
mqtt
::
last_successful_publish
,
config
::
mqtt_sending_interval
,
#if
defined(AMPEL_LORAWAN) &&
defined(ESP32)
#if defined(ESP32)
lorawan
::
connected
?
"Yes"
:
"No"
,
config
::
lorawan_frequency_plan
,
lorawan
::
last_transmission
,
config
::
lorawan_sending_interval
,
#endif
...
...
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