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
a77645b5
Commit
a77645b5
authored
Dec 25, 2020
by
Eric Duminil
Browse files
Trying to avoid conflict with ESP8266
parent
3cf93f02
Changes
3
Hide whitespace changes
Inline
Side-by-side
lorawan.cpp
View file @
a77645b5
#include
"lorawan.h"
#include
"lorawan.h"
#if defined(ESP32)
namespace
config
{
namespace
config
{
// Values should be defined in config.h
// Values should be defined in config.h
...
@@ -21,7 +22,6 @@ const lmic_pinmap lmic_pins = { .nss = 18, .rxtx = LMIC_UNUSED_PIN, .rst = 14, .
...
@@ -21,7 +22,6 @@ const lmic_pinmap lmic_pins = { .nss = 18, .rxtx = LMIC_UNUSED_PIN, .rst = 14, .
// More info : https://www.thethingsnetwork.org/docs/applications/mqtt/quick-start.html
// More info : https://www.thethingsnetwork.org/docs/applications/mqtt/quick-start.html
//TODO: Add infos to webserver (last timestamp, sending interval, connected or not?)
//TODO: Add infos to webserver (last timestamp, sending interval, connected or not?)
//TODO: Merge back to other branch (and other git)
//TODO: compile for both boards, and check ESP32 && LORA
//TODO: compile for both boards, and check ESP32 && LORA
void
os_getArtEui
(
u1_t
*
buf
)
{
void
os_getArtEui
(
u1_t
*
buf
)
{
...
@@ -141,15 +141,17 @@ namespace lorawan {
...
@@ -141,15 +141,17 @@ namespace lorawan {
}
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
]
=
(
min
(
max
(
sensor
::
co2
,
0
),
5100
)
+
10
)
/
20
;
buff
[
0
]
=
(
util
::
min
(
util
::
max
(
sensor
::
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
>
((
min
(
max
(
sensor
::
temperature
,
-
10
),
41
)
+
10.1
f
)
*
5
);
buff
[
1
]
=
static_cast
<
uint8_t
>
((
util
::
min
(
util
::
max
(
sensor
::
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
>
(
min
(
max
(
sensor
::
humidity
,
0
)
+
0.25
f
,
100
)
*
2
);
buff
[
2
]
=
static_cast
<
uint8_t
>
(
util
::
min
(
util
::
max
(
sensor
::
humidity
,
0
)
+
0.25
f
,
100
)
*
2
);
Serial
.
print
(
F
(
"LoRa - Payload : '
0x
"
));
Serial
.
print
(
F
(
"LoRa - Payload : '"
));
printHex2
(
buff
[
0
]);
printHex2
(
buff
[
0
]);
Serial
.
print
(
" "
);
printHex2
(
buff
[
1
]);
printHex2
(
buff
[
1
]);
Serial
.
print
(
" "
);
printHex2
(
buff
[
2
]);
printHex2
(
buff
[
2
]);
Serial
.
print
(
F
(
"', "
));
Serial
.
print
(
F
(
"', "
));
Serial
.
print
(
buff
[
0
]
*
20
);
Serial
.
print
(
buff
[
0
]
*
20
);
...
@@ -202,3 +204,4 @@ namespace lorawan {
...
@@ -202,3 +204,4 @@ namespace lorawan {
void
onEvent
(
ev_t
ev
)
{
void
onEvent
(
ev_t
ev
)
{
lorawan
::
onEvent
(
ev
);
lorawan
::
onEvent
(
ev
);
}
}
#endif
lorawan.h
View file @
a77645b5
#ifndef AMPEL_LORAWAN_H_
#ifndef AMPEL_LORAWAN_H_
#define AMPEL_LORAWAN_H_
#define AMPEL_LORAWAN_H_
#if defined(ESP32)
#include
<Arduino.h>
#include
<Arduino.h>
#include
<lmic.h>
#include
<lmic.h>
#include
<hal/hal.h>
#include
<hal/hal.h>
...
@@ -22,3 +22,4 @@ namespace lorawan {
...
@@ -22,3 +22,4 @@ namespace lorawan {
}
}
#endif
#endif
#endif
util.h
View file @
a77645b5
...
@@ -24,8 +24,18 @@ namespace ntp {
...
@@ -24,8 +24,18 @@ namespace ntp {
String
getLocalTime
();
String
getLocalTime
();
}
}
#define max(a,b) ((a)>(b)?(a):(b))
namespace
util
{
#define min(a,b) ((a)<(b)?(a):(b))
template
<
typename
Tpa
,
typename
Tpb
>
inline
auto
min
(
const
Tpa
&
a
,
const
Tpb
&
b
)
->
decltype
(
a
<
b
?
a
:
b
)
{
return
b
<
a
?
b
:
a
;
}
template
<
typename
Tpa
,
typename
Tpb
>
inline
auto
max
(
const
Tpa
&
a
,
const
Tpb
&
b
)
->
decltype
(
b
>
a
?
b
:
a
)
{
return
b
>
a
?
b
:
a
;
}
}
#define seconds() (millis() / 1000UL)
#define seconds() (millis() / 1000UL)
extern
uint32_t
max_loop_duration
;
extern
uint32_t
max_loop_duration
;
const
extern
String
SENSOR_ID
;
const
extern
String
SENSOR_ID
;
...
...
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