0.1.0 • Published 6 years ago
bigiot v0.1.0
BIGIoT
This is a BIGIot-Implementation for node.js
learn more about big-iot: http://big-iot.eu/
market: https://market.big-iot.org/
Installation
npm install bigiot
or
yarn add bigiot
Usage
Provider Perspective
const bigiot = require('bigiot');
// Create a new provider instance with your credentials
myProvider = new bigiot.provider(providerId, providerSecret);
// Authenticate your provider
myProvider.authenticate().then(() => {
// authentication is done
});
// Let's create a new offering
myOffering = new bigiot.offering('exampleOffering', 'urn:big-iot:EnvironmentalIndicatorCategory');
myOffering.addOutputData('someRandomNumbers', 'proposed:random');
myOffering.setEndpoint('http://example.org');
// Register your offering with the BIGIoT Marketplace
myProvider.register(myOffering).then(() => {
// registration is done
});
// Check if a http-request-header is permitted to access your resource
myProvider.validateRequestHeader(header).then((res) => {
// res is the decoded token
});
// alternatively you can check an access-token by hand
myProvider.validateConsumerToken(token).then((res) => {
// res is the decoded token
});
Consumer Perspective
Please beware, consumer perspective is a big todo!
const bigiot = require('bigiot');
// Create a new consumer instance with your credentials
myConsumer = new bigiot.consumer(consumerId, consumerSecret);
// Authenticate your consumer
myConsumer.authenticate().then(() => {
// authentication is done
});
// Now to create a new offeringQuery
myOfferingQuery = new bigiot.offeringQuery('exampleQuery', 'urn:big-iot:EnvironmentalIndicatorCategory');
myOfferingQuery.addInputData('testInput', 'proposed:testCategory');
myOfferingQuery.addOutputData('testOutput', 'proposed:testCategory');
// and register the query
myConsumer.register(myOfferingQuery).then(() => {
registration is done
});
now let's subscribe to an offering and get some data:
myParameters = new bigiot.accessParameter();
// the name and the value have to match those of the query / the provider
myParameters.addInputData(name, value);
myConsumer.subscribeToId(QueryId, OfferingId).then((data) => {
myConsumer.consumeQuery(data, myParameters).then((res) => {
// res is your response data
});
});