Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By...
Transcript of Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By...
![Page 1: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/1.jpg)
Modelling IOT Gateway – A CANBus Example
By
Rajesh Sola Shubham Srivastava
Core Faculty Technical Trainer
CDAC’s Advanced Computing Training School,Pune
![Page 2: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/2.jpg)
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
![Page 3: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/3.jpg)
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
![Page 4: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/4.jpg)
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!!
![Page 5: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/5.jpg)
A Case Study – CANBus Example
ThingSpeak
![Page 6: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/6.jpg)
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
![Page 7: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/7.jpg)
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
![Page 8: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/8.jpg)
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
![Page 9: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/9.jpg)
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
![Page 10: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/10.jpg)
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
![Page 11: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/11.jpg)
Node.js Support
SocketCAN
MQTT - mqtt.js
HTTP REST
– Inbuilt http module
– External modules like “request”
Cloud specific modules
![Page 12: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/12.jpg)
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);
![Page 13: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/13.jpg)
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
![Page 14: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/14.jpg)
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
![Page 15: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/15.jpg)
NodeRED snapshot
![Page 16: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/16.jpg)
Eclipse Kura
OSGi based framework
Supported Target boards
Rich APIs
Bundles
Services
Web console for configurtion
![Page 17: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/17.jpg)
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
![Page 18: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/18.jpg)
Kura in Action – Can Bundle
![Page 19: Modelling IOT Gateway – A CANBus Example€¦ · Modelling IOT Gateway – A CANBus Example By Rajesh Sola Shubham Srivastava Core Faculty Technical Trainer CDAC’s Advanced Computing](https://reader030.fdocuments.in/reader030/viewer/2022040407/5eae588275130821637f4dca/html5/thumbnails/19.jpg)
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!!