Coder Social home page Coder Social logo

iotintern's Introduction

IotIntern

お掃除ロボットの死活監視を題材にしたインターンシップのプログラム一式。

動かし方

依存関係の取得

予め取得済みのものが AMI に含まれているので、場合に応じて行う。

mix deps.get && mix deps.get

Web Server の起動

Linkit アカウント登録完了メールにパスワードが記載されているので、メール記載のリンクから Linkit を開いてください。

Gear コンフィグに下記の値を設定する。

linkit_api_key, notification_user_credential, chatroom_id は事前に共有される。

$ cat gear_config.json
{
  "linkit_app_id": "a_BjF4XHB2",
  "linkit_group_id": "g_YrTWTxJY",
  "linkit_api_key": "2t23xxxxxxxxxxxxxx", // 要確認
  "notification_user_credential": "xxxxx",
  "chatroom_id": "xxxxxxxx"
}
IOT_INTERN_CONFIG_JSON=$(cat gear_config.json) iex -S mix

シミュレータからの確認

Web Server を起動した状態でブラウザから http://iot-intern.localhost:8080/ui/index.html にアクセスする。

リポジトリレイアウト

.
├── README.md
├── deps // mix deps.get でパッケージが入る
├── doc // ドキュメント
├── gear_config.json // コンフィグファイル
├── lib // 自作のライブラリ記述先
├── mix.exs // mix project の設定(触らない)
├── mix.lock // 依存パッケージの version 一覧 (触らない)
├── priv // シミュレータ画面のような静的コンテンツ
├── test // テストコード
└── web // API 記述先

Antikythera概要

WebサーバーとしてのAntikythera

Antikytheraは複数のwebサービスをホスティングするPlatform as a Serviceである。 Antikytheraにホスティングされた個々のwebサービスをgearと呼んでいる。 AntikytheraはErlang VM上で動くErlangプロセスの1つであり、gearもまたAntikytheraと同じErlang VM上で動いている。

  • Antikytheraの機能
    • HTTPサーバー
      • クライアントからのHTTPリクエストに対し、Antikytheraが管理しているErlangプロセスを使ってgearの関数を呼び出し、処理を行う
      • 処理結果をHTTPレスポンスとしてクライアントに返す
    • Web Socketの管理
    • (図には書いていないが) gearが任意の非同期処理を行うための機能提供

Overview of antikythera framework

HTTPリクエストに対しHTTPレスポンスが返るまでの流れ

  1. AntikytheraがクライアントからのHTTPリクエストを受け取る
  2. Antikytheraがgearの関数を呼び出す
    1. リクエストURLによって処理を行うgearが決まる
      • サブドメインに基づく
    2. リクエストのメソッドとURLのパスによって処理を行う関数が決まる
      • gearのweb/router.exに基づく
      • このファイルにはメソッド・パスの組に対して呼び出されるべき関数(コントローラーと呼ぶ)が定義されている
    3. gearのコントローラーが実行される
      • コントローラーはHTTPリクエストを表すデータ構造を受け取り、HTTPレスポンスを表すデータ構造を返す関数
      • レスポンスボディは必要に応じてHTMLやJSONに加工する(ビューの関数を呼び出す)
  3. AntikytheraがクライアントにHTTPレスポンスを返す

Gear開発者はコントローラーを起点として、HTTPリクエストに対しどのような処理を行うべきか、どのようなHTTPレスポンスを返すべきかに集中すればいい。

API 追加のやり方

API を追加するには"コントローラーの処理を書くこと"と"ルーターのパスを設定する" の二つを行う。

コントローラーの処理を書く

web/controller/hello.ex のようにモジュールと関数を定義する。

Hello モジュールの hello/1 関数は第一引数に conn を受け取り、新しいconn を返す。そしてレスポンスのコンテンツを conn に詰めるには関数 Conn.json/3 を使っている。

ルーターのパスを書く

web/router.ex を書き換える。

テストの実行

全ての *_test.exs ファイルを対象に実行するには

IOT_INTERN_CONFIG_JSON=$(cat gear_config.json) mix test

または特定のテストファイルに対して下記のように行う。

IOT_INTERN_CONFIG_JSON=$(cat gear_config.json) mix test test/web/controller/hello_test.exs

お掃除ロボットの API 実装課題

apidoc branch 上の 仕様書シーケンス図 の通りに実装することを目指します。 下記の課題に従って実装を進めてください。

iotintern's People

Contributors

asyorikano avatar fumipo-theta avatar naru-hiyoko avatar amasakitakahashi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.