2015年7月11日土曜日

2015年7月9日木曜日

Hexo


Node.js 上にブログサイト?を作れるようだ。
Rubyベース、Pythonベースなど色々あるようだが、JavaScriptベースの「Hexo」にトライ。

npm install -g hexo
でインストールできるとあるが、resiterなんとかエラーが出る。
何が効いたか不明だが、3回目でうまくいったようだ。
C:\Users\Mobile>npm install -g hexo
\


> dtrace-provider@0.5.0 install C:\Users\Mobile\AppData\Roaming\npm\node_modules
\hexo\node_modules\bunyan\node_modules\dtrace-provider
> node scripts/install.js

npm WARN optional dep failed, continuing fsevents@0.3.6
npm WARN optional dep failed, continuing fsevents@0.3.6
C:\Users\Mobile\AppData\Roaming\npm\hexo -> C:\Users\Mobile\AppData\Roaming\npm\
node_modules\hexo\bin\hexo
hexo@3.1.1 C:\Users\Mobile\AppData\Roaming\npm\node_modules\hexo
├── hexo-front-matter@0.2.2
├── pretty-hrtime@1.0.0
├── abbrev@1.0.7
├── titlecase@1.0.2
├── archy@1.0.0
├── text-table@0.2.0
├── bluebird@2.9.32
├── moment-timezone@0.3.1
├── moment@2.10.3
├── lodash@3.10.0
├── tildify@1.1.0 (os-homedir@1.0.0)
├── chalk@1.1.0 (ansi-styles@2.1.0, supports-color@2.0.0, escape-string-regex
p@1.0.3, strip-ansi@3.0.0, has-ansi@2.0.0)
├── strip-indent@1.0.1 (get-stdin@4.0.1)
├── hexo-cli@0.1.7 (minimist@1.1.1)
├── hexo-i18n@0.2.1 (sprintf-js@1.0.2)
├── minimatch@2.0.8 (brace-expansion@1.1.0)
├── through2@1.1.1 (xtend@4.0.0, readable-stream@1.1.13)
├── swig-extras@0.0.1 (markdown@0.5.0)
├── js-yaml@3.3.1 (esprima@2.2.0, argparse@1.0.2)
├── cheerio@0.19.0 (entities@1.1.1, dom-serializer@0.1.0, css-select@1.0.0, h
tmlparser2@3.8.3)
├── hexo-util@0.1.7 (ent@2.2.0, highlight.js@8.6.0)
├── warehouse@1.0.2 (graceful-fs@3.0.8, cuid@1.2.5, JSONStream@0.10.0)
├── hexo-fs@0.1.3 (escape-string-regexp@1.0.3, graceful-fs@3.0.8, chokidar@0.
12.6)
├── nunjucks@1.3.4 (optimist@0.6.1, chokidar@0.12.6)
├── bunyan@1.4.0 (safe-json-stringify@1.0.3, dtrace-provider@0.5.0, mv@2.1.1)

└── swig@1.4.2 (optimist@0.6.1, uglify-js@2.4.23)

C:\Users\Mobile>

バージョンを調べる
C:\Users\Mobile>hexo -v
hexo-cli: 0.1.7
os: Windows_NT 6.1.7601 win32 ia32
http_parser: 2.3
node: 0.12.6
v8: 3.28.71.19
uv: 1.6.1
zlib: 1.2.8
modules: 14
openssl: 1.0.1o
続いて
C:\Users\Mobile>hexo init blog150708
INFO  Copying data to ~\blog150708
INFO  You are almost done! Don't forget to run 'npm install' before you start bl
ogging with Hexo!

ただ、ブログのルートが以下の場所に出来た。何かのサブディレクトリに入れたかった。

  C:\Users\Mobile\blog150708

インストールのコマンドに -g を入れたのが原因?
そのまま進み、指示に従って以下をたたく
C:\Users\Mobile\blog150708>npm install
長いログが出たので、ファイルにしておく
C:\Users\Mobile\blog150708\npm_install_の結果.txt
あとは hexo server して http://localhost:4000 にアクセスすると標準のホーム画面が起動した!!

最後は投稿。以下でタイトルだけは作れた。本文はどうやって書くのだろう?
C:\Users\Mobile\blog150708>hexo new
Usage: hexo new [layout] <title>

Description:
Create a new post.

Arguments:
  layout  Post layout. Use post, page, draft or whatever you want.
  title   Post title. Wrap it with quotations to escape.

Options:
  -p, --path     Post path. Customize the path of the post.
  -r, --replace  Replace the current post if existed.
  -s, --slug     Post slug. Customize the URL of the post.


C:\Users\Mobile\blog150708>hexo new post test150708
INFO  Created: ~\blog150708\source\_posts\test150708.md

C:\Users\Mobile\blog150708>hexo server
INFO  Hexo is running at http://0.0.0.0:4000/. Press Ctrl+C to stop.

2015年7月5日日曜日

arduino-firmata

橋本商会様

http://shokai.org/blog/archives/8559

に従い、arduino-firmata を Node.js command prompt からインストール
C:\Users\Mobile>npm install arduino-firmata
|
> serialport@1.7.4 install C:\Users\Mobile\node_modules\arduino-firmata\node_mod
ules\serialport
> node-pre-gyp install --fallback-to-build

[serialport] Success: "C:\Users\Mobile\node_modules\arduino-firmata\node_modules
\serialport\build\serialport\v1.7.4\Release\node-v14-win32-ia32\serialport.node"
 is installed via remote
arduino-firmata@0.3.2 node_modules\arduino-firmata
├── eventemitter2@0.4.14
├── debug@2.2.0 (ms@0.7.1)
└── serialport@1.7.4 (bindings@1.2.1, sf@0.1.7, async@0.9.0, nan@1.8.4, optim
ist@0.6.1)
インストールはうまくいったようだ。

使い方は以下を参考に
https://www.npmjs.com/package/arduino-firmata

ただ、エラーが出てうまくいかない。

var ArduinoFirmata = require('arduino-firmata');
var arduino = new ArduinoFirmata();

arduino.connect();  //use default arduino
arduino.connect('dev/tty/usb-device-name');

arduino.on('connect', function(){
  console.log("board version"+arduino.boardVersion);
});


■johnny-five 
その後、johnny-five でもうまくいかず。
http://ics-web.jp/lab/archives/4758
https://github.com/rwaldron/johnny-five/wiki/Board

以下のエラーが出る。
スクリプトは以下のもの。comポートを指定してconnectは出来たようだが、その後が進まない。
ここのトラブルシューティングを調べてみる。
https://github.com/rwaldron/johnny-five/wiki/Getting-Started#trouble-shooting



var j5 = require("johnny-five");
var arduino = new j5.Board({port:"COM11"});

console.log("ssugi");

arduino.on ("ready", function() {
  //
  var led = new j5.Led(2);
  this.repl.inject({
    led: led
  });
});
C:\Users\Mobile>node j5_ledblink150705.js
1436087045693 Connected COM11
ssugi
1436087055696 Device or Firmware Error A timeout occurred while connecting to th
e Board.

Please check that you've properly flashed the board with the correct firmware.
See: https://github.com/rwaldron/johnny-five/wiki/Getting-Started#trouble-shooti
ng
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: A timeout occurred while connecting to the Board.
    at Board.<anonymous> (C:\Users\Mobile\node_modules\johnny-five\lib\board.js:
411:26)
    at Timer.listOnTimeout (timers.js:119:15)

C:\Users\Mobile>

Node.js

マイコン制御のためにNode.jsを勉強。

■インストール
ほぼ、こちらのサイトの通り
http://tyoshikawa1106.hatenablog.com/entry/2015/04/03/224736

実行は通常のコマンドプロンプトではなく、専用の Node.Js command prompt をから行う。

C:\Users\Mobile\hellonodejs.js
などを作っておき

C:\Users\Mobile> node hellonodejs.js

と実行する。


2015年7月4日土曜日

JavaScriptでマイコン制御

ICS LAB様の以下の記事が最適
http://ics-web.jp/lab/archives/4758
ICS LAB様のサイトは他にも興味深い記事が多い。


橋本商会様の以下のページも詳しいのだが、レベルアップ後に参考にさせていただく。

■橋本商会様 「NodeにArduinoのコードを埋め込む arduino-firmata npm」
http://shokai.org/blog/archives/8559


Node.js のインストール
http://www.cyokodog.net/blog/first-node-js/

LED制御

Processing + ControlP5 + マイコン
Processing.js + マイコン
でLEDを制御する。出来るはず。

リンク

http://blog.goo.ne.jp/roboz80/e/6d309257fd23f2cbee97254df460fb56

【追記】 7/5
pyFirmata:GUIはpyQtで。
http://ca5.hatenablog.com/entry/2014/02/23/235731
http://www.instructables.com/id/Control-your-arduino-from-your-PC-with-the-Qt-Gui/

jonny-five: Node.Js上でfirmataを実現。GUIは別の.jsライブラリを探す。
http://nextdeveloper.hatenablog.com/entry/2015/06/10/114227