daas-sdk
Version:
nodejs wrapper for the DaaS-IoT SDK
93 lines (62 loc) • 2.15 kB
Markdown
**daas-sdk** • [**Docs**](globals.md)
***
# Daas sdk for nodejs
Daas-sdk a Framework for implementing Internet of Things (IoT) solutions that guarantees a significant reduction in design and development times.
This is the official SDK for the [DaaS](https://www.daasiot.com/) API for Node.js. It provides a convenient wrapper around the native API.
## Installation
```bash
npm install daas-sdk
```
### Documentation
You can generate the html documentation using the following command: `npm run doc`, or in markdown format using `npm run doc-md`.
## Example
In the following example we have 2 nodes, one is a server and the other one a client.
The client will send a message to the server at a regular interval.
```javascript
// server.js
const { DaasIoT, } = require("daas-sdk");
const INET4 = 2;
const SID = 100;
const DIN = 101;
const URL = '0.0.0.0:2101'
const REMOTE_DIN = 102;
const REMOTE_URL = '127.0.0.1:2102';
const hver = "nodeJS";
const daasApi = new DaasIoT(hver);
console.log(daasApi.getVersion());
daasApi.doInit(SID, DIN);
daasApi.onDinConnected((din) => { console.log("DIN Accepted: " + din); });
daasApi.onDDOReceived((din) => {
console.log("DDO received for DIN: " + din);
daasApi.locate(din);
daasApi.pull(din, (origin, timestamp, typeset, data) => {
console.log(`⬇ Pulling data from DIN: ${origin} timestamp: ${timestamp} - typeset: ${typeset} - data: `);
console.log(data);
});
});
drivers = daasApi.listAvailableDrivers();
for (const element of drivers) {
console.log(element);
}
if (daasApi.enableDriver(INET4, URL)) {
console.log("Driver enabled!");
}
if (daasApi.map(REMOTE_DIN)) {
console.log("Remote Node Mapped");
}
// if (daasApi.map(REMOTE_DIN, INET4, REMOTE_URL)) {
// console.log("Remote Node Mapped");
// }
if (daasApi.doPerform()) {
console.log("Node performed!");
}
/*
setInterval(() => {
if(daasApi.locate(REMOTE_DIN)){
console.log("Node Located...");
if(daasApi.push(REMOTE_DIN, 10, 1234567890, "Ciao Mondo!!!"))
console.log(`⬆ Pushing data to ${REMOTE_DIN} done.`);
}
}, 5000)
*/
```