I would like to send sensor data via the HTTPSClient to Fieldbook, which makes it super convenient to have a cloud based data-storage with REST-API.
The following node.js-Script does what I need. I wonder how to run the POST-part on a Particle / Core.
/ *
* Dependencies: Requestify
*/
var requestify = require('requestify');
var bookId = process.env.FIELDBOOK_BOOK_ID;
var baseUrl = 'https://api.fieldbook.com/v1/' + bookId;
var options = {
headers: {accept: 'application/json'},
auth: {
username: process.env.FIELDBOOK_USER,
password: process.env.FIELDBOOK_KEY
}
};
var url = baseUrl + '/activitydata';
var curTimestamp = new Date().toString();
// NOTE: Fieldbook uses only lower case variable names!!
var record = {
// Set attributes for new record here
sensorname: "distanceSensor1",
state: "false",
timestamp: "1234"
};
// GET
var response = requestify.get(url, options)
.catch(function (err) {
console.log(err);
})
.then(function(response) {
var resp = response.getBody(); // Get the response body (JSON parsed)
console.log(resp);
});
// POST
var response = requestify.post(url, record, options)
.catch(function (err) {
console.log(err);
})
.then(function(response) {
var resp = response.getBody(); // Get the response body (JSON parsed)
console.log(resp);
});
As the HTTPSClient for Particle does not have an options parameter I wonder how to use it to post to Fieldbook.
Some hints or a minimal working example would be highly appreciated!
Btw. it does not matter to me weather or not the data is published to the Particle Cloud via publish()
and then sent to Fieldbook via a webhook or sent directly with HTTPSClient (probably faster).