Top Banner
@johanjanssen42 #VoxxedBerlin THE INTERNET OF (LEGO) TRAINS Martin Kanters, Info Support Johan Janssen, Info Support, @johanjanssen42
80

The internet of (lego) trains

Apr 12, 2017

Download

Software

Grzegorz Duda
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The internet of (lego) trains

@johanjanssen42#VoxxedBerlin

THE INTERNET OF (LEGO) TRAINS

Martin Kanters, Info SupportJohan Janssen, Info Support, @johanjanssen42

Page 2: The internet of (lego) trains
Page 3: The internet of (lego) trains

Disclaimer: No Lego was harmed beyondrepair during the project.

Page 4: The internet of (lego) trains

CONTENT

Why?

Ingredients

Architecture

Hardware

Application

Challenges

Scala and Akka

Future

Conclusion

Questions

Page 5: The internet of (lego) trains

Why?

Page 6: The internet of (lego) trains

MINIMAL INGREDIENTS FOR 1 TRAIN ABOUT € 50

Raspberry Pi A+

Wifi dongleEDUP Ultra-Mini Nano USB 2.0 802.11n

USB battery packAnker® 2. Gen Astro Mini 3200mAh

Infrared transmitterKeyes 38KHz IR Infrared Transmitter Module for

Arduino

Page 7: The internet of (lego) trains
Page 8: The internet of (lego) trains

OTHER INGREDIENTS

Lego trains and tracks with power functions

RFID-RC522 RF IC Card Sensor Module

Mini Portable Speaker for the Raspberry Pi

Raspberry Pi’s and Raspberry Pi camera’s

Cables like Breadboard wires/USB

Electronics like servo’s etcetera

Page 9: The internet of (lego) trains

COMPARISON

Idle (mA) Memory (MB) CPU (Mhz) Size (mm)

RPi A+ 180-240 256 700 65 *56

RPi Zero 30 512 1000 65 * 30

RPi B+ 230-240 512 700 85 *56

RPi 2 B 420 1024 4*900 85 *56

Odroid C1 325 1024 4*1500 85 *56

Particle Photon

80-100 128KB 120 38 * 21

Page 10: The internet of (lego) trains

Architecture

Page 11: The internet of (lego) trains

LTCC

(Angular)

LTCC

(Java)

DeviceControl

(Java)

Infrared

(C and LIRC)

RFID

(C)

SwitchControl

(Java)

Servo

(Python)

RPi-Cam-Web-Interface

(C)

Page 12: The internet of (lego) trains

LTCC (Laptop)SwitchControl (Pi) Camera (Pi)

DeviceControl

(Pi)

Page 13: The internet of (lego) trains

Hardware

Page 14: The internet of (lego) trains

Original controls

Page 15: The internet of (lego) trains

Infrared

Page 16: The internet of (lego) trains

KeyesInfrared

Transmitter & receiver

GND, 5V, GPIO 17

GPIO 18, 3.3V, GND

Page 17: The internet of (lego) trains

Channels

Page 18: The internet of (lego) trains

Out

Page 19: The internet of (lego) trains

CALLING THE APPLICATION

http://ipaddress/cgi-bin/test/?ch=0&out=1&cmd=1&spd=3

ch: channel (there are 8)

out: output

cmd: command 0 Break

1 Forward

2 Backward

spd: speed (not necesarry with command ‘Break’)

Page 20: The internet of (lego) trains

@Path("train")

public class TrainService {

@GET

@Path("{channelParam}/forward/{speedParam}")

public void forward(@PathParam("channelParam") String channel,

@PathParam("speedParam") String speed) {

String command = "1";

callURL(channel, command, speed);

}

private void callURL(String channel, String command, String speed) {

StringBuilder result = new StringBuilder();

result.append("http://127.0.0.1/cgi-bin/test/?ch=");

result.append(channel);

result.append("&out=1&cmd=");

result.append(command);

if (speed != null) {

result.append("&spd=");

result.append(speed);

}

URL url = new URL(result.toString());

InputStream is = url.openStream();

}

}

Page 21: The internet of (lego) trains

Sound

Page 22: The internet of (lego) trains

RFID

3.3 V, GPIO25, GND, -, GPIO9, GPIO 10, GPIO11, GPIO 8

Page 23: The internet of (lego) trains
Page 24: The internet of (lego) trains
Page 25: The internet of (lego) trains

CONFIGURE RFID READER

Execute action after reading specific RFID

[a419d15f] curl http://localhost:8080/.../a419d15f

[f2d98c45] curl http://localhost:8080/.../f2d98c45

Use /etc/rc.local to start the RFID reader on boot

Page 26: The internet of (lego) trains

Camera

Page 27: The internet of (lego) trains
Page 28: The internet of (lego) trains
Page 29: The internet of (lego) trains

RPI CAM WEB INTERFACE

<!DOCTYPE html><html><head><title>RPi Cam Preview</title><script src="script_min.js"></script>

</head><body onload="setTimeout('init();', 100);"><center><div><img id="mjpeg_dest" /></div>

</center></body></html>

Page 30: The internet of (lego) trains

Overviewcamera

Page 31: The internet of (lego) trains
Page 32: The internet of (lego) trains

Switches

Page 33: The internet of (lego) trains

INGREDIENTS

Raspberry Pi A+

Adafruit Servo Driver PCA9685

60W adapter Volt

FeeTech FS5103B servo’s

Some cables

Paperclips

Page 34: The internet of (lego) trains

private void sendCommandToSwitch(String switchid, String direction) {

String[] cmd = {"python","…./Servo_Example.py", switchid, direction

};Runtime.getRuntime().exec(cmd);

}

Page 35: The internet of (lego) trains
Page 36: The internet of (lego) trains
Page 37: The internet of (lego) trains
Page 38: The internet of (lego) trains

LTCC APPLICATION

Page 39: The internet of (lego) trains

AUTOPILOT APPLICATION

Page 40: The internet of (lego) trains

SOFTWARE

Twitter Bootstrap

Angular Seed

Angular

Bower

NPM

Java

Jersey

Maven

Libraries for RFID, infrared, servo’s and camera

Page 41: The internet of (lego) trains

Challenges

Page 42: The internet of (lego) trains
Page 43: The internet of (lego) trains
Page 44: The internet of (lego) trains
Page 45: The internet of (lego) trains
Page 46: The internet of (lego) trains
Page 47: The internet of (lego) trains
Page 48: The internet of (lego) trains
Page 49: The internet of (lego) trains
Page 50: The internet of (lego) trains
Page 51: The internet of (lego) trains
Page 52: The internet of (lego) trains
Page 53: The internet of (lego) trains
Page 54: The internet of (lego) trains
Page 55: The internet of (lego) trains
Page 56: The internet of (lego) trains
Page 57: The internet of (lego) trains

SCALA AND AKKA

Page 58: The internet of (lego) trains

LTCC

(Angular)

LTCC

(Scala/Akka)

DeviceControl

(Scala/Akka)

Infrared

(C and LIRC)

RFID

(C)

SwitchControl

(Scala/Akka)

Servo

(Python)

Leds with Photon

(C)

RPi-Cam-Web-Interface

(C)

Page 59: The internet of (lego) trains

class Coordinator extends Actor {def receive = {case x =>println(x)

}}

implicit val system = ActorSystem("ExampleActorSystem")

val coordinatorActorRef = system.actorOf(Props[Coordinator])coordinatorActorRef ! "Hello conference"

Page 60: The internet of (lego) trains

val coordinatorActorRef = system.actorOf(Props[Coordinator])coordinatorActorRef ! "Hello conference"

val coordinatorActorRef = context.actorSelection("akka.tcp://[email protected]:9005/user/coordinatorActor")

coordinatorActorRef ! "Hello conference"

Page 61: The internet of (lego) trains

akka {actor {provider = "akka.remote.RemoteActorRefProvider"

}remote {enabled-transports =

["akka.remote.netty.tcp"]netty.tcp {hostname = "127.0.0.1"port = 9002

Page 62: The internet of (lego) trains

HTTP VS REMOTE ACTOR

Page 63: The internet of (lego) trains

ADVANTAGES REMOTE ACTORS

No converting to JSON/SOAP

More natural programming

Concurrent on default

Built-in load balancer

Built-in circuit breaker

Page 64: The internet of (lego) trains

ADVANTAGES HTTP

Indepedent of technology

Loosely coupled

Page 65: The internet of (lego) trains

HTTP VS REMOTE ACTOR

Page 66: The internet of (lego) trains

FAT JAR (SBT ASSEMBLY) IN MB

0

5

10

15

20

25

Local actor Remote actor Akka HTTP Spring boot

Page 67: The internet of (lego) trains

0

20

40

60

80

100

120

50 50 no pause 500 500 no pause 1000 1000 no pause

Mean response time (ms)

Akka HTTP Remote actor

Page 68: The internet of (lego) trains

0

100

200

300

400

500

600

700

800

900

50 50 no pause 500 500 no pause 1000 1000 no pause

Max response time (ms)

Akka HTTP Remote actor

Page 69: The internet of (lego) trains

REST is dead, long live remote actors!

- Johan Janssen

Page 70: The internet of (lego) trains

0

5

10

15

20

25

30

50 50 no pause 500 500 no pause 1000 1000 no pause

Mean response time (ms)

Remote actor Spring boot

Page 71: The internet of (lego) trains

0

100

200

300

400

500

600

700

800

900

50 50 no pause 500 500 no pause 1000 1000 no pause

Max response time (ms)

Remote actor Spring boot

Page 72: The internet of (lego) trains
Page 73: The internet of (lego) trains
Page 74: The internet of (lego) trains
Page 75: The internet of (lego) trains
Page 76: The internet of (lego) trains
Page 77: The internet of (lego) trains

CONCLUSION

Page 78: The internet of (lego) trains

The best part!!

Page 79: The internet of (lego) trains

QUESTIONS?

Page 80: The internet of (lego) trains

Thank you!!

Johan Janssen, Info Support@johanjanssen42

[email protected]

Martin Kanters, Info Support

[email protected]