2
0

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.

obnizに駅すぱあとの駅コードを表示する

Last updated at Posted at 2018-09-22

Node.js内でWeb APIに接続する勉強も兼ねて。
obnizの画面上に「駅すぱあと」で定義した駅コードを表示させます。

(22671はJR高円寺駅の駅コードです)
IMG_0849.JPG

obnizのセットアップ方法はこちら
Node.jsの起動方法はこちら
駅すぱあとWebサービスのアクセスキーの取得はこちら。ですがすぐに発行されないので、こちらの入門書(0円書籍)にサンプル用のキーを用意しているので、そちらを使うのが速いです(笑)

var Obniz = require("obniz");
var rp = require('request-promise');

var obnizeId = "YOUR-OBNIZ-ID";
var ekispertKey = 'YOUR-EKISPERT-ACCESS-KEY';

var stationCode = '';
var obniz = new Obniz(obnizeId);

obniz.onconnect = async function () {

  var options = {
    uri: 'https://api.ekispert.jp/v1/json/station',
    qs: {
      key: ekispertKey,
      name: '高円寺'
    },
    json: true
  };

  var ekispertReq = await rp(options)
  .then(function (body) {
    var points = body.ResultSet.Point;
    if(points) {
      if(points[0]) {
        stationCode = points[0].Station.code;
      } else {
        stationCode = points.Station.code;
      }
    } else {
      console.log('station is null');
    }
  })
  .catch(function (err) {
    console.log("error");
  });

  obniz.display.clear();
  obniz.display.print("Hello " + stationCode);
}

obnizとは?:
Node.jsで簡単にセンサ情報を扱えるツール。
https://obniz.io/

駅すぱあとWebサービスとは?:
みなさんご存知「駅すぱあと」の機能をWeb APIで提供したもの。
https://ekiworld.net/service/sier/webservice/index.html

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?