Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core,...
Transcript of Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core,...
![Page 1: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/1.jpg)
© 2016 InterSystems Corporation. All rights reserved.
Connecting IOT Devices Pierre-Yves Duquesnoy
![Page 2: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/2.jpg)
1 | © 2016 InterSystems Corporation. All Rights Reserved.
¿What are IOTs? • Devices connected to the Internet
• “Amazon Dash” button
• Heating systems
• Alarms
• Power plugs, Cameras, Sensors
• wearables
• Closed EcoSystems
Cannot interact with Caché/Ensemble
• Open Platforms/Protocols
• Json/rest
• MQTT
• Websockets
![Page 3: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/3.jpg)
2 | © 2016 InterSystems Corporation. All Rights Reserved.
• Micro controller
• Good platform to get started
• Rapid Prototyping (Uno)
• Cost effective
• Low energy needs
• Lack of processing power
(SSL ?)
• Analog and Digital I/O
• Many sensors, relays
• Internet “shield” as an
extension
• C language (!)
IOT Platforms: Micro controllers, the Arduino
![Page 4: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/4.jpg)
3 | © 2016 InterSystems Corporation. All Rights Reserved.
• Raspberry PI 3:
• Very powerful
• 4Core, 64Bits CPU
• Instalación OS (linux)
• Higher energy requirements
• Used with other smaller IOTs
• Eg: Alarm central
IOT Platforms: CPUs, Raspberry PI
![Page 5: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/5.jpg)
4 | © 2016 InterSystems Corporation. All Rights Reserved.
IOT Plataforms: other examples
ESP8266: Wifi Espruino: Javascript
![Page 6: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/6.jpg)
5 | © 2016 InterSystems Corporation. All Rights Reserved.
• Less powerful platforms
• Need a “shield” to connect to internet
• Power Supply issues
• Bluetooth, etc…
• Internet Connectivity
• Wifi / Cable Ethernet
• Firewall, connectivity
• Security
• SSL / TLS
• Intrusions
• Protocols
• Http, Rest, JSON
• websockets
• MQTT
• Propietarios
Interner Communication: challenges
![Page 7: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/7.jpg)
6 | © 2016 InterSystems Corporation. All Rights Reserved.
Connecting sensors to Caché
ESP8266, Wifi, REST and JSON
![Page 8: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/8.jpg)
7 | © 2016 InterSystems Corporation. All Rights Reserved.
Sending sensor data: Wifi, HTTP, JSON, REST
ESP8266
Caché
![Page 9: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/9.jpg)
8 | © 2016 InterSystems Corporation. All Rights Reserved.
Class PYD.IOT.RestServer Extends %CSP.REST
{
XData UrlMap { <Routes> <Route Url="/ESP8266/sensorData" Method="POST" Call="sensorData" /> </Routes>
ClassMethod sensorData() As %Status {
… //Procesar JSON del Request
//Grabar a Tabla o Global
} }
JSON and REST in Caché
![Page 10: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/10.jpg)
9 | © 2016 InterSystems Corporation. All Rights Reserved.
#include "ESP8266WiFi.h“
WiFiClient client;
String json = "{\"temperature\":\""+String(temperature)+"\"}";
WiFi.begin(ssid, password); //---Conectar a la Wifi
client.connect(host,port); //---Verificar Conexión a Servidor Caché
client.println(
"POST http://52.17.73.170:57772/csp/IOTRest/ESP8266/sensorData HTTP/1.1");
client.println("Host: 52.17.73.170:57772");
client.println("Content-Type: application/json");
client.print("Content-Length: " client.println(json.length());
client.println();
client.println(json);
JSON & REST on ESP8266
![Page 11: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/11.jpg)
10 | © 2016 InterSystems Corporation. All Rights Reserved.
Sending sensor data
![Page 12: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/12.jpg)
11 | © 2016 InterSystems Corporation. All Rights Reserved.
Connected vending machine
Arduino AT Mega + Ethernet Shield, MQTT, Mosquitto Broker, Ensemble
![Page 13: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/13.jpg)
12 | © 2016 InterSystems Corporation. All Rights Reserved.
Benefits
• Remote control
• Out of Stock products, price changes..
• Remote maintenance
• Temperatrue sensors, vibration sensors, etc.
• RFID Keys for payment
• Autentication, Server-side balance management (prevents key copies and theft)
• Purchasing data (Time and Date, consumer) for data mining
• Special offers
• happy hour, 3x2,
• Offer on products (like sandwiches) before they expire
Connected vending machine
![Page 14: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/14.jpg)
13 | © 2016 InterSystems Corporation. All Rights Reserved.
• Publish/Subscribe protocol
• On top of TCP/IP
• Light messaging
• Designed for communication for remote sites
• Tiny footprint for client library
• Limited bandwidth usage
• MQTT Brokers
• HiveMQ (propietary)
• Mosquitto (Open Source)
• Client Libraries
• Eclipse PAHO (java)
• C Library for Arduino
![Page 15: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/15.jpg)
14 | © 2016 InterSystems Corporation. All Rights Reserved.
Venduino, MQTT, Ensemble Ensemble
MQTT Broker
Mgmt Interface
![Page 16: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/16.jpg)
15 | © 2016 InterSystems Corporation. All Rights Reserved.
Publishes
• Venduino/Ens/CARD
• Asks Details for an RFID Card
• Venduino/Ens/BUY
• Notifies a purchase
• Venduino/Ens/STATUS -> “ONLINE”
Suscribes
• Venduino/Dev/A#
• Venduino/Dev/A/CARD
• Details for an RFID Card
• ID | CustomerName | Balance
• Venduino/Dev/A/PRICE
• Price change Notification
• Venduino/Dev/A/OFFER
• Offer Notification
MQTT Venduino Topics
![Page 17: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/17.jpg)
16 | © 2016 InterSystems Corporation. All Rights Reserved.
Publishes (Business Operation)
• Venduino/Dev/A/CARD
• Details reply for an RFID card
• Venduino/Dev/A/PRICE
• Price change notification
• Venduino/Dev/A/OFFER
• Special Offer notification
Suscribes (Business Service)
• Venduino/Ens/CARD
• Details request for an RFID Card
• Venduino/Ens/BUY
• Notification of a purchase
• Venduino/Ens/STATUS -> “ONLINE”
MQTT Ensemble Topics
Ensemble
![Page 18: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/18.jpg)
17 | © 2016 InterSystems Corporation. All Rights Reserved.
Venduino: MQTT messages
Ensemble
Venduino/Ens/CARD ID=XX-XX-XX-XX
Venduino/A/CARD Jordi | $30
Venduino/Ens/BUY CardID | TRAY 2
Venduino/A/OFFER $1
Venduino/A/PRICE $3
![Page 19: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/19.jpg)
18 | © 2016 InterSystems Corporation. All Rights Reserved.
• JavaInitiator: Allows to define Ensemble Components in Java (BS y BO)
• MqttSub: Business Service (Java) that subscribes to MQTT Topics
• MqttPub: Business Operation (Java) that sends messages to the MQTT Broker
• BPCard: Busines Process that processes messages from RFID Card
Ensemble Production
![Page 20: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/20.jpg)
19 | © 2016 InterSystems Corporation. All Rights Reserved.
Ensemble Messages: Venduino/Ens/CARD
![Page 21: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/21.jpg)
20 | © 2016 InterSystems Corporation. All Rights Reserved.
#include <PubSubClient.h>
PubSubClient client(ethClient);
//---Initialize
client.setServer(MqttServer, MqttServerPort);
client.connect(MQTTClientName);
//---Subscribe
void callback(char* topic, byte* payload, unsigned int length) { … }
client.setCallback(callback);
client.subscribe(topic);
//---Publish
client.publish(topic,content);
Arduino: MQTT Library
![Page 22: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/22.jpg)
21 | © 2016 InterSystems Corporation. All Rights Reserved.
Venduino: Casing and Idea by Ryan Bates:
http://www.retrobuiltgames.com/the-build-page/arduino-vending-machine/
Modified with:
- Arduino Uno replaced with AT MEGA 2560
- Ethernet Shield added
- RFID reader added
- RGB led added
Venduino Connected to Ensemble through MQTT
![Page 23: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/23.jpg)
22 | © 2016 InterSystems Corporation. All Rights Reserved.
Initialization
![Page 24: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/24.jpg)
23 | © 2016 InterSystems Corporation. All Rights Reserved.
RFID Card Data from Server
![Page 25: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/25.jpg)
24 | © 2016 InterSystems Corporation. All Rights Reserved.
Special Offer message
![Page 26: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/26.jpg)
25 | © 2016 InterSystems Corporation. All Rights Reserved.
Connect a light through websockets
Amazon Alexa, REST, Caché, WebSockets, ESP8266
![Page 27: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/27.jpg)
26 | © 2016 InterSystems Corporation. All Rights Reserved.
Connect a voice service to Caché
![Page 28: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/28.jpg)
27 | © 2016 InterSystems Corporation. All Rights Reserved.
Connect a voice service to Caché
Caché AWS Lambda
Skill “Intersystems”
Amazon Echo, Echo Dot, or Raspberry
REST & JSON Text reply Alexa
voice service
WebSockets
ESP8266
HTTPS +Rest&Json
![Page 29: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/29.jpg)
28 | © 2016 InterSystems Corporation. All Rights Reserved.
Class PYD.IOTDemo.WebSocketServer Extends %CSP.WebSocket {
Method Server() As %Status {
//---Read data if there is any. set len=32000, timeout=0.5 //500 ms timeout set data=..Read(.len,.tSC,.timeout)
if (ledStatusChanged=1) {
//---Send Status
set tSC=..Write(##class(PYD.IOTDemo.Data.LedStatus).getStatusAsString())
}
quit tSC
}
Caché WebSockets
![Page 30: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/30.jpg)
29 | © 2016 InterSystems Corporation. All Rights Reserved.
#include "ESP8266WiFi.h"
#include "WebSocketClient.h“
WiFiClient client;
WebSocketClient webSocketClient;
char* socketURL="/csp/IOTSocket/PYD.IOTDemo.WebSocketServer.cls";
//--- Connect to server and establish WebSocket
if (client.connect(host, port)) { ... }
webSocketClient.path = socketURL;
webSocketClient.host = host;
if (webSocketClient.handshake(client)) { ... }
/---Write & Read Data
webSocketClient.getData(data);
webSocketClient.sendData(json);
ESP8266 WebSockets
![Page 31: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/31.jpg)
30 | © 2016 InterSystems Corporation. All Rights Reserved.
• Alexa
• https://developer.amazon.com/
• Tutorials available…
• Alexa Skills Kit
• Invocation name “Intersystems”
• Utterances: <Text of the commands to recognize> + sinonims
• Intent Schema: <action to execute>
• Target: HTTPS o AWS Lambda
• AWS Lambda
• aws.amazon.com
• GitHub examples: amzn/alexa-skills-kit-js
Modified the javaScript server code to to add a REST call to Caché.
Amazon Alexa Skills & AWS Lambda
![Page 32: Connecting IOT Devices - InterSystems€¦ · • Raspberry PI 3: • Very powerful • 4Core, 64Bits CPU • Instalación OS (linux) • Higher energy requirements • Used with](https://reader034.fdocuments.us/reader034/viewer/2022042308/5ed5086c8bd58e246d47492e/html5/thumbnails/32.jpg)
31 | © 2016 InterSystems Corporation. All Rights Reserved.
Thank you!
Code, sketches, and further questions: [email protected]