FIWARE Building your own IoT Agent
Daniel Calvo
IoE Lab. ATOS Research & Innovation
daniel.calvo@atos.net
@danicalvoalonso
Building your own IoT Agent: overview
§ Frameworks: Node.js and C++
• https://github.com/Fiware/iot.IoTagent-node-lib
• https://github.com/telefonicaid/fiware-IoTAgent-Cplusplus
§ North bound features provided by the platform:
• NGSI Context Provision server
• NGSI Client
• Device Provisioning API
• Configuration API
§ All South bound features are protocol specific
• External library
• Ad-hoc development
1
Building your own IoT Agent: Node.js
§ Module provided in NPM Registry:
• Add iotagent-node-lib to your package.json
• Require it as any other module
§ https://github.com/telefonicaid/iotagent-node-lib/blob/master/doc/howto.md
§ Possible in few days/weeks:
• Current agents: ~ 1000 lines of source code (supporting several transport protocols)
2
Context Server
NGSI Client
Device
Protocol
Device
Registry
Group
Registry
Provision Server
IoT Agent
Building your own IoT Agent: CoAP + JSON
3
§ CoAP: Constrained Application Protocol
• RESTful protocol designed from scratch
• Transparent mapping to HTTP
• Binary protocol
□ Low parsing complexity
□ Small message size
• Security based on DTLS (TLS/SSL for Datagrams)
• IETF Standard: https://tools.ietf.org/search/rfc7252
GET /status/power
PUT /control/color #00FF00
Building your own IoT Agent: CoAP + JSON
4
APPLICATION
TRANSPORT
SIMPLIFIED OSI
NETWORK
LINK
PHYSICAL
CoAP
UDP
IoT Device
JSON
IoT Agent
UDP
IPv4
TCP
CoAP
JSON
HTTP
NGSI/REST
TCP
CONTEXT BROKER
IPv4
HTTP
NGSI /REST
§ Protocol translation
Building your own IoT Agent: CoAP + JSON
§ Active attributes reporting
• POST coap://{iot_agent_ip}/iot/coap
{
“deviceId": " #00FF00",
“apiKey": “123456",
“Luminosity”:”20”,
“ActivePower”:”0.42”
}
§ Southbound API: Rely on well-know libraries
• coap package: https://www.npmjs.com/package/coap
• coap-cli package: https://www.npmjs.com/package/coap-cli
5
Building your own IoT Agent: CoAP + JSON
1. Create a new node project
• npm init
2. Add iotagent-node-lib dependency
• npm install --save https://github.com/Fiware/iot.IoTagent-node-lib
3. Add your Southbound library
• npm install –save coap
4. Add some usefull packages:
• npm install –save async
• npm install –save logops
• npm install coap-cli -g
6
Building your own IoT Agent: CoAP + JSON
§ Start agent
7
Building your own IoT Agent: CoAP + JSON
§ Start south bound API:
8
Building your own IoT Agent: CoAP + JSON
§ Handle South Bound API requests:
9
Building your own IoT Agent: CoAP + JSON
§ Update attributes in IoT Agent and CB:
10
Building your own IoT Agent: CoAP + JSON
§ From JSON to NGSI:
11
Building your own IoT Agent: CoAP + JSON
§ Starting is quite easy and fast
§ IoT Agent supporting active attributes with CoAP and JSON data model
• 1 single file
• 147 lines of code
• Less than two hours of coding
• https://github.com/dcalvoalonso/iot.IoTagent-CoAP
• https://hub.docker.com/r/danielcalvo/iotagent-coap/
12
Thank you!
http://fiware.org
Follow @FIWARE on Twitter
Daniel Calvo
IoE Lab. ATOS Research &
Innovation
daniel.calvo@atos.net

FIWARE Global Summit - Building Your Own IoT Agent

  • 1.
    FIWARE Building yourown IoT Agent Daniel Calvo IoE Lab. ATOS Research & Innovation daniel.calvo@atos.net @danicalvoalonso
  • 2.
    Building your ownIoT Agent: overview § Frameworks: Node.js and C++ • https://github.com/Fiware/iot.IoTagent-node-lib • https://github.com/telefonicaid/fiware-IoTAgent-Cplusplus § North bound features provided by the platform: • NGSI Context Provision server • NGSI Client • Device Provisioning API • Configuration API § All South bound features are protocol specific • External library • Ad-hoc development 1
  • 3.
    Building your ownIoT Agent: Node.js § Module provided in NPM Registry: • Add iotagent-node-lib to your package.json • Require it as any other module § https://github.com/telefonicaid/iotagent-node-lib/blob/master/doc/howto.md § Possible in few days/weeks: • Current agents: ~ 1000 lines of source code (supporting several transport protocols) 2 Context Server NGSI Client Device Protocol Device Registry Group Registry Provision Server IoT Agent
  • 4.
    Building your ownIoT Agent: CoAP + JSON 3 § CoAP: Constrained Application Protocol • RESTful protocol designed from scratch • Transparent mapping to HTTP • Binary protocol □ Low parsing complexity □ Small message size • Security based on DTLS (TLS/SSL for Datagrams) • IETF Standard: https://tools.ietf.org/search/rfc7252 GET /status/power PUT /control/color #00FF00
  • 5.
    Building your ownIoT Agent: CoAP + JSON 4 APPLICATION TRANSPORT SIMPLIFIED OSI NETWORK LINK PHYSICAL CoAP UDP IoT Device JSON IoT Agent UDP IPv4 TCP CoAP JSON HTTP NGSI/REST TCP CONTEXT BROKER IPv4 HTTP NGSI /REST § Protocol translation
  • 6.
    Building your ownIoT Agent: CoAP + JSON § Active attributes reporting • POST coap://{iot_agent_ip}/iot/coap { “deviceId": " #00FF00", “apiKey": “123456", “Luminosity”:”20”, “ActivePower”:”0.42” } § Southbound API: Rely on well-know libraries • coap package: https://www.npmjs.com/package/coap • coap-cli package: https://www.npmjs.com/package/coap-cli 5
  • 7.
    Building your ownIoT Agent: CoAP + JSON 1. Create a new node project • npm init 2. Add iotagent-node-lib dependency • npm install --save https://github.com/Fiware/iot.IoTagent-node-lib 3. Add your Southbound library • npm install –save coap 4. Add some usefull packages: • npm install –save async • npm install –save logops • npm install coap-cli -g 6
  • 8.
    Building your ownIoT Agent: CoAP + JSON § Start agent 7
  • 9.
    Building your ownIoT Agent: CoAP + JSON § Start south bound API: 8
  • 10.
    Building your ownIoT Agent: CoAP + JSON § Handle South Bound API requests: 9
  • 11.
    Building your ownIoT Agent: CoAP + JSON § Update attributes in IoT Agent and CB: 10
  • 12.
    Building your ownIoT Agent: CoAP + JSON § From JSON to NGSI: 11
  • 13.
    Building your ownIoT Agent: CoAP + JSON § Starting is quite easy and fast § IoT Agent supporting active attributes with CoAP and JSON data model • 1 single file • 147 lines of code • Less than two hours of coding • https://github.com/dcalvoalonso/iot.IoTagent-CoAP • https://hub.docker.com/r/danielcalvo/iotagent-coap/ 12
  • 14.
    Thank you! http://fiware.org Follow @FIWAREon Twitter Daniel Calvo IoE Lab. ATOS Research & Innovation daniel.calvo@atos.net