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
c6e782c1
Commit
c6e782c1
authored
Dec 25, 2020
by
Eric Duminil
Browse files
Show LoRaWAN info on web server
parent
bf5954da
Changes
5
Hide whitespace changes
Inline
Side-by-side
lorawan.cpp
View file @
c6e782c1
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
namespace
config
{
namespace
config
{
// Values should be defined in config.h
// Values should be defined in config.h
uint16_t
lora_sending_interval
=
LORAWAN_SENDING_INTERVAL
;
// [s]
uint16_t
lora
wan
_sending_interval
=
LORAWAN_SENDING_INTERVAL
;
// [s]
static
const
u1_t
PROGMEM
APPEUI
[
8
]
=
LORAWAN_APPLICATION_EUI
;
static
const
u1_t
PROGMEM
APPEUI
[
8
]
=
LORAWAN_APPLICATION_EUI
;
static
const
u1_t
PROGMEM
DEVEUI
[
8
]
=
LORAWAN_DEVICE_EUI
;
static
const
u1_t
PROGMEM
DEVEUI
[
8
]
=
LORAWAN_DEVICE_EUI
;
...
@@ -21,7 +21,6 @@ const lmic_pinmap lmic_pins = { .nss = 18, .rxtx = LMIC_UNUSED_PIN, .rst = 14, .
...
@@ -21,7 +21,6 @@ const lmic_pinmap lmic_pins = { .nss = 18, .rxtx = LMIC_UNUSED_PIN, .rst = 14, .
// 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}]}}
// 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
// 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: Test with config.public.h
//TODO: Test with config.public.h
//TODO: Test with EPS8266
//TODO: Test with EPS8266
...
@@ -39,6 +38,8 @@ void os_getDevKey(u1_t *buf) {
...
@@ -39,6 +38,8 @@ void os_getDevKey(u1_t *buf) {
namespace
lorawan
{
namespace
lorawan
{
bool
waiting_for_confirmation
=
false
;
bool
waiting_for_confirmation
=
false
;
bool
connected
=
false
;
String
last_transmission
=
""
;
void
printHex2
(
unsigned
v
)
{
void
printHex2
(
unsigned
v
)
{
v
&=
0xff
;
v
&=
0xff
;
...
@@ -48,18 +49,16 @@ namespace lorawan {
...
@@ -48,18 +49,16 @@ namespace lorawan {
}
}
void
onEvent
(
ev_t
ev
)
{
void
onEvent
(
ev_t
ev
)
{
static
bool
trying_to_join
=
false
;
Serial
.
print
(
"LoRa - "
);
Serial
.
print
(
"LoRa - "
);
Serial
.
print
(
ntp
::
getLocalTime
());
Serial
.
print
(
ntp
::
getLocalTime
());
Serial
.
print
(
" - "
);
Serial
.
print
(
" - "
);
switch
(
ev
)
{
switch
(
ev
)
{
case
EV_JOINING
:
case
EV_JOINING
:
trying_to_join
=
true
;
Serial
.
println
(
F
(
"EV_JOINING"
));
Serial
.
println
(
F
(
"EV_JOINING"
));
break
;
break
;
case
EV_JOINED
:
case
EV_JOINED
:
trying_to_join
=
false
;
waiting_for_confirmation
=
false
;
waiting_for_confirmation
=
false
;
connected
=
true
;
LedEffects
::
onBoardLEDOff
();
LedEffects
::
onBoardLEDOff
();
Serial
.
println
(
F
(
"EV_JOINED"
));
Serial
.
println
(
F
(
"EV_JOINED"
));
{
{
...
@@ -100,17 +99,11 @@ namespace lorawan {
...
@@ -100,17 +99,11 @@ namespace lorawan {
Serial
.
println
(
F
(
"EV_REJOIN_FAILED"
));
Serial
.
println
(
F
(
"EV_REJOIN_FAILED"
));
break
;
break
;
case
EV_TXCOMPLETE
:
case
EV_TXCOMPLETE
:
Serial
.
println
(
F
(
"EV_TXCOMPLETE (includes waiting for RX windows)"
));
last_transmission
=
ntp
::
getLocalTime
();
if
(
LMIC
.
txrxFlags
&
TXRX_ACK
)
Serial
.
println
(
F
(
"EV_TXCOMPLETE"
));
Serial
.
println
(
F
(
"Received ack"
));
if
(
LMIC
.
dataLen
)
{
Serial
.
print
(
F
(
"Received "
));
Serial
.
print
(
LMIC
.
dataLen
);
Serial
.
println
(
F
(
" bytes of payload"
));
}
break
;
break
;
case
EV_TXSTART
:
case
EV_TXSTART
:
waiting_for_confirmation
=
trying_to_join
;
waiting_for_confirmation
=
!
connected
;
Serial
.
println
(
F
(
"EV_TXSTART"
));
Serial
.
println
(
F
(
"EV_TXSTART"
));
break
;
break
;
case
EV_TXCANCELED
:
case
EV_TXCANCELED
:
...
@@ -195,7 +188,7 @@ namespace lorawan {
...
@@ -195,7 +188,7 @@ namespace lorawan {
void
preparePayloadIfTimehasCome
()
{
void
preparePayloadIfTimehasCome
()
{
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
::
lora_sending_interval
)
{
if
(
now
-
last_sent_at
>
config
::
lora
wan
_sending_interval
)
{
last_sent_at
=
now
;
last_sent_at
=
now
;
preparePayload
();
preparePayload
();
}
}
...
...
lorawan.h
View file @
c6e782c1
...
@@ -16,8 +16,14 @@ typedef uint8_t u1_t;
...
@@ -16,8 +16,14 @@ typedef uint8_t u1_t;
#include
"util.h"
#include
"util.h"
namespace
config
{
extern
uint16_t
lorawan_sending_interval
;
// [s]
}
namespace
lorawan
{
namespace
lorawan
{
extern
bool
waiting_for_confirmation
;
extern
bool
waiting_for_confirmation
;
extern
bool
connected
;
extern
String
last_transmission
;
void
initialize
();
void
initialize
();
void
process
();
void
process
();
void
preparePayloadIfTimehasCome
();
void
preparePayloadIfTimehasCome
();
...
...
mqtt.cpp
View file @
c6e782c1
...
@@ -46,10 +46,10 @@ namespace mqtt {
...
@@ -46,10 +46,10 @@ namespace mqtt {
snprintf
(
payload
,
sizeof
(
payload
),
json_sensor_format
,
timestamp
.
c_str
(),
co2
,
temperature
,
humidity
);
snprintf
(
payload
,
sizeof
(
payload
),
json_sensor_format
,
timestamp
.
c_str
(),
co2
,
temperature
,
humidity
);
// Topic is the same as clientID. e.g. 'CO2sensors/ESP3d03da'
// Topic is the same as clientID. e.g. 'CO2sensors/ESP3d03da'
if
(
mqttClient
.
publish
(
publish_topic
.
c_str
(),
payload
))
{
if
(
mqttClient
.
publish
(
publish_topic
.
c_str
(),
payload
))
{
Serial
.
println
(
"OK"
);
Serial
.
println
(
F
(
"OK"
)
)
;
last_successful_publish
=
ntp
::
getLocalTime
();
last_successful_publish
=
ntp
::
getLocalTime
();
}
else
{
}
else
{
Serial
.
println
(
"Failed."
);
Serial
.
println
(
F
(
"Failed."
)
)
;
}
}
LedEffects
::
onBoardLEDOff
();
LedEffects
::
onBoardLEDOff
();
}
}
...
...
web_server.cpp
View file @
c6e782c1
...
@@ -87,6 +87,11 @@ namespace web_server {
...
@@ -87,6 +87,11 @@ namespace web_server {
#ifdef MQTT
#ifdef MQTT
"<tr><td>Last MQTT publish</td><td>%s</td></tr>
\n
"
"<tr><td>Last MQTT publish</td><td>%s</td></tr>
\n
"
"<tr><td>MQTT publish timestep</td><td>%5d s</td></tr>
\n
"
"<tr><td>MQTT publish timestep</td><td>%5d s</td></tr>
\n
"
#endif
#if defined(LORAWAN) && defined(ESP32)
"<tr><td>Connected to LoRaWAN?</td><td>%s</td></tr>
\n
"
"<tr><td>Last LoRaWAN transmission</td><td>%s</td></tr>
\n
"
"<tr><td>LoRaWAN publish timestep</td><td>%5d s</td></tr>
\n
"
#endif
#endif
"<tr><td>Temperature offset</td><td>%.1fK</td></tr>
\n
"
//TODO: Read it from sensor?
"<tr><td>Temperature offset</td><td>%.1fK</td></tr>
\n
"
//TODO: Read it from sensor?
"<tr><td>Local address</td><td><a href='http://%s.local/'>%s.local</a></td></tr>
\n
"
"<tr><td>Local address</td><td><a href='http://%s.local/'>%s.local</a></td></tr>
\n
"
...
@@ -196,6 +201,9 @@ namespace web_server {
...
@@ -196,6 +201,9 @@ namespace web_server {
csv_writer
::
last_successful_write
.
c_str
(),
config
::
csv_interval
,
csv_writer
::
last_successful_write
.
c_str
(),
config
::
csv_interval
,
#ifdef MQTT
#ifdef MQTT
mqtt
::
last_successful_publish
.
c_str
(),
config
::
sending_interval
,
mqtt
::
last_successful_publish
.
c_str
(),
config
::
sending_interval
,
#endif
#if defined(LORAWAN) && defined(ESP32)
lorawan
::
connected
?
"Yes"
:
"No"
,
lorawan
::
last_transmission
.
c_str
(),
config
::
lorawan_sending_interval
,
#endif
#endif
config
::
temperature_offset
,
SENSOR_ID
.
c_str
(),
SENSOR_ID
.
c_str
(),
WiFi
.
localIP
().
toString
().
c_str
(),
config
::
temperature_offset
,
SENSOR_ID
.
c_str
(),
SENSOR_ID
.
c_str
(),
WiFi
.
localIP
().
toString
().
c_str
(),
WiFi
.
localIP
().
toString
().
c_str
(),
get_free_heap_size
(),
available_fs_space
,
max_loop_duration
,
BOARD
,
hh
,
mm
,
WiFi
.
localIP
().
toString
().
c_str
(),
get_free_heap_size
(),
available_fs_space
,
max_loop_duration
,
BOARD
,
hh
,
mm
,
...
...
web_server.h
View file @
c6e782c1
...
@@ -13,6 +13,9 @@
...
@@ -13,6 +13,9 @@
#ifdef MQTT
#ifdef MQTT
# include "mqtt.h"
# include "mqtt.h"
#endif
#endif
#ifdef LORAWAN
# include "lorawan.h"
#endif
namespace
web_server
{
namespace
web_server
{
void
initialize
();
void
initialize
();
...
...
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