modelling iot gateway – a canbus example€¦ · modelling iot gateway – a canbus example by...
TRANSCRIPT
Modelling IOT Gateway – A CANBus Example
By
Rajesh Sola Shubham Srivastava
Core Faculty Technical Trainer
CDAC’s Advanced Computing Training School,Pune
Outline
Significance of an IOT Gateway
CAN Bus Example, Enabling Technologies
CAN Slave Design - platformio IDE, mbed APIs
CAN Master - BeagleBoneBlack , SocketCAN
Gateway Design
Node.js socketcan module
Eclipse Kura canbus bundle
Cloud Connectivity
MQTT
HTTP REST
Introduction
Need for an IOT Gateway
Things in a typical IOT architecture – Layers
Layer 1 : End devices/Sensor nodes/Edge nodes
Layer 2 : Gateway nodes/Middleware solutions
Layer 3 : Servers/Cloud Platforms
Typical characteristics of a gateway
Technical Enablers for Gateway Design
Prototyping
NodeRED
Frameworks
Eclipse Kura based on OSGi Macchina.io based on OSP & POCO C++ Libraries Ubuntu Snappy Core IOTiviity OpenHAB based on Eclipse Smart Home
Language of choice!!
Expected Features!!
A Case Study – CANBus Example
ThingSpeak
CAN Slave Design
PlatformIO IDE
– Framework
– Toolchain
– Flash Utils
mbed APIs
– Peripheral Support
(ADC, GPIO, SPI, I2C etc)
– CANBus APIs
– Timers
– Interrupts
Target Board
– STM32 F4 Discovery Board
mbed APIs – Code Snippets Fixing target layer code in mbed-os
– Missing structures,enum definitions @ target layer
– Pinmap structure for CAN Tx and Rx
CAN Communication
– Loopback mode
– Normal Mode (explicit polling)
– Interrupt Mode
Common APIs
HAL
Manufacturer/Family
Manufacturer/Family
Board-1A Board-1B Board-2A Board-2B
CMSIS Layer
CAN Master Design
CAN Controller on AM335x
Linux SocketCAN Support
Socketcan API
Can-utils
– candump
– cansend
– cangen
Please refer wiki for the usage ofcan-utils and C examples using SocketCAN API
https://github.com/linux-can/can-utils
BeagleBoneBlack – DCAN Support
Kernel Support - can, can_dev, can_raw
Drivers - c_can, c_can_platform
Device Tree Support
dtc -O dtb -o BB-CAN1-00A0.dtbo -b 0 -@ BB-DCAN1-00A0.dts
cp BB-CAN1-00A0.dts /lib/firmware
echo BB-CAN1 > /sys/devices/bone_capemgr.*/slots (or)
bone_capemgr.enable_partno=BB-CAN1 #in uEnv.txt
BB-CAN1-00A0.dtb0 is available in most of debian distros
CAN interfaces are enabled by default in some of the recent debian distros, eg:- LXQT based debian v8.6
Configuring & Monitoring CAN Interfaces
ip link set can0 type can bitrate 250000
ip link set can0 type can bitrate 250000 triple-sampling on loopback off
ip link set can0 type can bitrate 250000 loopback on
ip link set can0 up
ifconfig can0
ip -d -s link show can0
cat /proc/net/can/stats
Ref:- http://processors.wiki.ti.com/index.php/AM335X_DCAN_Driver_Guide
Node.js Support
SocketCAN
MQTT - mqtt.js
HTTP REST
– Inbuilt http module
– External modules like “request”
Cloud specific modules
Node.js - SocketCAN
Initialization:-
var can = require('socketcan');
var channel;
channel=can.createRawChannel("can1", true);
channel.start();
Receiving frames:-
channel.addListener("onMessage", function(msg) {
console.log(msg);
//publish data to cloud platform
} );
Sending frames:-
var canmsg = {
id: m.id,
dlc: 4
data : new Buffer(dlc)
};
//fill canmsg.data
channel.send(canmsg);
NodeRED
Visual wiring tool for quick prototyping embedded,iot solutions
Zero or minimal java script coding
Runs on top of Node.js runtime
Rich set of addons , few examples are
Peripheral interfacing on target boards Arduino interfacing using Firmata Cloud connectivity (MQTT, HTTP REST,CoAP,WebSockets etc.) talking to database(mongodb,mysql,influxdb etc) social networking services (twitter,hangouts,twilio etc.)
Any node.js module can be wrapped into NodeRED addon with node.js
code for business logic and HTML code for front end
Can run in PaaS platform like IBM Bluemix or in a docker container
Referflows.nodered.orgFor more addons,
example flows
NodeRED – canbus,cloud connectivity
Addons
– node-red-contrib-canbus (github.com/rajeshsola/node-red-addons)
– node-red-contrib-sitewhere (github.com/sitewhere/sitewhere-node-red)
– node-red-contrib-coap
cansend node
– Takes msg object with id,payload as fields or node config values
– Generates random id, data in absence of msg properties or node configuration
candump node - outputs msg with id,dlc,payload fields
canconfig node – select channel, configure bitrate etc.
Some bridging scenerios
– combine output of candump with mqtt in or http-request(POST)
– combine output of mqtt out or http-request(GET) with cansend
– Combine CoAP observe output with cansend
– Using sitewhere nodes for forming mqtt payloads
NodeRED snapshot
Eclipse Kura
OSGi based framework
Supported Target boards
Rich APIs
Bundles
Services
Web console for configurtion
Kura Bundles
org.eclipse.kura.protocol.canbus
a service Bundle based on entropia socketcan library
libsocket-can-java-1.0.2.jar (de.entropia.can.*)
MQTT Support
– CloudService
– DataService
– MQTTDataTransport Bundles
HTTP REST
– RESTService
– Thingspeak REST example
Demo bundle
org.eclipse.kura.example.candemo
Integrating canbus services with DataService/RESTService
Kura in Action – Can Bundle
Conclusion
WishList
– Some more target boards,eg:-FRDM K64F
– Extended Frame testing
– Well designed Kura Bundles
– Enhancing NodeRED canbus nodes
– Custom IOT Platforms
• Sitewhere (under progress)
• Kaa IOT Platform (future plan)
Please follow https://rajeshsola.github.io/ for some of the detailed steps, additional references and links to some examples
AwaitingKura Wires!!