2012年9月23日日曜日

制御用のプログラムをdaemon化

以前作ったプログラムはコマンドラインで命令を引数に実行すると、XBeeモジュールに命令を出して、その応答を待って表示して終わるだけのものでした。
XBeeのモジュールが増えてきたせいか、たまに通信のシーケンスがおかしくなって暫く通信できなくなった後に復帰する現象がみられました。

まずXBeeモジュールの通信部分を安定させるため、送ったコマンドと応答のパケットをqueueに積んで照合しながらTimeoutしたものをRetryするように作り直しました。
daemonとしてmac miniで常時動かしておいて、socketでこのdaemonにテキストベースの命令を投げるとconfigファイルで定義されたシーケンスを実行するようにしました。

現在のコマンド一覧です。

south_window_open
south_window_stop
south_window_close
south_window_stat
north_window_open
north_window_stop
north_window_close
north_window_half
north_window_stat
floor_heater_living_on
floor_heater_living_off
floor_heater_living_stat
floor_heater_dining_on
floor_heater_dining_off
floor_heater_dining_stat
entrance_key_open
entrance_key_close
entrance_key_stat
internal_2f_temp
internal_1f_temp
external_south_temp
external_north_temp
external_rain
east_shutter_open
east_shutter_stop
east_shutter_close
center_shutter_open
center_shutter_stop
center_shutter_close
west_shutter_open
west_shutter_stop
west_shutter_close
aircon_cooler_full_27
aircon_cooler_auto_27
aircon_heater_auto_18
aircon_heater_full_18
aircon_cooler_25
aircon_cooler_26
aircon_cooler_27
aircon_cooler_28
aircon_cooler_29
aircon_heater_24
aircon_heater_23
aircon_heater_22
aircon_heater_21
aircon_heater_20
aircon_stop



例えばsocketでdaemonに対してfloor_heater_living_onという命令がきたら、床暖房のコントローラにつけたモジュール経由でHA端子のStatusを読んでonになっていなければonにするパルスを出し、再度Statusを確認して応答を返す。変わらない場合は何回かリトライ。それでもだめならエラーを返す。
という感じです。
後半のaircon系のコマンドはiRemoconへsocket通信で投げています。

まずは家の中からはtelnet経由で制御できるところまでは出来ました。
次はスケジュール管理しながら、定期的にいろんなセンサーの状態を読み取って雨が降ってきたら窓を閉めたりするプログラムを追加していきます。

0 件のコメント:

コメントを投稿