Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the...

41
Panche Chavkovski 2018-02-06 / Jfokus The SkopjePulse.mk case Gluing the IoT world with Java and LoRaWAN

Transcript of Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the...

Page 1: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Panche Chavkovski2018-02-06 / Jfokus

The SkopjePulse.mk case

Gluing the IoT world with Java and LoRaWAN

Page 2: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Who am I?

2

Senior Software Engineer @ netceterajug.mk Leader

Codefu.mk administratorHardware & IoT enthusiast

TTN SK Initiator

http://pance.mk/ and @hsilomedus

Panche Chavkovski

Page 3: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

3

Page 4: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

SkopjePulse

§ extreme air pollution

§ Excessive urban noise§ Flash floods

No clear means for improvement

§ Leverage technology§ Crowd-sourced sensor network§ Data analysis and availability§ Warnings§ Clearer insights§ Data-driven basis for action

https://skopjepulse.mk/faq

SolutionProblems

4

Page 5: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

System overview

Analytics

MobileappsData Storage

LoRaWAN

Devices

Data FetchingFront-end &

API

Warnings

5

!

Page 6: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

LoRaWAN

6

Page 7: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

LoRa & LoRaWAN

§ Based on FSK & CSS, multiple channels

§ Low Power§ Low Cost§ Long range

§ Free ISM bands: 433, 868, 915 MHz§ Proprietary by Semtech

§ MAC layer on top of LoRa

§ IoT communication standard

§ Standardized stack

§ Driven by LoRa Alliance

Long Range Wide Area NetworkLong Range

7

Page 8: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Fully bi-directional

End-to-end security

Easy commisioning

Built-in positioning

Network scalability

Features

8

Page 9: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Limitations

Low speed (default BW)§ SF12: 250bps with the farthest distance and the longest air-time§ SF7: 5470bps with the shortest distance and the shortest air-time

Small package sizes: ~1-20bytes

Less frequent§ 2-200 uplinks per day§ 1-10 downlinks per day

9

Page 10: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

LoRaWAN architecture

10

End nodes Gateway / concentrator Network server(s) Application server(s)

LoRa RFLoRaWAN

TCP/IP SSLLoRaWAN

TCP/IP SSLSecure payload

AES secured payload

Page 11: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

LoRaWAN devices

Different classes§ Class A, rare async devices (current): one uplink with two downlink windows§ Class B, always on, timed: beacon downlink windows§ Class C, always on, always listening.

Network sign on:§ Over The Air Authorization (OTAA): App EUI and Key§ Authorization By Personalization (ABP): App / Network keys and Device address

11

Page 12: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

TheThingsNetwork

12

Global, crowdsourced Internet Of Things data network

§ Community driven with local initiators and teams

§ Provided network and back-end

§ Free for fair use

§ Can be elevated to SLA (private – public partnership)

§ Multiple integration options

§ LoRaWAN as base technology

https://www.thethingsnetwork.org/

Page 13: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

How to use TTN

https://console.thethingsnetwork.org/

§ Applications§ Devices§ Keys, UIDs, Credentials

§ MQTT

§ HTTP§ Data storage§ Amazon AWS

§ Cayenne§ EVRYTHNG

IntegrationsRegistration

13

Page 14: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Devices

14

Page 15: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Microchip RN2483 (LoRaWAN stack)

Arduino (MCU)

RFM95W (LoRa transceiver)

El. Design & PCB CAD Software

The start up kit

15

Page 16: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

KiCAD usage

16

Scheme design

PCB design

3D render and gerbers

Page 17: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Assembly

17

PCB fabrication

Solder and connect

3D printed enclosure

Page 18: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Make it work

§ Arduino or other embedded code

§ Restricted environment– 32KB flash

– 2KB RAM

– 16MHz CPU

§ Perpetual non-observed execution

§ Select and inspect used sensors

§ Test and / or calibrate§ Check for factory defects§ Plan for hardware wear-out and lifespan

§ Don’t assume anything

BewareCode

18

Page 19: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

System design

19

Page 20: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Rules to go by

§ Data transceiver

§ Data Store§ Web and API§ Analytics & processing

§ Robustness

§ Scaling§ Fallbacks§ Data sanity

Aim for and produceDecouple

20

Page 21: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Our approach

SpringBoot framework§ Self contained web server / application§ Modular§ Starter packs for needed spring pieces§ Less configuration, more conventions§ Light(er)weight§ Container and orchestrator friendly (Cloud native)

21

Page 22: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Data fetching

22

Page 23: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Communication first!

(almost) No overhead§ Use binary protocols if possible§ Always on connection

– reconnect fast– plan for fallback

React first, store later!

Get closer to the data source.

23

Page 24: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Our approach

TheThingsNetwork MQTT Integration

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/applications/mqtt/api.html

24

Page 25: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Data storage

25

Page 26: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

IoT data

IoT data is almost always impartial and time-series based

Use data store that is designed for sorted time-series§ Utilize recent data caches or TTLs§ Don’t hold on redundancies§ Always just append data§ Never aggregate, but process and store§ Design to live with eventual consistency

26

Page 27: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Our approach

Cassandra DB 3.7

Spring Boot + Cassandra Driver Core + Extras§ Cassandra Cluster wrapped in @Service§ InstantCodec for java.time interoperability§ QueryBuilder§ No data filtering.

* spring-data-cassandra seemed like a poor choice.

27

Page 28: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Analytics

28

Page 29: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Averaging data

§ A lot of (impartial) data

§ Observed system load§ Possible downtime§ Retroactivity

§ Side-running SpringBoot microservice

§ Runs a few times a day§ Checks first§ Calculates last two days, week and month

§ Uses intermediary data§ Uses simple heuristic

Our approachSituation

29

Page 30: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Warnings

30

!

Page 31: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Early warning system

Keep a track on what’s happening§ Periodically fetch the recent data§ Analyze, produce and save current state§ Notify if the state has changed significantly§ Don’t spam§ Periodically cleanup

Our approach: SpringBoot + SpringSocial + Firebase

31

Page 32: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Front-end & API

32

Page 33: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Provide and visualize the data

Interactive cockpit and data explorers§ D3js client side visualizations§ Leaflet.js + OpenStreetMap

(+ Stamen designs)

Provide open to use API§ SpringBoot + SpringMVC +

SpringSecurity§ Set rules to avoid easy DOS§ Log usage§ Circuit breakers

33https://skopjepulse.mk/new

Page 34: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Control the system

SPA for device and user management§ Angular2§ ng2-admin

System health dashboard

34

Page 35: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Mobile apps

35

Page 36: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Native Android and iOS apps

36

Page 37: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

Extras

37

Page 38: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

WiFi devices

Where you *really* can’t do LoRaWAN§ ESP8266 powered device § HTTPS communication§ provision device address securely§ implement own address -> key mapping

More: http://pance.mk/index.php/securing-esp8266-communication/

38

Page 39: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

AWS This is my architecture

39

http://tiny.cc/awsttn

Page 40: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

40

Discussion

Page 41: Gluing the IoTworld with Java and LoRaWAN...Limitations Low speed (default BW) SF12: 250bps with the farthest distance and the longest air -time SF7: 5470bps with the shortest distance

41

Thank you