Pi Zero Easy IoT

安価で簡単に IoT を始めよう! - Raspberry Pi Zero によるプログラミングレス IoT 環境データ収集

ambient.js

Library for sending some data to Ambient, this module exports class Ambient.

Ambient class (extends Record class)

Usage example

let Ambient = require('file path to this ambient.js');

let ambient = new Ambient({
   channelId: param.ambientChannelId,
   writeKey: param.ambientWriteKey,
   readKey: param.ambientReadKey,
   userId: param.ambientUserId,
   batchQuantity: param.ambientBatchQuantity,
   format: (datas)=>datas.map((data)=>{
      return {
      	 created: new Date(data.timestamp).toFormat('YYYY-MM-DD HH24:MI:SS'),
	 d1: data.a,
	 d2: data.b,
   };})
});

ambient.write({a: 1, b: 2, timestamp: new Date.getTime()});

Constructor & Method

format function in constructor argument

Like above sample, argument of format function, datas is an array (this is internal stocks of which from write method argument), and format function return formated objects array.

   format: (datas)=>datas.map((data)=>{
      return {
      	 created: new Date(data.timestamp).toFormat('YYYY-MM-DD HH24:MI:SS'),
	 d1: data.a,
	 d2: data.b,
   };})