Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Käppler
ampel-firmware
Commits
d8733548
Commit
d8733548
authored
Dec 26, 2020
by
Eric Duminil
Browse files
One fewer dependency
parent
d5eeba11
Changes
3
Show whitespace changes
Inline
Side-by-side
ampel-firmware.ino
View file @
d8733548
...
@@ -142,7 +142,7 @@ void loop() {
...
@@ -142,7 +142,7 @@ void loop() {
#endif
#endif
#if defined(LORAWAN) && defined(ESP32)
#if defined(LORAWAN) && defined(ESP32)
lorawan
::
preparePayloadIfTime
h
asCome
();
lorawan
::
preparePayloadIfTime
H
asCome
(
sensor
::
co2
,
sensor
::
temperature
,
sensor
::
humidity
);
#endif
#endif
}
}
...
...
lorawan.cpp
View file @
d8733548
...
@@ -143,18 +143,18 @@ namespace lorawan {
...
@@ -143,18 +143,18 @@ namespace lorawan {
}
}
}
}
void
preparePayload
()
{
void
preparePayload
(
int16_t
co2
,
float
temperature
,
float
humidity
)
{
// Check if there is not a current TX/RX job running
// Check if there is not a current TX/RX job running
if
(
LMIC
.
opmode
&
OP_TXRXPEND
)
{
if
(
LMIC
.
opmode
&
OP_TXRXPEND
)
{
Serial
.
println
(
F
(
"OP_TXRXPEND, not sending"
));
Serial
.
println
(
F
(
"OP_TXRXPEND, not sending"
));
}
else
{
}
else
{
uint8_t
buff
[
3
];
uint8_t
buff
[
3
];
// Mapping CO2 from 0ppm to 5100ppm to [0, 255], with 20ppm increments.
// Mapping CO2 from 0ppm to 5100ppm to [0, 255], with 20ppm increments.
buff
[
0
]
=
(
util
::
min
(
util
::
max
(
sensor
::
co2
,
0
),
5100
)
+
10
)
/
20
;
buff
[
0
]
=
(
util
::
min
(
util
::
max
(
co2
,
0
),
5100
)
+
10
)
/
20
;
// Mapping temperatures from [-10°C, 41°C] to [0, 255], with 0.2°C increment
// Mapping temperatures from [-10°C, 41°C] to [0, 255], with 0.2°C increment
buff
[
1
]
=
static_cast
<
uint8_t
>
((
util
::
min
(
util
::
max
(
sensor
::
temperature
,
-
10
),
41
)
+
10.1
f
)
*
5
);
buff
[
1
]
=
static_cast
<
uint8_t
>
((
util
::
min
(
util
::
max
(
temperature
,
-
10
),
41
)
+
10.1
f
)
*
5
);
// Mapping humidity from [0%, 100%] to [0, 200], with 0.5°C increment (0.4°C would also be possible)
// Mapping humidity from [0%, 100%] to [0, 200], with 0.5°C increment (0.4°C would also be possible)
buff
[
2
]
=
static_cast
<
uint8_t
>
(
util
::
min
(
util
::
max
(
sensor
::
humidity
,
0
)
+
0.25
f
,
100
)
*
2
);
buff
[
2
]
=
static_cast
<
uint8_t
>
(
util
::
min
(
util
::
max
(
humidity
,
0
)
+
0.25
f
,
100
)
*
2
);
Serial
.
print
(
F
(
"LoRa - Payload : '"
));
Serial
.
print
(
F
(
"LoRa - Payload : '"
));
printHex2
(
buff
[
0
]);
printHex2
(
buff
[
0
]);
...
@@ -183,12 +183,12 @@ namespace lorawan {
...
@@ -183,12 +183,12 @@ namespace lorawan {
}
}
}
}
void
preparePayloadIfTime
h
asCome
()
{
void
preparePayloadIfTime
H
asCome
(
int16_t
co2
,
float
temperature
,
float
humidity
)
{
static
unsigned
long
last_sent_at
=
0
;
static
unsigned
long
last_sent_at
=
0
;
unsigned
long
now
=
seconds
();
unsigned
long
now
=
seconds
();
if
(
now
-
last_sent_at
>
config
::
lorawan_sending_interval
)
{
if
(
now
-
last_sent_at
>
config
::
lorawan_sending_interval
)
{
last_sent_at
=
now
;
last_sent_at
=
now
;
preparePayload
();
preparePayload
(
co2
,
temperature
,
humidity
);
}
}
}
}
}
}
...
...
lorawan.h
View file @
d8733548
...
@@ -9,7 +9,6 @@
...
@@ -9,7 +9,6 @@
#include
<arduino_lmic_hal_boards.h>
#include
<arduino_lmic_hal_boards.h>
#include
<SPI.h>
#include
<SPI.h>
#include
"co2_sensor.h"
#include
"led_effects.h"
#include
"led_effects.h"
#include
"config.h"
#include
"config.h"
...
@@ -41,7 +40,7 @@ namespace lorawan {
...
@@ -41,7 +40,7 @@ namespace lorawan {
extern
String
last_transmission
;
extern
String
last_transmission
;
void
initialize
();
void
initialize
();
void
process
();
void
process
();
void
preparePayloadIfTime
h
asCome
();
void
preparePayloadIfTime
H
asCome
(
int16_t
co2
,
float
temp
,
float
hum
);
}
}
#endif
#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