7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Node.js でECHONET Liteを送受信

Posted at

#はじめに
Node.jsを使ってECHONET Liteのデータを送受信するプログラムの作成

#UDP受信

UDPの受信のために、dgramのモジュールをインストールする

$ npm install dgram

以下サンプルコード

receive.js
var dgram = require('dgram');

//ECHONET Liteのポート
port = 3610

//コールバック関数を設定する
sock = dgram.createSocket("udp4", function (msg, rinfo) {
    console.log(rinfo["address"]); //ipアドレスのみを表示
    console.log(msg);
});

sock.bind(port, '0.0.0.0');

マルチキャストに対応したサンプルコード

mult_receive.js
var dgram = require('dgram');

port = 3610

sock = dgram.createSocket("udp4", function (msg, rinfo) {
    console.log(rinfo["address"]);
    console.log(msg);
});

sock.bind(port, '0.0.0.0',function(){
    sock.setMulticastLoopback( true );
    sock.addMembership("224.0.23.0");
});

#UDP送信
ECHONET Liteの送信は echonet-lite モジュールが使いやすい

$ npm install echonet-lite

機器の探索のためのサンプルコード
受信しながら以下を実行すると、同一lan上のECHOENT Lite機器が返答する。

search.js
// モジュールの機能をELとして使う
var EL = require('echonet-lite');

EL.search();

#参考
echonet-lite モジュール

node.jsでUDPサーバーを作る1

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?