This document provides an overview of connecting IoT devices to the cloud using LoRaWAN and The Things Network. It discusses using sensors to monitor air pollution, noise and flooding in Skopje, Macedonia. It then provides a crash course on LoRaWAN, describing its features and limitations. The document outlines the basic hardware and software needed, including using Arduino, RN2483 chips and the LMIC library. It also discusses best practices for IoT systems architecture, such as decoupling, optimizing, and storing time-series data in Cassandra. The document concludes with some additional projects like forecasting, notifications and hardware security.
1 of 54
Downloaded 21 times
More Related Content
Gluing the IoT world with Java and LoRaWAN
1. Gluing the IoT world
with Java and LoRaWAN
Pance Cavkovski, Netcetera, jug.ch 12.09.2017
3. whoamisenior software engineer @ Netcetera
jug.mk Leader
codefu.mk admin
hardware & IoT enthusiast
TTN SK initiator
http://pance.mk/ and @hsilomedus
6. In the agenda for today
LoRaWAN crash-course
Hardware prototyping
Rules & Architecture for IoT systems
Software Development
Extras
7. Warning
The video youre about to see is made completely by a software
developer, and it is for demonstration purposes only.
If something similar is to meet the general public, it *will* be re-
implemented by a trained professional
9. SkopjePulse
Problems
- extreme air pollution
- excessive urban noise
- flash floods
No clear means for improvement
Solution
- leverage technology
- crowdsourced sensor network
- data analysis and availability
- warnings
- clearer insights and basis for
action
https://skopjepulse.mk/faq
11. LoRa
LongRange
Chirp Spread-spectrum radio modulation (~ OSI physical layer)
Low-power, long-range, low-cost communication enabler
Proprietary by Semtech
Can work on license-free ISM bands (433, 868, 915 MHz)
Multiple channels, multiple spreading factors
12. LoRaWAN
Long Range Wide Area Network
MAC layer on top of LoRa
De-facto the new IoT communication standard
Specification and development guided by LoRa Alliance
15. Limitations
Low-Speed: 250 5470 bps (configurable with SF and BW, distance
dependable)
Very small packages: (by provider) ~ 20 bytes
Less frequent: (by provider): 2-200 up/ 1-10 down
16. Class A LoRaWAN devices
One Uplink followed by two downlink windows (at 1s period)
OTAA or ABP authorization
Can be done with:
- RN2483 chip and sending MAC commands.
- RFM95w or similar with the LMIC library
17. LoRaWAN MAC example
mac reset 868
mac set rx2 3 869525000
mac set devaddr <devaddr>
mac set appskey <appSkey>
mac set nwkskey <nwkSkey>
mac set adr off
mac set ar off
mac set pwridx 1
mac set dr <datarate> (0 to 5)
mac save
mac join abp
mac tx uncnf 1 <dataToSend>
23. How to use TTN
Register at https://console.thethingsnetwork.org/
- Applications / devices
- Keys, UIDs, credentials
- Plugins / Integrations
24. Also in Switzerland
Swisscom LPN: http://lpn.swisscom.ch/e/
- Nationwide LoRa coverage
- Different offers based on intended traffic
Loriot
- provide distributed backend
- you provide the network devices and coverage
36. Decouple
Clear separation of concern
- data acquisition and transmission
- data offering
- web
- analytics / processing
Robustness, resilience, scaling, fallbacks
tl;dr: containers and orchestrators
37. Optimize
(almost) No overhead
- binary protocols
- always on
- react and store fast
- short physical distance
* Optimized MQTT is a good way to go.
38. Store
IoT data is almost always time-series based
Redundant and impartial data
Append only
Dont aggregate, but process
Live with eventual consistency
* Apache Cassandra is a good way to go
39. Skopje Pulse serverSkopje Pulse server Cassanda DBCassanda DB
LoRa GatewayLoRa Gateway
The Things NetworkThe Things Network Public data sourcePublic data source
MQTTMQTT
Sensor
RN2483
Sensor
RN2483
Sensor
RN2483
Data Collection
MicroService
Data Collection
MicroService
42. Getting to TTN
Spring Boot + Eclipse Paho client + Gson
- @Component client implementing MqttCallback
- connect in @PostConstruct
- @Scheduled(fixedrate = ) watchdog @Component
Details on MQTT URL, credentials and message formats:
https://www.thethingsnetwork.org/docs/network/migrate.html#mqtt
43. Storing data
Spring Boot + Cassandra Driver Core + Extras
- Cassandra Cluster wrapped in @Service
- InstantCodec for java.time interoperability
- QueryBuilder
- No data filtering.
spring-data-cassandra seems like a poor choice.
47. WiFi devices
Where you *really* cant do LoRaWAN
- ESP8266 powered device
- use TLS!!!
- provision device address securely
- implement own address -> key mapping
More: http://pance.mk/index.php/securing-esp8266-communication/
48. In the oven 1
Nostradamus Time-series forecast service
- trainer + executor based on Python + StatsModels + Pandas & ARIMA.
Averaging service
- periodically scheduled scenarios, processing and decisions
Watchdog sanity checker
- notifies sensor downtime and data irregularities
Water level sensors
- still in early phase. Based on water or sonic sensors.
49. In the oven 2
Notifications and warning service
- periodically analyses recent data
- sends digests to users
- filters out excessive situations and sends out warnings
- tweets for every digest and warning
50. Story 1: Hardware (dis)trust
Carefully select and inspect sensors
Test for correctness (if possible)
Beware of factory defects (cold sensitive RN2483)
51. Story 2: When its more than a number
Thunderstorm
PM10:
Forest fire (5km outside of the city)
52. Story 3: Share & inspire
Student projects ongoing
- Best caf辿 to sit at right now?
- Smart trash collection
- SkopjeDashboard