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
00cd00e2
Commit
00cd00e2
authored
Feb 15, 2022
by
Eric Duminil
Browse files
Soon
parent
31c74498
Changes
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/lorawan.cpp
View file @
00cd00e2
...
...
@@ -48,16 +48,51 @@ namespace config {
// co2ampel-test/devices/esp3a7c94/up {"app_id":"co2ampel-test","dev_id":"esp3a7c94","hardware_serial":"00xxxxxxxx","port":1,"counter":5,"payload_raw":"TJd7","payload_fields":{"co2":760,"rh":61.5,"temp":20.2},"metadata":{"time":"2020-12-23T23:00:51.44020438Z","frequency":867.5,"modulation":"LORA","data_rate":"SF7BW125","airtime":51456000,"coding_rate":"4/5","gateways":[{"gtw_id":"eui-xxxxxxxxxxxxxxxxxx","timestamp":1765406908,"time":"2020-12-23T23:00:51.402519Z","channel":5,"rssi":-64,"snr":7.5,"rf_chain":0,"latitude":22.7,"longitude":114.24,"altitude":450}]}}
// More info : https://www.thethingsnetwork.org/docs/applications/mqtt/quick-start.html
uint8_t
hexToByte
(
char
c
)
{
int
v
=
-
1
;
if
((
c
>=
'0'
)
&&
(
c
<=
'9'
))
{
v
=
(
c
-
'0'
);
}
else
if
((
c
>=
'A'
)
&&
(
c
<=
'F'
))
{
v
=
(
c
-
'A'
+
10
);
}
else
if
((
c
>=
'a'
)
&&
(
c
<=
'f'
))
{
v
=
(
c
-
'a'
+
10
);
}
return
v
;
}
void
parseConfig
(
uint8_t
*
buf
,
const
char
*
hex
,
uint
max_n
,
int
step
)
{
int
n
=
util
::
min
(
strlen
(
hex
)
/
2
,
max_n
);
Serial
.
println
(
hex
);
Serial
.
print
(
"Size : "
);
Serial
.
println
(
n
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
uint8_t
r
=
hexToByte
(
hex
[
i
*
2
])
*
16
+
hexToByte
(
hex
[
i
*
2
+
1
]);
buf
[
i
]
=
r
;
}
for
(
int
var
=
0
;
var
<
max_n
;
++
var
)
{
Serial
.
print
(
buf
[
var
],
HEX
);
Serial
.
print
(
" "
);
}
Serial
.
println
();
Serial
.
println
(
"-----"
);
}
void
os_getArtEui
(
u1_t
*
buf
)
{
memcpy_P
(
buf
,
config
::
APPEUI
,
8
);
parseConfig
(
buf
,
config
::
lorawan_app_eui
,
8
,
-
1
);
// memcpy_P(buf, config::APPEUI, 8);
}
void
os_getDevEui
(
u1_t
*
buf
)
{
memcpy_P
(
buf
,
config
::
DEVEUI
,
8
);
parseConfig
(
buf
,
config
::
lorawan_device_eui
,
8
,
-
1
);
// memcpy_P(buf, config::DEVEUI, 8);
}
void
os_getDevKey
(
u1_t
*
buf
)
{
memcpy_P
(
buf
,
config
::
APPKEY
,
16
);
parseConfig
(
buf
,
config
::
lorawan_app_key
,
16
,
1
);
// memcpy_P(buf, config::APPKEY, 16);
}
namespace
lorawan
{
...
...
@@ -65,43 +100,11 @@ namespace lorawan {
bool
connected
=
false
;
char
last_transmission
[
23
]
=
""
;
uint8_t
hexToByte
(
char
c
)
{
int
v
=
-
1
;
if
((
c
>=
'0'
)
&&
(
c
<=
'9'
))
{
v
=
(
c
-
'0'
);
}
else
if
((
c
>=
'A'
)
&&
(
c
<=
'F'
))
{
v
=
(
c
-
'A'
+
10
);
}
else
if
((
c
>=
'a'
)
&&
(
c
<=
'f'
))
{
v
=
(
c
-
'a'
+
10
);
}
return
v
;
}
void
parseConfig
(
const
char
*
hex
)
{
int
n
=
strlen
(
hex
);
Serial
.
println
(
hex
);
Serial
.
print
(
"Size : "
);
Serial
.
println
(
n
);
for
(
int
i
=
0
;
i
<
n
;
i
=
i
+
2
)
{
uint8_t
r
=
hexToByte
(
hex
[
i
])
<<
4
|
hexToByte
(
hex
[
i
+
1
]);
Serial
.
print
(
r
,
HEX
);
Serial
.
print
(
" "
);
}
Serial
.
println
();
Serial
.
println
(
"-----"
);
}
void
initialize
()
{
Serial
.
print
(
F
(
"Starting LoRaWAN. Frequency plan : "
));
Serial
.
print
(
config
::
lorawan_frequency_plan
);
Serial
.
println
(
F
(
" MHz."
));
parseConfig
(
config
::
lorawan_device_eui
);
parseConfig
(
config
::
lorawan_app_eui
);
parseConfig
(
config
::
lorawan_app_key
);
// More info about pin mapping : https://github.com/mcci-catena/arduino-lmic#pin-mapping
// Has been tested successfully with ESP32 TTGO LoRa32 V1, and might work with other ESP32+LoRa boards.
const
lmic_pinmap
*
pPinMap
=
Arduino_LMIC
::
GetPinmap_ThisBoard
();
...
...
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