So-net無料ブログ作成

EdisonでIoT Analyticsを使ってみる [edison]

前回,Intel XDK IoT Editionで温湿度センサAM2321を使ってみた.
今回は,その温湿度センサの値をIoT Analyticsへ飛ばしてみる.

IoT Analyticsがどんなものであるかとか,必要な設定は下記サイトが詳しい.
21: Intel Edison実践編 (1) 〜 センサーデータを受け取るSaaS「IoT Analytics」
22: Intel Edison実践編 (2) 〜 EdisonからIoT Analyticsにデータを送る
23: Intel Edison実践編 (3) 〜 XDKで開発したプログラムからiotkit-agentにデータを送る

というわけで,上記サイトを参考に,ほぼそのままやってみる.ただ,今回は温度と湿度をIoT Analyticsに送りたいので,以下のようにコマンドを入力してやる.
iotkit-admin register temperature temperature.v1.0
iotkit-admin register humidity humidity.v1.0


あとはコードだが,前回同様,適当なProjectを作って,package.jsonとmain.jsを以下のようにしてやる.

まず,package.json
{
  "name": "iot_analytics_test",
  "description": "",
  "version": "0.0.0",
  "main": "main.js",
  "engines": {
    "node": ">=0.10.0"
  },
  "dependencies": {
      "sleep": "*"
  }
}

次に,main.js
var dgram = require('dgram');
var client = dgram.createSocket('udp4');
var udpOptions = {
    host : '127.0.0.1',
    port : 41234
};
 
function sendObservation(name, value, on){
    var msg = JSON.stringify({
        n: name,
        v: value,
        on: on
    });
 
    var sentMsg = new Buffer(msg);
    console.log("Sending observation: " + sentMsg);
    client.send(sentMsg, 0, sentMsg.length, udpOptions.port, udpOptions.host);
}

var mraa = require('mraa');
console.log('MRAA Version: ' + mraa.getVersion());

var sleep = require('sleep');

function crc16(buf, length)
{
    var crc = 0xFFFF;
    for (var j = 0; j < length; j++) {
        crc ^= buf[j];
        for (var i = 0; i < 8; i++) {
            if (crc & 0x01) {
                crc >>= 1;
                crc ^= 0xA001;
            }
            else {
                crc >>= 1;
            }
        }
    }
    return crc;
}

function Am2321(bus, address, bufsize) {
    this.x = new mraa.I2c(bus);
    this.x.address(address);
    this.buff = new Buffer(bufsize);
    
    this.wakeupSensor = function() {
        this.x.writeReg(0, 0);
    }
    
    this.sendCommand = function() {
        get_command = new Buffer([0x03, 0x00, 0x04]);
        this.x.write(get_command);
        sleep.usleep(1500);
    }
    
    this.receiveData = function() {
        this.buff = this.x.read(8);
    }
    
    this.checkCrc = function() {
        var crc = this.buff[6] + this.buff[7] * 256;
        return crc == crc16(this.buff, 6);
    }
    
    this.checkRecieveData = function() {
        return (this.buff[0] == 0x03) && (this.buff[1] == 0x04);
    }

    this.getHumidity = function() {
        var high = this.buff[2];
        var low  = this.buff[3];
        return (high * 256 + low) / 10;
    }

    this.getTemperature = function() {
        var temperature = 0;
        var high = this.buff[4];
        var low  = this.buff[5];

        if (high & 0x80) {
            temperature = -1 * (high & 0x7F) * 256 + low;
        }
        else {
            temperature = high * 256 + low;
        }
        return temperature / 10;
    }
}

var sensor = new Am2321(6, 0x5C, 8);
periodicActivity();

function periodicActivity()
{
    sensor.wakeupSensor();
    sensor.sendCommand();
    sensor.receiveData(); 

    if (sensor.checkCrc() == true) {
        if (sensor.checkRecieveData() == true) {
            var humidity = sensor.getHumidity();
            var temperature = sensor.getTemperature();
            console.log("%d %%, %d C", humidity, temperature);
            
            var date = new Date();
            sendObservation('humidity',    humidity,    date.getTime());
            sendObservation('temperature', temperature, date.getTime());
        }
    }

    setTimeout(periodicActivity,10000);
}


これをビルドして実行すると,IoT Analyticsに10秒おきに温度と湿度を送信するようになる.

で,しばらく動かしてみたときの結果は,こんな感じ.
IoT Analytics Graph.png
送信したデータをグラフにしてくれる.あと,csvのエクスポートも可能だ.

非常にお手軽に温湿度を送ることができる.
お試しあれ.

nice!(0)  コメント(65)  トラックバック(0) 
共通テーマ:日記・雑感

nice! 0

コメント 65

CrbnuttefsGF

credit debt management - http://personalnerloan.org/ biggest cash payday loans <a href=http://personalnerloan.org/>personal loan bad credit</a> ’
by CrbnuttefsGF (2017-09-21 00:42) 

BvbnfloanoNT

americash payday loan
<a href="http://paydayhhkl.org/">loans payday</a>
loans unemployed
<a href=http://paydayhhkl.org/>payday loans bad credit</a> ’
by BvbnfloanoNT (2017-09-22 01:08) 

HhhjJidilsXR

can military get payday loans
<a href="http://personalacrb.org/">easy personal loans</a>
bad credit consolidation loans
<a href=http://personalacrb.org/>personal loans online</a> ’
by HhhjJidilsXR (2017-09-22 01:08) 

お名前(必須)

payday loans cash advances
<a href="http://paydaydvtb.com/">loans payday</a>
emergency loan
<a href=http://paydaydvtb.com/>payday loans online</a> ’
by お名前(必須) (2017-09-22 06:26) 

お名前(必須)

buy cheap cialis
<a href="http://cialisofkl.com/">cialis generic</a>
buy cialis 10mg
<a href=http://cialisofkl.com/>buy cialis</a> ’
by お名前(必須) (2017-09-23 08:36) 

お名前(必須)

best cialis price
<a href="http://cialisovnas.com/">buy cialis</a>
10mg cialis
<a href=http://cialisovnas.com/>cialis online</a> ’
by お名前(必須) (2017-09-23 18:05) 

お名前(必須)

lowest price cialis
<a href="http://retcialis.com/">buy cialis</a>
cialis professional vs cialis
<a href="http://retcialis.com/">cialis online</a> ’
by お名前(必須) (2017-09-24 17:12) 

FfvgUsepleIM

cialis.com free offer
<a href="http://veucialis.com/">buy cialis</a>
cialis every day pill
<a href=http://veucialis.com/>cialis online</a> ’
by FfvgUsepleIM (2017-09-24 17:15) 

VqvqKeyncEA

price of cialis in canada
<a href="http://gawcialis.com/">cialis online</a>
cialis dosage instructions
<a href=http://gawcialis.com/>generic cialis</a> ’
by VqvqKeyncEA (2017-09-24 17:15) 

お名前(必須)

cialis cost australia
<a href="http://cialiseimah.com/">cialis</a>
cialis for sale nyc
<a href=http://cialiseimah.com/>cialis</a>
by お名前(必須) (2017-09-25 19:59) 

お名前(必須)

cheap cialis australia
<a href="http://cialisoakdm.com/">generic cialis</a>
cialis dosing
<a href=http://cialisoakdm.com/>cheap cialis</a> ’
by お名前(必須) (2017-09-25 20:25) 

お名前(必須)

generic cialis australia
<a href="http://cialisjrncd.com/">cialis online</a>
cialis tadalafil side effects
<a href=http://cialisjrncd.com/>cialis</a>
by お名前(必須) (2017-09-25 20:25) 

お名前(必須)

cheap cialis professional
<a href="http://cialiseiand.com/">generic cialis</a>
cialis professional canada fda
<a href=http://cialiseiand.com/>cheap cialis</a> ’
by お名前(必須) (2017-09-26 04:10) 

KrtpbarcomDE

overnight cialis delivery - http://haycialis.com/
generic soft tabs cialis <a href=http://haycialis.com/>buy cialis</a> ’
by KrtpbarcomDE (2017-09-26 22:05) 

VtnoFeeRSY

is generic cialis from india safe - https://jrucialis.com
cialis free sample <a href=https://jrucialis.com>cheap cialis</a> ’
by VtnoFeeRSY (2017-09-26 22:05) 

お名前(必須)

generic cialis capsules - http://cialisivndh.com/
does female cialis work for women <a href=http://cialisivndh.com/>generic cialis</a> ’
by お名前(必須) (2017-09-27 00:23) 

お名前(必須)

cialis.com free offer - https://cialisonlin.com
cialis samples free <a href=https://cialisonlin.com>buy cialis</a> ’
by お名前(必須) (2017-09-27 07:49) 

お名前(必須)

generic cialis tadalafil - http://cialiskanr.com
generic cialis soft tabs <a href=http://cialiskanr.com>cheap cialis</a> ’
by お名前(必須) (2017-09-27 07:59) 

お名前(必須)

cialis dosage daily
<a href="http://cialiseimah.com/">cialis online</a>
cialis 5 mg daily
<a href=http://cialiseimah.com/>buy cialis</a> ’
by お名前(必須) (2017-09-27 15:17) 

お名前(必須)

loan store
<a href="https://cashrvyn.com/">payday advance</a>
payday loans no credit check online
<a href="https://cashrvyn.com/">payday advance</a> ’
by お名前(必須) (2017-09-28 22:12) 

お名前(必須)

online check advance
<a href="https://paydayrvjlo.com/">payday loan online</a>
fresno
<a href=https://paydayrvjlo.com/>payday loans online</a> ’
by お名前(必須) (2017-09-28 22:12) 

LmazJidilsOU

loans people bad credit
<a href="https://paydayrvyaf.com/">pay day loan</a>
small business loans
<a href=https://paydayrvyaf.com/>payday loans online</a> ’
by LmazJidilsOU (2017-09-29 00:30) 

お名前(必須)

cash advance loans
<a href="https://loansbtxsa.org/">payday loans</a>
personal loans for bad credit
<a href=https://loansbtxsa.org/>loans online</a> ’
by お名前(必須) (2017-09-29 00:59) 

お名前(必須)

payday loan installment
<a href="https://personalvrdcg.org/">personal loan bad credit</a>
payday cash advance
<a href=https://personalvrdcg.org/>personal loan online</a> ’
by お名前(必須) (2017-09-29 06:14) 

お名前(必須)

title loans texas
<a href="https://paydaytbukl.org/">payday advance loans</a>
online cash loans
<a href=https://paydaytbukl.org/>cash advance</a> ’
by お名前(必須) (2017-09-29 07:57) 

PamefloanoYJ

personal loan debt consolidation
<a href="https://installmentsvfacr.com/">bad credit installment loans</a>
2nd payday loan
<a href=https://installmentsvfacr.com/>get installment loan</a> ’
by PamefloanoYJ (2017-09-29 08:00) 

お名前(必須)

online payday loan
<a href="https://paydayvynk.org/">payday loan</a>
payday loans online
<a href=https://paydayvynk.org/>pay day loans</a> ’
by お名前(必須) (2017-09-29 13:39) 

お名前(必須)

quick cash loan
<a href="https://paydaykmae.com">cash advance loans</a>
1 hr payday loans
<a href="https://paydaykmae.com">cash advance america</a> ’
by お名前(必須) (2017-09-30 18:15) 

お名前(必須)

1 hour payday loans no credit check
<a href="https://loansonlinevaec.org">same day payday loan</a>
bad credit loans online
<a href=https://loansonlinevaec.org>same day payday loan</a> ’
by お名前(必須) (2017-09-30 18:15) 

FvrcJidilsHZ

credit loan application
<a href="https://cashadvanceamericasev.org">cash advance on credit card</a>
online loans no credit check instant approval
<a href=https://cashadvanceamericasev.org>online payday loans</a> ’
by FvrcJidilsHZ (2017-09-30 20:38) 

お名前(必須)

bad credit loans
<a href="https://leopaydayadvanceonlinefastpayday.org">pay day loan</a>
fast loans with bad credit
<a href=https://leopaydayadvanceonlinefastpayday.org>payday loans</a> ’
by お名前(必須) (2017-10-01 09:46) 

お名前(必須)

personal loans
<a href="https://cashadvanceamericavatn.org">cash advance usa</a>
personal loans poor credit
<a href=https://cashadvanceamericavatn.org>cash advance loan</a> ’
by お名前(必須) (2017-10-01 21:18) 

お名前(必須)

cialis prices - http://cialisovnas.com/
cialis tadalafil india <a href=http://cialisovnas.com/>online cialis</a> ’
by お名前(必須) (2017-10-03 09:22) 

お名前(必須)

personal loan rates
<a href="https://paydayllae.com/">best online payday loans</a>
payday loan no fax document
<a href=https://paydayllae.com/>payday loans online</a> ’
by お名前(必須) (2017-10-03 21:13) 

JtnbJidilsRF

cash advance online
<a href="https://paydayloamec.com/">cash advance</a>
online loans no credit check
<a href=https://paydayloamec.com/>loans online</a> ’
by JtnbJidilsRF (2017-10-03 23:29) 

お名前(必須)

instant payday loans
<a href="https://cashnowemr.com">cash advance online</a>
bad credit faxless payday loans
<a href=https://cashnowemr.com>payday loans online</a> ’
by お名前(必須) (2017-10-04 00:18) 

お名前(必須)

bad credit loans online
<a href="https://cashadmme.com/">payday loans bad credit</a>
opening bank account
<a href=https://cashadmme.com/>loans payday</a> ’
by お名前(必須) (2017-10-04 07:18) 

お名前(必須)

100 payday loan - https://paydayllae.com/
apple payday loan <a href=https://paydayllae.com/>online payday loans direct lenders</a> ’
by お名前(必須) (2017-10-05 05:04) 

FnrxmoiptAR

get loan bad credit - https://paydayloamec.com/
paydayloans chicago <a href=https://paydayloamec.com/>payday loans online</a> ’
by FnrxmoiptAR (2017-10-05 07:25) 

お名前(必須)

500 fast cash payday loan - https://cashnowemr.com
all payday loan companies <a href=https://cashnowemr.com>best payday loans</a> ’
by お名前(必須) (2017-10-05 07:56) 

お名前(必須)

$1500 payday loans - https://cashadmme.com/
same day payday loan <a href=https://cashadmme.com/>instant payday loans</a> ’
by お名前(必須) (2017-10-05 14:49) 

FnveemoiptJU

online payday loan companies - https://paydaybdrfs.com/
fast cash loans <a href=https://paydaybdrfs.com/>loans online</a> ’
by FnveemoiptJU (2017-10-06 23:19) 

お名前(必須)

personal loans for people with bad credit - https://cashcevth.com
payday loans austin texas <a href=https://cashcevth.com>get payday loan</a> ’
by お名前(必須) (2017-10-06 23:50) 

お名前(必須)

usa payday advance - https://paydayloansrvhj.com/
low cost payday loans <a href=https://paydayloansrvhj.com/>same day payday loans</a> ’
by お名前(必須) (2017-10-07 06:50) 

VtvzvdFeeRVW

cialis soft tabs online pharmacy - https://genonlinecialis.com
cialis india pharmacy <a href=https://genonlinecialis.com>generic cialis</a> ’
by VtvzvdFeeRVW (2017-10-07 07:05) 

JtnvbJidilsIY

online payday loan companies
<a href="https://paydaybdrfs.com/">pay day loans</a>
500 cash payday loan
<a href=https://paydaybdrfs.com/>cash advance online</a> ’
by JtnvbJidilsIY (2017-10-08 06:57) 

お名前(必須)

are online payday loans
<a href="https://cashcevth.com">cash advance</a>
get installment loan
<a href=https://cashcevth.com>payday loans</a> ’
by お名前(必須) (2017-10-08 07:28) 

お名前(必須)

brand cialis over the net
<a href="https://genericgenericcialis.com/">online cialis</a>
soft tabs cialis
<a href=https://genericgenericcialis.com/>generic cialis</a> ’
by お名前(必須) (2017-10-09 07:51) 

お名前(必須)

3 month payday loans uk
<a href="https://cashecbya.com/">payday loans online</a>
small payday loans online
<a href=https://cashecbya.com/>payday loans online</a> ’
by お名前(必須) (2017-10-09 10:00) 

お名前(必須)

brand name cialis - http://buycialis-menedpil.com/
cialis 20mg tablets <a href="http://buycialis-menedpil.com/">cheap cialis</a> ’
by お名前(必須) (2017-10-11 02:15) 

お名前(必須)

generic cialis overnight - http://onlinecialis-cialisvip.com
brand cialis name online order <a href=http://onlinecialis-cialisvip.com>buy cialis cheap</a> ’
by お名前(必須) (2017-10-11 05:46) 

お名前(必須)

cialis 10mg tablets - http://cialisonline-pricepil.com/
cialis mail order <a href=http://cialisonline-pricepil.com/>cialis online</a> ’
by お名前(必須) (2017-10-11 11:34) 

AqrhdAccurlDI

cialis shipped to canada - http://genericcialis-viaed.com/
price for cialis <a href=http://genericcialis-viaed.com/>cialis</a>
by AqrhdAccurlDI (2017-10-11 12:55) 

お名前(必須)

cialis once a day pill - http://cialisonline-vipmej.com/
cialis 40 mg <a href=http://cialisonline-vipmej.com/>generic cialis</a> ’
by お名前(必須) (2017-10-12 04:35) 

お名前(必須)

cialis by mail
<a href="http://onlinecialis-cialisvip.com">cialis online</a>
overnight cialis delivery
<a href=http://onlinecialis-cialisvip.com>online cialis</a> ’
by お名前(必須) (2017-10-12 08:17) 

お名前(必須)

soft cialis tabs
<a href="http://cialisonline-vipmej.com/">order cialis online</a>
cialis doses
<a href=http://cialisonline-vipmej.com/>cialis online</a> ’
by お名前(必須) (2017-10-13 06:37) 

お名前(必須)

1 hour payday loans - https://paydayceinf.org/
personal installment loans poor credit <a href=https://paydayceinf.org/>payday loans online</a> ’
by お名前(必須) (2017-10-17 23:15) 

お名前(必須)

no fax payday loan today - https://paydayobns.com/
fast cash loan <a href="https://paydayobns.com/">online payday loan</a> ’
by お名前(必須) (2017-10-17 23:15) 

KmrcnmoiptDE

loans people bad credit - https://paydaycnrs.net/
bad credit loan <a href=https://paydaycnrs.net/>payday loan online</a> ’
by KmrcnmoiptDE (2017-10-18 03:16) 

SecvvelenueZO

short term loan - https://loansczne.com/
debt consolidation loan bad credit <a href=https://loansczne.com/>payday loans</a> ’
by SecvvelenueZO (2017-10-18 11:10) 

お名前(必須)

online instant payday loans - https://loans24rjn.com/
cash 1 payday loan <a href=https://loans24rjn.com/>payday loans online</a> ’
by お名前(必須) (2017-10-18 18:40) 

お名前(必須)

auto payday loan - https://loanenav.net/
bad credit loans no payday loans <a href=https://loanenav.net/>payday loans</a> ’
by お名前(必須) (2017-10-19 06:15) 

お名前(必須)

payday loans no credit check direct lender
<a href="https://loansnerc.org/">payday loans online</a>
small personal loans
<a href=https://loansnerc.org/>payday loans</a> ’
by お名前(必須) (2017-10-20 17:04) 

お名前(必須)

cialis.com - http://pillsme.com/
cialis online without prescription <a href="http://pillsme.com/">cialis</a>
by お名前(必須) (2017-10-20 23:10) 

お名前(必須)

cialis overdose - http://doverpharma.com/
cialis pills online <a href=http://doverpharma.com/>generic cialis</a> ’
by お名前(必須) (2017-10-21 07:28) 

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

トラックバック 0

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。