Skip to content
This repository has been archived by the owner on Feb 28, 2020. It is now read-only.

This Node.js project helps to integrate SAP IoT Services (CF) APIs and to easily integrate apps to SAP Cloud IoT service.

License

Notifications You must be signed in to change notification settings

SAP-archive/iot-services-sdk-nodejs

Repository files navigation

Important Notice

We have decided to stop the maintenance of this public GitHub repository.

Node.JS library for SAP IoT Services

This library helps to call public APIs of SAP IoT Services and to easily integrate IoT apps working with Node.JS to SAP Cloud service.

Requirements

An instance of SAP IoT Services (Cloud Foundry) to use this SDK. Find more information about SAP IoT Service product here. To enable SAP IoT Service in your account follow this help page.

Download and Installation

To install Node.JS package for a project, $ npm install iot-services-sdk --save

To import Node.JS package in your project add following dependencies in your package.json,

"dependencies": {
   ...
   "iot-services-sdk": "^latest",
   ...
 },

Configuration

  • Rename .env.template to .env and change values respectively for IoT Tenant and Credentials.
  • For more information, see dotenv NPM configuration.

Services

Service Name Description Example Link
IoTDeviceService is for IoT Device Management API (All CRUD operations and device certificate management) Example
IoTMeasureService to read measurements (data-points) of a device Example
IoTGatewayService to connect and send measurements (data-points) for a device (Currently, only Cloud MQTT Gateway is supported) Example

Features

  • Create, List, Update of following SAP IoT Services elements
    • [Capability, SensorType, Sensor, Device, Gateway, Tenant]
  • List certificates for a device
  • Download a new certificate for a device
  • Revoke a certificate for a device
  • List all data-points (measurements) sent from a device
  • Push data-point (measurement) for a device using device certificate

Example

IoTAPIService Example

  • First include a serviceObject (e.g. IoTDeviceService) and a dataModelObject (e.g. IoT)
const iotService = new IoTDeviceService();
const iot = new IoT();
  • To list all objects of an element, (e.g. SensorTypes)
const tenantId = "Put tenant ID here";    // This is not required if tenant ID is specified in .env file

iotService.list(iot.tenant.sensorTypes, {tenantId: tenantId})
    .then(sensorTypes => {
        // work with array of sensorTypes objects
    })
    .catch(error => {
        // If API threw error
    });
  • To create an element, (e.g. Capability with single property)
const p1 = new Property({name: "tempProp1", dataType: "integer", unitOfMeasure: "c"});
const capability = new Capability({
    name: "testCapability1",
    alternateId: "testCapability1",
    properties: [p1]
});

return iotService.create(iot.tenant.capabilities, {tenantId: tenanId}, capability)
    .then(response => {
        // Capability Created
    })
    .catch(error => {
        // If API threw error
    });
  • To delete an element use iotService.delete()
  • To download device certificate
const deviceId = "device uuid";
// list PEM is actually generating a new certificate.
iotService.list(iot.tenant.devices.authClientCertificate.pem, {
      tenantId: tenantId,   // Can be ommited
      deviceId: deviceId    // Must specify
    })
    .then(clientCertPem => {
        return clientCertPem.saveJson(deviceId + ".json");
    })
    // chain .then .catch if you wish

IoTMeasureService Example

IoTMeasureService
    .listMeasures({deviceId: "0e4fe3e1-bf8b-44d7-8e6e-6f8184e9c06f"})
    .then(measures => {
        // Work with array of Measurement objects
    });

IoTGatewayService Example

const gateway = IoTGatewayService.gateway("MQTT", deviceAltId, clientCert);
gateway.connect()
    .then(gateway => {
        return gateway.send(MESSAGE);
    })
    .then(() => {
        // Work after sending message
    })
    .finally(() => {
        gateway.disconnect();
    })

TODO / Future Scopes

  • Allow custom observer when message gets acknowledged by MQTT broker
  • Create all required elements from YAML file.
  • Gateway Bundle Management APIs

How to obtain support

Please create issue at issues to get support or report bug.

License

Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved.
This project is licensed under the Apache Software License, v.2 except as noted otherwise in the LICENSE file.

About

This Node.js project helps to integrate SAP IoT Services (CF) APIs and to easily integrate apps to SAP Cloud IoT service.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published