マイブーム@技術と生活

仕事や生活に関わる技術的なことを記述します。

Poke.io

参考:https://github.com/Armax/Pokemon-GO-node-api

ポケモンGO API node.js ライブラリ <開発中>

Discord に開発チャンネルがあります。開発でのみ使います。サポート問合せはしないでください。

example.js の例を確認してください。

 

インストール方法と使い方:

npm install pokemon-go-node-api
var Pokeio = require('pokemon-go-node-api')

 

マニュアル:

■ Pokeio.init(username, password, location, provider, callback)
ポケモントレーナークラブまたは Google アカウントで Pokeio を初期化する。地名または緯度・経度を指定できる。
username {String} ポケモントレーナークラブまたは Google アカウントのユーザー名
password {String} ポケモントレーナークラブまたは Google アカウントのパスワード
location {Object} 位置は、
  type = 'name' と name
  type = 'coords' と latitude、longitude、altitude
  の組合せで指定する
type {String} 'name' または 'coords'
name {String} Google マップ API を使い検索する地名
coords {Object}
  latitude {Number} 緯度
  longitude {Number} 経度
  altitude {Number} 標高
provider {String} 'ptc' または 'google'
callback {Function(error)}
  error {Error} エラー

■ Pokeio.GetAccessToken(username, password, callback)
Pokeio 内部変数に、接続チケットを保存する
username {String} ポケモントレーナークラブのユーザー名
password {String} ポケモントレーナークラブのパスワード
callback {Function(error, token)}
  error {Error} エラー
  token {String} チケット

■ Pokeio.GetApiEndpoint(callback)
Pokeio 内部変数に、API 終点を保存する
callback {Function(error, api_endpoint)}
error {Error} エラー
api_endpoint {String} API 終点

■ Pokeio.GetProfile(callback)
callback {Function(error, profile)}
error {Error} エラー
profile {Object} プロファイル
  creation_time {Number} 作成時間
  username {String} ユーザー名
  team {Number} チーム
  tutorial {Number/Boolean} 情報
    poke_storage {String} 所有できるポケモン
    item_storage {String} 所有できるアイテム数
    daily_bonus {Object} 毎日のボーナス
      NextCollectTimestampMs {Number} 次のアイテム入手更新時間(ms)
      NextDefenderBonusCollectTimestampMs {Number} 次の防衛ボーナス更新時間(ms)
    currency {Object} 所持金
      type {String} 種類
      amount {Number} 数量

■ Pokeio.GetLocation(callback)
Google マップ API を使い、現在の緯度・経度から、各国表記での住所を表示する
callback {Function(error, formattrd_address)}
error {Error} エラー
formatted_address {String} 各国表記での住所

■ Pokeio.GetLocationCoords()
Pokeio 内部変数に位置を保存する。緯度・経度または地名を指定できる
location {Object} 位置
  type {String} 'name' または 'coords'
  name {String} Google マップ API を使い検索する地名
  coords {Object}
    latitude {Number} 緯度
    longitude {Number} 経度
    altitude {Number} 標高
callback {Function(error, coordinates)}
error {Error} エラー
  coords {Object}
    latitude {Number} 緯度
    longitude {Number} 経度
    altitude {Number} 標高

 

プログラム例:

var a = new PokemonGO.Pokeio();
var location = {
 type: 'coords',
 coords: {
  'latitude': 35.712271,
  'longitude': 139.770557,
  'altitude': 0.0
 }
};

var username = 'abcde@gmail.com';
var password = 'xyz';
var provider = 'google';

a.init(username, password, location, provider, function(err) {
 if (err) throw err;

 console.log('1[i] Current location: ' + a.playerInfo.locationName);
 console.log('1[i] lat/long/alt: : ' + a.playerInfo.latitude + ' ' + a.playerInfo.longitude + ' ' + a.playerInfo.altitude);

 a.GetProfile(function(err, profile) {
  if (err) throw err;

  console.log('1[i] Username: ' + profile.username);
  console.log('1[i] Poke Storage: ' + profile.poke_storage);
  console.log('1[i] Item Storage: ' + profile.item_storage);

  var poke = 0;
  if (profile.currency[0].amount) {
   poke = profile.currency[0].amount;
  }

  console.log('1[i] Pokecoin: ' + poke);
  console.log('1[i] Stardust: ' + profile.currency[1].amount);

  setInterval(function(){
   a.Heartbeat(function(err,hb) {
   if(err) {
    console.log(err);
   }

   if(hb) {
    for (var i = hb.cells.length - 1; i >= 0; i--) {
     if(hb.cells[i].NearbyPokemon[0]) {
      var pokemon =  a.pokemonlist[parseInt(hb.cells[i].NearbyPokemon[0].PokedexNumber)-1];
      console.log('1[+] There is a ' + pokemon.name + ' near.');
     }
    }
   }
  });
  }, 5000);

 });
});

 

デモ:

node --debug-brk=28179 --nolazy example.js
Debugger listening on port 28179
[i] Logging with user: abcde@gmail.com
[i] Received Google access token!
[i] Received API Endpoint: https://pgorelease.nianticlabs.com/plfe/196/rpc
1[i] Current location: 2-1 Uenokōen, Taitō-ku, Tōkyō-to 110-0007, Japan
1[i] lat/long/alt: : 35.712271 139.770557 0
1[i] Username: abcde
1[i] Poke Storage: 250
1[i] Item Storage: 350
1[i] Pokecoin: 0
1[i] Stardust: 35247
[i] Logged in!
1[+] There is a Magikarp near.
1[+] There is a Psyduck near.
 

家で実験:

Github からプログラムコードを入手。[Clone or download]ボタンで Pokemon-GO-node-api-master.zip をダウンロード
cd C:\Git\Pokeio
npm install request
npm install geocoder
npm install protobufjs
npm install gpsoauthnode
npm install s2-geometry
npm install node-pogo-signature
npm install long

node example.js

 

日本語化:
pokemons.jsonポケモン名を日本語にしました。
https://1drv.ms/u/s!AtrmEyB9KEJijlh96gjw3mpSjoFX

 

プログラム例(ビュー):
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
  $.get(
    '/loc',
    function(data){
      $('#locationName').text(String(data));
    }
  );
  $.get(
    '/nearby',
    function(data){
      $('#nearbyPokemon').text(String(data));
    }
  );

  $('#set').click(function(){
    $.post(
      '/set',
      {latitude:$('#latitude').val(), longitude:$('#longitude').val()},
      function(data){
        $('#locationName').text(String(data));
        $('#nearbyPokemon').text('');
      }
    )
  });

  $('.map').click(function(){
    var id = $(this).attr('id');
    var data = id.split(',');
    $('#latitude').val(data[0]);
    $('#longitude').val(data[1]);
    $('#set').click();
  });

  setInterval(function() {
    $.get(
      '/loc',
      function(data){
        $('#locationName').text(String(data));
      }
    );
    $.get(
      '/nearby',
      function(data){
        $('#nearbyPokemon').text(String(data));
      }
    );
  }, 5000);
</script>

 

eexさんの情報(eextutto):
LEDのついた万歩計程度のもので、GOプラスに内蔵されてる振動センサーやら時計機能やらを元にポケモンが出現したことにして、アプリを立ち上げると位置に見合ったポケモンが出てきたことにすればいい

ポケストップからのアイテム入手は?
→ 近くを通ると自動的にアイテムを入手する。定期信号を送信して、スマホ側で位置ログを残せばよい

ダイアログ・セミコンダクター DA14580:「Pokemon GO Plus」のBLEソリューション、採用の決め手は

東京でポケモンGO

コラッタ、文京区、0723、1020

f:id:sato7411:20160723130425p:plain

 

カイロス、文京区、0723、1039

f:id:sato7411:20160723130612p:plain

 

ズバット、文京区、0723、1222

f:id:sato7411:20160723160900p:plain

 

サンド、文京区、0723、1228

f:id:sato7411:20160723131007p:plain

 

ニョロモ、文京区、0723、2054

f:id:sato7411:20160725013702p:plain

 

トランセル、文京区、0723、1033

f:id:sato7411:20160723132404p:plain

 

ドードリオ、文京区、0723、2011

f:id:sato7411:20160724022238p:plain

 

トサキント、文京区、0723、2053

f:id:sato7411:20160724022338p:plain

 

ポッポ、文京区、0724、1354

f:id:sato7411:20160725030809p:plain

 

 

ビーコン、モノのインターネット(IoT)、Bluetooth Low Energy(BLE)

(株)ACCESS よりビーコンの使い方のマニュアルが出ていました。

https://a-beacon.com/manual/

 

管理アプリ(iPad) / 管理サイト(ウェブ)

ビーコン機器(ビーコン端末)

リファレンスアプリ(スマホ / タブレット

 

スマホ / タブレット
位置情報を有効化
Bluetooth を ON
プッシュ通知をタップすると配信要素をアプリで開きます
LINK の場合は、URL をタップするとウェブページを表示します

 

■ リファレンスアプリ
ログイン / ログアウト(メールアドレスまたはユーザID、パスワード)
事業者ID
商品説明 / ポイントカード / スタンプラリー / クーポン配信 / 勤怠管理 / Passbook / Google Glass

 

■ 管理サイト
PUSH配信の要素
 TEXT、TEXTBOX、NUMBER、IMG、FILE、EXTERNAL_IMG
 LINK、DATE、EXPIRED(有効期限)、AVAILABLE(有効 / 無効)
 JSONJSON形式のテキスト)

トリガー対象(ビーコン(グループ)、位置情報、NFC
日程(任意期間、日時・曜日繰り返し)
配信条件(常に配信、性別、年齢)

■ ビーコン機器
特性
 UUID
 Type
 isLowBattery
 is3axis
 TxPower(送信パワー)
 Adv Interval(送信間隔)
 Measured Power(キャリブレーション用電波発信強度)
 Battery Level(電池残量低下の警告)、Notify Battery Low(電池残量低下通知)
 Term Of Signal(s)(ボタン押下時の信号送信時間)※ボタンビーコンのみ対応
 LED Control(電波発信時のLED点灯/点滅On/Off) 
表示項目
 名前
 Major / Minor
 Proximity (Far / Intermediate / Near / Unknown)
 RSSI (受信強度)

リージョン(=ビーコングループ: UUID / Major / Minor で指定する)
クラウドデータ、ビーコンデータ、ビーコンパラメータ

ファームウェア更新、nRF Toolbox App、Nordic

 

GPS 位置情報
位置情報名
経度、緯度、距離(プッシュ受信領域の半径)、概要(住所)、都道府県、都市名

 

■ ログ
ビーコンアクセスログ、ユーザアクションログ、コンテンツ取得ログ
(アプリユーザの行動履歴ログ)

ユーザ
 メールアドレス
 エリアに属する、エリアは4階層まで、エリアで配信要素を制限する

ヒートマップ
 多くのユーザを検出すると赤に変化する
 ビーコンと通信したスマホ/タブレットがビーコン間を移動した動線を表示

 

■ Wallet(Passbook)
空港アプリで搭乗券を購入し、右上のボタンを押して Wallet(Passbook)に追加する。空港アプリを起動しておく。搭乗口のビーコンに近づくと、一覧に搭乗券名が表示される。タップすると、Wallet(Passbook)アプリが起動し、紐付けられた搭乗券が表示される。

 

Google Glass
[事前準備]
MyGlass アプリを iPhone にインストールする。iPhoneGoogle GlassBluetooth でペアリングする。MyGlass アプリで表示した QR コード(接続名とパスワード)を、Google Glass で読み取って、サインインする。Google GlassWifi 経由でネットワークに接続可能になる(Google Glass 単体ではパスワードを入力することができないため)。

案内アプリに Google アカウントでログインする。Google Glass がビーコンに近づくと、データ要素が配信され、Google Glass と案内アプリの両方に表示される。

 

■ 雑
https://fabkura.gitbooks.io/ble-docs/content/


 

IoT 末端分析

参考:http://rethink-iot.com/2016/06/09/ibm-cisco-access-thingworx-race-iot-edge-analytics/

無線通信での、セキュリティソフトとファームウェアのアップデート
クラウドで分析するために、データを送信する前に事前処理を行い、ネットワークの負荷を軽減する
node.js や PhantomJS(JSCore)がベースの JavaScript エンジンを使ったソフトウェアよりも省メモリで動作する

 

HTML5 ユーザーインターフェイス]( node.js 系でアプリ開発
  |
Chromium ベースの軽量ブラウザ]
  |
[独自OS]と[ node.js の実行環境の1つ]と[無線 LAN]

 

開発ツール Express

参考: http://www.tutorialspoint.com/nodejs/nodejs_express_framework.htm

■ ハローワールド

ファイル:app.js
var express = require('express');
var app = express();

app.get('/', function (req, res) {
  res.send('Hello World!');
});
// app.get('/index.htm', function (req, res) {
//    res.sendFile( __dirname + "/" + "index.htm" );
// })

app.listen(3000, function () {
  console.log('Example app listening on port 3000!');
});

 

■ GETメソッド

ファイル:index.htm
項目入力を作成
フォームの送信先を action="http://127.0.0.1:3000/process_get" にする

ファイル:app.js
public ファイルの公開(ブラウザで直接URLを指定して表示できるファイル)
index.htm の表示
process_get の表示(応答)
サーバーの listen

■ POSTメソッド

ファイル:index.htm
項目入力を作成
フォームの送信先を action="http://127.0.0.1:3000/process_post" にする

ファイル:app.js
urlencodedParser の用意
public ファイルの公開(ブラウザで直接URLを指定して表示できるファイル)
index.htm の表示
process_post の表示(応答)
サーバーの listen

 

■ ファイルアップロード

ファイル:index.htm
ファイル名を選択(input type="file")
フォームの送信先を action="http://127.0.0.1:3000/file_upload" にする
また、enctype="multipart/form-data" で、POST

ファイル:app.js
bodyParser の用意
multer の用意(ファイルアップロードのモジュール)
public ファイルの公開(ブラウザで直接URLを指定して表示できるファイル)
index.htm の表示
file_upload の応答(POST)
 保存先のファイル名を用意
 readFile( path, function () { writeFile( file, data, function () {
   結果表示
     });
 });
サーバーの listen

 

■ クッキー

ファイル:app.js
cookieParser の用意
/ の表示時に、req.cookies で、クライアントから送られたクッキーを取得
サーバーの listen

 

MySQL

参考:https://codeforgeek.com/2015/01/nodejs-mysql-tutorial/
参考:http://atmarkplant.com/nodejs-mysql-basic/

package.json - "dependencies": { - "mysql": "^2.5.4"

npm install

ファイル:app.js
var express    = require("express");
var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'mysql001.db.com',
  user     : 'laa0397',
  password : 'abcdef',
  database : 'laa0397-db'
});
var app = express();
connection.connect(function(err){
  if (!err) {
    console.log("Database is connected ... nn");    
  } else {
    console.log("Error connecting database ... nn");    
  }
});
app.get("/control/mysql_responds", function(req,res) {
  connection.query('SELECT * from co_person', function(err, rows, fields) {
    connection.end();
    if (!err)
      console.log('The solution is: ', rows);
    else
      console.log('Error while performing Query.');
    });
});
app.listen(3000);
→ 更にプール接続に変更する

 

HTTPS

ファイル:bin/www

var https = require('https');
var fs = require('fs');

var options = {
  key: fs.readFileSync('/var/www/html/homepage/keys/server.rsa'),
  cert: fs.readFileSync('/var/www/html/homepage/keys/server.crt')
};
var server = https.createServer(options, app);
 

■ ルーティング / ビュー / パブリック

ファイル&フォルダ:
  routes / index.js、users.js
  views / index.ejs
  public
render を実行すると、ビューに置かれ編集した HTML を表示する
send を実行すると、データを送信する

 

■ ボタン押下

ファイル:views / index.ejs
<input name="like" id="like" value="Like" type="submit" /> <input name="count" id="count" value="0" type="text" readonly />
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
  $('#like').click(function(){
    $.post(
      '/test',
      {name:"ABC", email:"abc@yahoo.com"},
      function(data){
        $('#count').val(data);
      }
    )
});
</script>

ファイル:routes / index.js
/* Button click. */
var count = 0;
router.post('/test', function (req, res) {
    count += 1;
    res.send(String(count));
    console.log('works');
});

 

■ 空きメモリ量

ファイル:views / index.ejs
空きメモリ量<span id="freemem"></span><br>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
  setInterval(function() {
    $.get(
      '/freemem',
      function(data){
        $('#freemem').text(String((Number(data)/1024/1024/1024).toFixed(3))+' GB');
      }
    )
  }, 300);
</script>

ファイル:routes / index.js
/* Memory information. */
const os = require('os');
router.get('/freemem', function (req, res) {
    res.send(String(os.freemem()));
    console.log('freemem');
});

 

■ HTTP プロキシ(HTTPS プロキシ)

ファイル:proxy.js

var http = require('http');
var httpProxy = require('http-proxy');
var url = require('url');

var proxy = httpProxy.createProxyServer({});
var server = http.createServer(function(req, res) {
  if (req.headers == null || req.headers.host == null || req.url == null) {
    // do nothing
  }
  else {

    var hostname = req.headers.host.split(":")[0];
    var pathname = url.parse(req.url).pathname;

    if (hostname == 'example.com' || hostname == 'apache.example.com') {
      proxy.web(req, res, { target: 'https://localhost:8443', secure: false });
    } else if (hostname == 'node.example.com') {
      proxy.web(req, res, { target: 'https://localhost:8124', secure: false });
    } else {
      res.writeHead(404);
      res.end();
    }
  }
});
server.listen(80); 

 

(作成中)

パナマ文書

租税回避地を利用しての節税を放置したままで、来年4月の消費税率10%への増税は、ありえないと思いますが、どうでしょう。経過を見守りたいと思います。

 

2016年5月10日午前3時、公開日

[予想]
日本の多くの大企業、会社経営者、が名前を連ねる。宮内氏かな。

[実際]
公開のウェブページ: https://offshoreleaks.icij.org/
国で探す(Search by country)と管轄で探す(Search by jurisdiction)があって、
前者にて、人名、会社名、住所、を入力して、検索する。

 

2016年5月、やばそうな情報

Kazuhiko ASAKAWA、AIJ投資顧問
SOKA GAKKAI, INC. (opencorporates から Panama 所在で見つかる)、創価学会
NHK GLOBAL INC.
パナマップ: http://153.120.36.84/

ダウンロードした csv をテキスト検索(Bunkyo)

東京都文京区白山1-33-16 パークコートプレイス 801、1F ネオスタンダード、2F澤田こどもクリニック、3F NiCT、4F NiCT、5F 医療法人社団 同友会、6F NiCT、7F NiCT、8F空き、9F 日本ビル管理保証(株)、9F Grace international Ltd.、PH T.S Investment Ltd.、KIYOTSUGU KAWASAKI
東京都文京区弥生2-4-22、リサーラ東京(有)、MUTO KAZUHITO、塚本和子
東京都文京区白山4-33-21 ライオンズマンション白山 303、TSUSHIMA KOJI
東京都文京区本郷3-15-2 本郷二村ビル、OZAKI SHIGERU
東京都文京区白山5-22-1 コロナビル 2F (〒112-0001、Shiroyama Ichilhara Building)、YASUHIKO ONO
東京都文京区千駄木3-36-8 シルバーパレス千駄木 601、TAKATOSHI KUWAHARA
東京都文京区小石川4-16-13 小石川パークタワー 1705、YASUSHI KINOSHITA、http://www.kinoshita.com/
東京都文京区本郷4-9-25 真成館ビル 604、JASC 日本資産証券化センター、柳川 勇夫、YATSUKI MATSUMI
東京都文京区大塚3-3-14 茗荷谷パークホームズ 901、Hisako Akutagawa
東京都文京区本郷4-12-16 トーア文京マンション 305、WATARU YOSHIKOSHI
東京都文京区音羽1-14-2 三井音羽ハイツ 1303、Masaru Yamamoto
東京都文京区西片2-25-8 モンテベルデ本郷西片 703、Shiro Otomo

2016年5月28日午後10時

来年4月の消費税率10%への引き上げについて、2019年10月まで2年半延期

 

(作成中)