isobarot-client
v1.2.0
Published
Client library for sending data to isobarot cloud over HTTP or MQTT.
Downloads
11
Readme
isobarot-client
- Client library for sending data to isobarot cloud over HTTP or MQTT.
Getting Started
npm install --save isobarot-client
HttpClient Example
const { HttpClient } = require("isobarot-client");
const httpClient = new HttpClient(`app.isobarot.com`);
httpClient.send({
apiToken: "<api-token-here>",
createdAt: "2022-03-31T12:22:12.000Z",
record: {
// properties here
}
})
.then(response => console.log(response.data))
.catch(error => console.log(error.response.data));
MqttClient Example
const { MqttClient } = require("isobarot-client");
const mqttClient = new MqttClient(`app.isobarot.com`);
mqttClient.init()
// Connection to the MQTT Broker success
.then(() => {
// Send the data
mqttClient.send({
apiToken: "<api-token-here>",
createdAt: "2022-03-31T12:22:12.000Z",
record: {
// properties here
}
});
// Send the data with QoS and Retain options
mqttClient.send({
apiToken: "<api-token-here>",
createdAt: "2022-03-31T12:22:12.000Z",
record: {
// properties here
}
}, {
qos: 2,
retain: true
});
// Subscribe to topic
mqttClient.subscribe('some/topic', data => {
console.log(data);
});
})
// Connection to the MQTT Broker failed
.catch(error => {
console.log(error);
// Close connection
mqttClient.close();
});