LoginSignup
1
0

More than 1 year has passed since last update.

NetBSDでもIoT

Last updated at Posted at 2022-12-13

ORIONのネットワークが使えるようになったのでInternet of Test(IoT)を行ってみます。

まずhttpが話せるmrubyを用意します。ここのビルド設定に以下を追加します。

build_config/netbsd.rb
  conf.gem :git => 'https://github.com/mattn/mruby-uv.git'
  conf.gem :git => 'https://github.com/mattn/mruby-http.git'
  conf.gem :git => 'https://github.com/luisbebop/mruby-polarssl.git'
  conf.gem :git => 'https://github.com/matsumoto-r/mruby-simplehttp.git'
  conf.gem :git => 'https://github.com/matsumoto-r/mruby-httprequest.git'
  conf.gem :git => 'https://github.com/matsumoto-r/mruby-sleep.git'

  conf.linker.libraries = %w(m)

libuvのconfigureを作るためautoconf,automake,libtoolが必要なのでpkgをインストールしておきます。

これでrakeでビルドするとmruby-uvのlibuvのビルドで失敗するので、以下を追加します。

build/repos/cross-netbsd-arm/mruby-uv/mrbgem.rake
  configure_opts += ["--host arm-portbld-netbsd"]

直に追加しました。なにか適当な条件式で括るのが良いですが、分からなかったです。RUBY_PLATFORMを使うのが良さそうなのですが、他のところでエラーになるので、あきらめました。現在のコードはRUBY_PLATFORMがhostの意味を持つケースとtargetの意味を持つケースがあり、混乱しているようです。

--hostなのでamd64-portbld-freebsdが正しいような気がします、こうしないとダメでした。libuvのconfigureの問題か、configure自体の問題のどちらかと思われます。

LUNAやってたころはconfigureはすばらしいと思いましたが、あの頃ほどシステムに違いがなく、必要以上に複雑なconfigureは近代においては百害あって一利なしなきさえします。

ライブラリの構成が違うのでここもいじりました。

build/repos/cross-netbsd-arm/mruby-uv/mrbgem.rake
#    spec.linker.libraries << ['uv', 'pthread', 'rt', 'm', 'dl']
    spec.linker.libraries << ['uv', 'pthread', 'kvm']

libmは何故かここに書いてもきかなかったので、build_configに書いてます。

またNetBSDにはAI_ALLとAI_V4MAPPEDが無いようなのでbuild/repos/cross-netbsd-arm/mruby-uv/src/mrb_uv.cの定義をコメントアウトします。

ZRouterのFreeBSD環境ではlibuvは別にビルドしてそれを使うようにしています。

これでビルドできたmrubyをramdisk.fsに入れてINSTALLカーネルを作りu-bootでブートします。

シングルユーザーで上がっているshから以下のmrubyスクリプトを実行します。

iot.rb
APIKEY = "naisyo"

count = 0
while 1 do
  p SimpleHttp.new("https", "api.thingspeak.com", 443).get("/update?api_key=" +
APIKEY + "&field1=" + count.to_s, {'User-Agent' => "test-agent"})
  count = count + 1
  Sleep::sleep(60)
end

実行する前にdhcpcdを起動してIPを取得しておきます。

できました。

image.png

しばらく動かしていたらエラーで止まってました。なんだろう?

trace (most recent call last):
        [7] iot.rb:5
        [6] iot.rb:5:in get
        [5] iot.rb:5:in request
        [4] iot.rb:5:in send_request
        [3] iot.rb:5:in new
        [2] iot.rb:5:in initialize
        [1] iot.rb:5:in foreach
iot.rb:5:in getaddrinfo: getaddrinfo: Temporary failure in name resolution (SocketError)

Ethernetコンバーターが落ちたようです。。。

mrubyのバイナリサイズ確認してみました。

オプション ストリップ前 ストリップ後
無し(デフォルト) 4242524 3212000
-Os 3405148 2412344

スタティックリンクなので大きいです。

この仕組みでモジュールに押し込むためにはRAM 16MでFlash 4Mでどうにかなるかもしれません。(未確認)

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