
前回、iRemocon Wi-FiをWindowsのコマンドプロンプトから操作する方法を書きました。
このように、iRemoconは、ローカルIPさえ分かってしまえば、telnetで簡単なコマンドを書くことで、結構たやすく操作することができます。
ただ、コマンドを覚えたり書いたりするのが面倒なので、もっと手軽にテストができる簡易サンプルプログラムを作ってみたので紹介です。
目次
iRemocon Wi-Fi簡易操作アプリ
その、簡易サンプルプログラムがこちら。

[wpdm_file id=6]
開発者向け情報のIRM-03WLAコマンド仕様書(PDF)にある操作コマンドを、ボタンで実行できるようにしてあります。
ボタンを押すことで、手軽にWindowsからiRemocon Wi-Fiのコマンド操作テストを行うことができます。
一応ソースも付いています。ただし作成は、Delphiというかなりマイナーな部類に入る言語で行いました。(それしかまともに使えないので)
しかも、Delphiといっても前時代の遺物Delphi7 IDEで作成しているので、今のIDEでは、そのままソース編集できないかもしれません。
一応、iRemoconオブジェクトを作成し、オブジェクトのiRemocon Wi-Fi操作メソッドで操作をしています。
以下に、Delphiで書いたiRemocon操作オブジェクトを載せておきます。(クリックで開く)
unit iRemocon;
interface
uses
Windows, Messages, SysUtils, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdTelnet, ExtCtrls, Classes, Forms, DateUtils, dbg;
const
//リピート時間定数
RS_NONE = 0; //リピートなし
RS_ONE_HOUR = 3600; //一時間ごと
RS_12_HOUR = RS_ONE_HOUR * 12;
RS_ONE_DAY = RS_ONE_HOUR * 24; //一日ごと
RS_ONE_WEEK = RS_ONE_DAY * 7; //一週間ごと
UTC0900 = 32400;
type
TSendEvent = procedure (Sender: TObject; Command: String) of object;
TSentEvent = procedure (Sender: TObject; Response: String) of object;
TCustomErrorEvent = procedure (Sender: TObject;
ErrorCode, ErrorTitle, ErrorMessage: string) of object;
//タイマーリスト取得用レコード
TTimerRec = record
No: Word;
RemoconNo: Word;
DateTime: TDateTime;
RepeatSec: Cardinal;
end;
//タイマーリスト取得用動的配列
TTimerArray = array of TTimerRec;
TIRemocon = class(TComponent)
private
FHost: string;
FIdTelnet: TIdTelnet;
FInterval: Word;
FIsLastCommandError: Boolean;
FLastErrorCode: string;
FLastErrorMessage: string;
FLastErrorTitle: string;
FLastReturnCommand: string;
FLearningTimeout: Cardinal;
FLogList: TStringList;
FNecessaryCRLF: Boolean;
FOnCustomError: TCustomErrorEvent;
FOnSend: TSendEvent;
FOnSent: TSentEvent;
FPort: Integer;
IsLearning: Boolean;
IsReturnFinished: Boolean;
TmpLastReturnCommand: string;
procedure IdTelnetDataAvailable(Sender: TIdTelnet;
const Buffer: String);
procedure SetLearningTimeout(const Value: Cardinal);
function SendCommand(Command: string): Boolean;
function IsRemoconNoValid(RemoconNo: Word): Boolean;
procedure SetErrors(const ReturnCommand: string);
procedure SetInterval(const Value: Word);
procedure SetOnSend(const Value: TSendEvent);
procedure SetOnSent(const Value: TSentEvent);
procedure SetHost(const Value: string);
procedure SetOnCustomError(const Value: TCustomErrorEvent);
procedure SetNecessaryCRLF(const Value: Boolean);
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
{IRM-01Lコマンド}
function KeepAlive: Boolean; //[au]:接続確認用
function TransmitInfrared(RemoconNo: Word): Boolean; //[is]:赤外線発光
function StartLearning(RemoconNo: Word): Boolean; //[ic]:リモコン学習開始
function StopLearning: Boolean; //[cc]:リモコン学習中止
function SetTimer(RemoconNo: Word; //[tm]:タイマーセット
ADateTime: TDateTime; RepeatSec: Cardinal): Boolean;
function GetTimers(var Timers: TTimerArray): Boolean; //[tl]:タイマー一覧取得
function CancelTimer(TimerNo: Word): Boolean; //[td]:タイマー解除
function SetDateTime(ADateTime: TDateTime): Boolean; //[ts]:現在時刻設定
function GetDateTime(var ADateTime: TDateTime): Boolean; //[tg]:現在時刻取得
function GetVersion(var Version:string): Boolean; //[vr]:ファームバージョン番号の取得
function GetIlluminance(var Illuminance:Single): Boolean; //[li]:照度センサー値の取得
function GetHumidity(var Humidity:Single): Boolean; //[hu]:湿度センサー値の取得
function GetTemperature(var Temperature:Single): Boolean; //[te]:温度センサー値の取得
function GetSensors(var Illuminance, Humidity, Temperature:Single): Boolean; //[se]:すべてのセンサー値の取得
//iRemocon用接続先ポート番号(51013)
property Port: Integer read FPort;
//最新の返信コマンド
property LastReturnCommand: string read FLastReturnCommand;
//最新のエラーコード
property LastErroreCode: string read FLastErrorCode;
//最新のエラータイトル
property LastErrorTitle: string read FLastErrorTitle;
//最新のエラーメッセージ
property LastErrorMessage: string read FLastErrorMessage;
//最新の返信コマンドがエラーだったか
property IsLastCommandError: Boolean read FIsLastCommandError;
//コマンドログ
property Log: TStringList read FLogList;
published
property Host: string read FHost write SetHost;
//連射防止用のインターバル Default 500ms
property Interval: Word read FInterval write SetInterval default 500;
//学習タイムアウト時間 Default 15秒(15000ms)
property LearningTimeout: Cardinal
read FLearningTimeout write SetLearningTimeout default 15000;
//返信コマンドに#13#10を含めるか
property NecessaryCRLF: Boolean
read FNecessaryCRLF write SetNecessaryCRLF default False;
//コマンド送信前イベント
property OnSend: TSendEvent read FOnSend write SetOnSend;
//コマンド送信後イベント
property OnSent: TSentEvent read FOnSent write SetOnSent;
//エラー出力用に作ったイベントの設定
//書式の変更をするにはSetErrors手続きを変更してください
property OnCustomError: TCustomErrorEvent
read FOnCustomError write SetOnCustomError;
end;
procedure Register;
implementation
uses Math;
procedure Register;
begin
RegisterComponents('Samples', [TIRemocon]);
end;
{ TIRemocon }
constructor TIRemocon.Create(AOwner: TComponent);
begin
inherited;
FPort := 51013;
FInterval := 500;
FLearningTimeout := 15000;
FNecessaryCRLF := False;
//Telnetの初期設定
FIdTelnet := TIdTelnet.Create(AOwner);
with FIdTelnet do begin
Port := FPort;
OnDataAvailable := IdTelnetDataAvailable;
end;
FLogList := TStringList.Create;
end;
destructor TIRemocon.Destroy;
begin
inherited;
FIdTelnet.Free;
FLogList.Free;
end;
procedure TIRemocon.IdTelnetDataAvailable(Sender: TIdTelnet;
const Buffer: String);
function IsCRLF2(s: string): Boolean;
var i, n: Integer;
begin
n := 0;
for i := 1 to Length(s)-1 do begin
if (s[i] + s[i+1]) = #13#10 then begin
Inc(n);
end;
end;
Result := n = 2;
end;
var crlfPos: Integer;
begin
TmpLastReturnCommand := TmpLastReturnCommand + Buffer;
crlfPos := Pos(#13#10, TmpLastReturnCommand);
if crlfPos > 0 then begin
//学習を中止した時用の処理
//返信コマンド→cc;ok#13#10ic;err;002#13#10
if Pos('cc;ok', TmpLastReturnCommand) > 0 then begin
//2つめの#13#10が出た時点で取得終了するようにする
if (Pos(#13#10, Copy(TmpLastReturnCommand,
crlfPos+1, Length(TmpLastReturnCommand))) > 0) and
IsCRLF2(TmpLastReturnCommand) then begin
IsReturnFinished := True;
end;
end else begin
//それ以外は最初の#13#10が出たときに取得終了
IsReturnFinished := True;
end;
end;
end;
function TIRemocon.KeepAlive: Boolean;
begin
Result := SendCommand('au');
end;
function TIRemocon.TransmitInfrared(RemoconNo: Word): Boolean;
begin
Result := False;
if IsRemoconNoValid(RemoconNo) then
Result := SendCommand('is;' + IntToStr(RemoconNo));
end;
function TIRemocon.StartLearning(RemoconNo: Word): Boolean;
begin
Result := False;
if IsRemoconNoValid(RemoconNo) then begin
Result := SendCommand('ic;' + IntToStr(RemoconNo));
IsLearning := False;
end;
end;
function TIRemocon.StopLearning: Boolean;
begin
if IsLearning then begin
Result := SendCommand('cc');
end else begin
raise Exception.Create('リモコンコード学習モード以外の状態に対して実行しました。');
end;
end;
function TIRemocon.SetDateTime(ADateTime: TDateTime): Boolean;
begin
Result := SendCommand('ts;' + IntToStr(DateTimeToUnix(ADateTime) - UTC0900));
end;
function TIRemocon.GetDateTime(var ADateTime: TDateTime): Boolean;
var s: string;
begin
Result := SendCommand('tg');
if Result then begin
s := Trim(StringReplace(FLastReturnCommand, 'tg;ok;', '', []));
ADateTime := UnixToDateTime(StrToIntDef(s, 0) + UTC0900);
end else begin
ADateTime := UnixToDateTime(UTC0900);
end;
end;
function TIRemocon.SetTimer(RemoconNo: Word; ADateTime: TDateTime;
RepeatSec: Cardinal): Boolean;
begin
Result := False;
if not ((RepeatSec = 0) or ((RepeatSec >= 60) and (RepeatSec <= 31536000))) then begin
raise Exception.Create('繰り返し秒数は、0もしくは60~31536000にしてください。');
end;
if IsRemoconNoValid(RemoconNo) then
Result := SendCommand('tm;' + IntToStr(RemoconNo) + ';' +
IntToStr(DateTimeToUnix(ADateTime) - UTC0900) + ';' + IntToStr(RepeatSec));
end;
function TIRemocon.GetTimers(var Timers: TTimerArray): Boolean;
function NextValue(s: string): string;
begin
//;までを削除
Result := StringReplace(s, Copy(s, 1, Pos(';', s)), '', []);
end;
var s: string; n, i: Integer;
begin
Result := SendCommand('tl'); {}
if Result then begin
//返信コマンド例 tl;ok;2;1;3;1334692382;0;2;6;1335642637;604800
s := FLastReturnCommand + ';';
s := StringReplace(s, 'tl;ok;', '', []); //tl;ok;1;を削除
n := StrToIntDef(Copy(s, 1, Pos(';', s)-1), 0); //タイマー登録数を取得
if n = 0 then Exit;
SetLength(Timers, n);
s := NextValue(s); //回数を削除
for i := 0 to n-1 do begin
Timers[i].No := StrToIntDef(Copy(s, 1, Pos(';', s)-1), -1); //タイマーNoを取得
if Timers[i].No = -1 then Exit;
s := NextValue(s); //タイマーNoを削除
Timers[i].RemoconNo := StrToIntDef(Copy(s, 1, Pos(';', s)-1), -1); //リモコンNoを取得
if Timers[i].RemoconNo = -1 then Exit;
s := NextValue(s); //リモコンNoを削除
Timers[i].DateTime := //予約時間を取得
UnixToDateTime(StrToIntDef(Copy(s, 1, Pos(';', s)-1), -1) + UTC0900);
s := NextValue(s); //予約時間を削除
Timers[i].RepeatSec := StrToIntDef(Copy(s, 1, Pos(';', s)-1), -1); //繰り返し秒数を取得
s := NextValue(s); //繰り返し秒数を削除
end;
end;
end;
function TIRemocon.CancelTimer(TimerNo: Word): Boolean;
begin
if (TimerNo >= 1) and (TimerNo <= 1500) then begin
Result := SendCommand('td;' + IntToStr(TimerNo));
end else begin
raise Exception.Create('タイマー番号が1~500の範囲外です。');
Result := False;
end;
end;
function TIRemocon.GetVersion(var Version: string): Boolean;
begin
Result := SendCommand('vr');
if Result then
Version := FLastReturnCommand
else
Version := '';
end;
function TIRemocon.SendCommand(Command: string): Boolean;
var i: Integer; s, cmd, sendcmd, lrc: string; startms: Cardinal;
begin
//開始時間
startms := GetTickCount;
//メンバーの初期化
FLastReturnCommand := '';
TmpLastReturnCommand := '';
FLastErrorCode := '';
FLastErrorMessage := '';
FIsLastCommandError := False;
IsReturnFinished := False;
cmd := Copy(Command, 1, 2); //コマンド先頭2文字 ex. au, ic, cc
//学習中はccコマンド以外受け付けない
if IsLearning and (cmd <> 'cc') then begin
raise Exception.Create('リモコン学習開始コマンドが終了していません。');
Exit;
end;
//接続
if not FIdTelnet.Connected then FIdTelnet.Connect;
try
if FIdTelnet.Connected then begin
s := '*' + Command + #13#10;
//コマンドの改行が必要か否か
sendcmd := s;
if not FNecessaryCRLF then
sendcmd := Trim(sendcmd);
//コマンド送信前イベント
if Assigned(FOnSend) then
FOnSend(Self, sendcmd);
for i := 1 to Length(s) do
FIdTelnet.SendCh(s[i]);
FLogList.Add('*' + Command);
if cmd = 'ic' then
IsLearning := True;
end;
finally
//コマンド応答が終わるまで待機
while not IsReturnFinished do begin
Application.ProcessMessages;
Sleep(10);
//学習タイムアウト時間を超えたら学習キャンセル
if IsLearning and ((GetTickCount-startms) > FLearningTimeout) then begin
StopLearning;
end;
//学習時以外は5秒でループを抜ける
if not IsLearning and ((GetTickCount-startms) > 5000) then begin
Break;
end;
end;
lrc := TmpLastReturnCommand;
// DOut(lrc);
Result := not (Pos(cmd + ';err;', lrc) > 0); //コマンド成功か
if Result then begin
//文字列先頭から改行まで
FLastReturnCommand := Copy(lrc, 1, Pos(#13#10, lrc)+1);
// lrc := StringReplace(lrc, 'cc;ok'#13#10, '', []);
// DOut(TmpLastReturnCommand);
// DOut('1' + FLastReturnCommand);
//コマンドの改行が必要か否か
if not FNecessaryCRLF then
FLastReturnCommand := Trim(FLastReturnCommand);
//コマンド送信後イベント
if Assigned(FOnSent) then
FOnSent(Self, FLastReturnCommand);
end else begin
// //文字列の送信コマンド先頭から文末まで
// if Pos('cc;ok', lrc) > 0 then begin
// lrc := StringReplace(lrc, 'cc;ok'#13#10, '', []);
// end;
FLastReturnCommand := Copy(lrc, Pos(cmd, lrc), Length(lrc));
FIsLastCommandError := True;
SetErrors(lrc);
// DOut('2' + FLastReturnCommand);
//コマンドの改行が必要か否か
if not FNecessaryCRLF then
FLastReturnCommand := Trim(FLastReturnCommand);
//コマンド送信後イベント
if Assigned(FOnSent) then
FOnSent(Self, FLastReturnCommand);
if Assigned(FOnCustomError) then
FOnCustomError(Self, FLastErrorCode, FLastErrorTitle, FLastErrorMessage);
end;
//コマンド送信後イベント
// if Assigned(FOnSent) then begin
// FOnSent(Self, FLastReturnCommand);
// end;
//オンタイマー、音声切り替え
FLogList.Add(FLastReturnCommand);
Sleep(FInterval); //連射防止のインターバル
//切断
if FIdTelnet.Connected then
FIdTelnet.Disconnect;
end;
end;
procedure TIRemocon.SetErrors(const ReturnCommand: string);
var s, errCode: string;
begin
s := ReturnCommand;
errCode := Copy(s, Pos(#13#10, s)-3, 3);
if errCode = '010' then begin
FLastErrorTitle := 'フォーマットエラー';
FLastErrorMessage := 'コマンドの書式が不正です。';
FLastErrorCode := 'XX' + errCode;
end else if errCode = '020' then begin
FLastErrorTitle := 'タイムアウトエラー';
FLastErrorMessage := 'コマンド入力が5秒以上途切れました。';
FLastErrorCode := 'XX' + errCode;
end else if errCode = '051' then begin
FLastErrorTitle := '内部システムタイムアウトエラー';
FLastErrorMessage := '内部のシステムタイムアウトエラー 。';
FLastErrorCode := 'XX' + errCode;
end else if errCode = '052' then begin
FLastErrorTitle := '内部システム応答データなしエラー';
FLastErrorMessage := '内部システムに応答するデータがありません。';
FLastErrorCode := 'XX' + errCode;
end else if errCode = '053' then begin
FLastErrorTitle := '内部システム応答データ不正エラー';
FLastErrorMessage := '内部システムの応答データが不正です。';
FLastErrorCode := 'XX' + errCode;
end else begin
if Pos('is;', s) > 0 then begin
FLastErrorTitle := '';
FLastErrorMessage := '';
FLastErrorCode := 'IS' + errCode;
if errCode = '001' then begin
FLastErrorTitle := 'リモコン番号範囲外';
FLastErrorMessage := 'リモコン番号が1~1500の範囲外です。';
end else if errCode = '002' then begin
FLastErrorTitle := 'リモコンデータ未登録エラー';
FLastErrorMessage := 'リモコンデータが記録されていない番号が指定されました。';
end else if errCode = '003' then begin
FLastErrorTitle := '送信エラー ';
FLastErrorMessage := '不正なデータを送信しようとしました。';
end;
end else if Pos('ic;', s) > 0 then begin
FLastErrorCode := 'IC' + errCode;
if errCode = '001' then begin
FLastErrorTitle := 'リモコン番号範囲外';
FLastErrorMessage := 'リモコン番号が1~1500の範囲外です。';
end else if errCode = '002' then begin
FLastErrorTitle := '学習キャンセル';
FLastErrorMessage := 'リモコン学習はコマンドによってキャンセルされました。';
end else if errCode = '003' then begin
FLastErrorTitle := '受信エラー';
FLastErrorMessage := '不正なリモコンデータを受信しました。';
end else if errCode = '004' then begin
FLastErrorTitle := 'リモコンデータ件数エラー';
FLastErrorMessage := '登録可能なリモコンデータの最大件数を超えて登録しようとしています。';
end else if errCode = '005' then begin
FLastErrorTitle := '二重操作エラー';
FLastErrorMessage := '既にic/ibで受信待ちの状態です。';
end;
end else if Pos('cc;', s) > 0 then begin
FLastErrorCode := 'CC' + errCode;
if errCode = '001' then begin
FLastErrorTitle := '実行エラー';
FLastErrorMessage := 'リモコンコード学習モード以外の状態に対して実行しました。';
end;
end else if Pos('tm;', s) > 0 then begin
FLastErrorCode := 'TM' + errCode;
if errCode = '001' then begin
FLastErrorTitle := 'リモコン番号範囲外';
FLastErrorMessage := 'リモコン番号が1~1500の範囲外です。';
end else if errCode = '002' then begin
FLastErrorTitle := '実行時間範囲外エラー';
FLastErrorMessage := '現在時刻+1~4102444800の範囲外です。';
end else if errCode = '003' then begin
FLastErrorTitle := '繰り返し時間範囲外エラー';
FLastErrorMessage := '0~31536000以外の範囲が指定されました。';
end else if errCode = '004' then begin
FLastErrorTitle := '2重登録エラー(同一時間あり)';
FLastErrorMessage := '既に同一の時間にタイマー登録されています。';
end else if errCode = '005' then begin
FLastErrorTitle := '登録数オーバーエラー';
FLastErrorMessage := '登録数オーバー(最大500件)です。';
end else if errCode = '006' then begin
FLastErrorTitle := 'リモコンデータエラー';
FLastErrorMessage := 'リモコンデータが登録されていない番号が指定されました。';
end else if errCode = '007' then begin
FLastErrorTitle := '曜日指定エラー';
FLastErrorMessage := '曜日指定のフォーマットが不正です。';
end;
end else if Pos('tl;', s) > 0 then begin
FLastErrorCode := 'TL' + errCode;
if errCode = '001' then begin
FLastErrorTitle := 'タイマー登録なし';
FLastErrorMessage := 'タイマーが1件も登録されていません。';
end;
end else if Pos('td;', s) > 0 then begin
FLastErrorCode := 'TD' + errCode;
if errCode = '001' then begin
FLastErrorTitle := 'タイマー番号範囲外エラー';
FLastErrorMessage := '1~500の範囲外です。';
end else if errCode = '002' then begin
FLastErrorTitle := 'タイマー登録なし';
FLastErrorMessage := '指定したタイマー番号のタイマーが存在しません。';
end;
end else if Pos('ts;', s) > 0 then begin
FLastErrorCode := 'TS' + errCode;
if errCode = '001' then begin
FLastErrorTitle := '設定時間範囲外';
FLastErrorMessage := '1293775200~4102444800の範囲外です。';
end;
end else if Pos('li;', s) > 0 then begin
FLastErrorCode := 'LI' + errCode;
if errCode = '001' then begin
FLastErrorTitle := 'センサーの値が不正';
FLastErrorMessage := 'センサーの値が不正です。';
end;
end else if Pos('hu;', s) > 0 then begin
FLastErrorCode := 'HU' + errCode;
if errCode = '001' then begin
FLastErrorTitle := 'センサーの値が不正';
FLastErrorMessage := 'センサーの値が不正です。';
end;
end else if Pos('te;', s) > 0 then begin
FLastErrorCode := 'TE' + errCode;
if errCode = '001' then begin
FLastErrorTitle := 'センサーの値が不正';
FLastErrorMessage := 'センサーの値が不正です。';
end;
end else if Pos('se;', s) > 0 then begin
FLastErrorCode := 'SE' + errCode;
if errCode = '001' then begin
FLastErrorTitle := 'センサーの値が不正';
FLastErrorMessage := 'センサーの値が不正です。';
end;
end;
end;
end;
function TIRemocon.IsRemoconNoValid(RemoconNo: Word): Boolean;
begin
if (RemoconNo >= 1) and (RemoconNo <= 1500) then
Result := True
else begin
raise Exception.Create('リモコン番号が1 - 1500の範囲外です。');
Result := False;
end;
end;
procedure TIRemocon.SetLearningTimeout(const Value: Cardinal);
begin
FLearningTimeout := Value;
if Value < 3000 then begin
FLearningTimeout := 3000;
raise Exception.Create('3000ms(3秒)以上に設定してください。');
end else if Value > (1000*60) then begin
raise Exception.Create('60000ms(1分)以下に設定してください。');
FLearningTimeout := 1000*60;
end;
end;
procedure TIRemocon.SetInterval(const Value: Word);
begin
FInterval := Value;
if Value < 100 then begin
FInterval := 100;
raise Exception.Create('100ms(0.1秒)以上に設定してください。');
end else if Value > 2000 then begin
FInterval := 2000;
raise Exception.Create('2000ms(2秒)以下に設定してください。');
end;
end;
procedure TIRemocon.SetOnSend(const Value: TSendEvent);
begin
FOnSend := Value;
end;
procedure TIRemocon.SetOnSent(const Value: TSentEvent);
begin
FOnSent := Value;
end;
procedure TIRemocon.SetHost(const Value: string);
begin
FHost := Value;
FIdTelnet.Host := Value;
end;
procedure TIRemocon.SetOnCustomError(const Value: TCustomErrorEvent);
begin
FOnCustomError := Value;
end;
procedure TIRemocon.SetNecessaryCRLF(const Value: Boolean);
begin
FNecessaryCRLF := Value;
end;
function TIRemocon.GetIlluminance(var Illuminance:Single): Boolean;
begin
Result := SendCommand('li');
if Result then
Illuminance := StrToFloatDef(StringReplace(FLastReturnCommand, 'li;ok;', '', []), -1)
else
Illuminance := -1;
end;
function TIRemocon.GetHumidity(var Humidity: Single): Boolean;
begin
Result := SendCommand('hu');
if Result then
Humidity := StrToFloatDef(StringReplace(FLastReturnCommand, 'hu;ok;', '', []), -1)
else
Humidity := -1;
end;
function TIRemocon.GetTemperature(var Temperature: Single): Boolean;
begin
Result := SendCommand('te');
if Result then
Temperature := StrToFloatDef(StringReplace(FLastReturnCommand, 'te;ok;', '', []), -1000)
else
Temperature := -1000;
end;
function TIRemocon.GetSensors(var Illuminance, Humidity,
Temperature: Single): Boolean;
var s:String;
sl:TStringList;
begin
Result := SendCommand('se');
if Result then begin
sl := TStringList.Create;
try
s := StringReplace(FLastReturnCommand, 'se;ok;', '', []);
s := StringReplace(s, ';', ',', [rfReplaceAll]);
sl.CommaText := s;
Illuminance := StrToFloatDef(sl[0], -1);
Humidity := StrToFloatDef(sl[1], -1);
Temperature := StrToFloatDef(sl[2], -1000);
finally
sl.Free;
end;
end else begin
Illuminance := -1;
Humidity := -1;
Temperature := -1000;
end;
end;
end.
あと、当然ながらこのアプリを利用するには、iRemocon Wi-Fiが必要です。
アプリの使い方
Windowsから、アプリを利用するには、実行ファイルを起動して、以下の部分にiRemocon Wi-FiのローからIPアドレスを入力します。

WindowsでのIP取得方法は、以下を参照してください。
IPを入力したら、あとは、以下のコマンドボタンで操作をします。

個々のコマンドについては、以下に書いてあるコマンドの使い方を参照してください。
すると、こんな感じで、簡易的ではありますが、GUIからiRemocon Wi-Fiを操作出来るようになります。

こんな感じで、コマンドと実行結果が表示されます。
これを応用すれば、iRemocon Wi-Fiを利用して、自分好みのリモコンアプリなどを作ることができます。
とりあえず、こういったものの機能を強化したものが以下の、Windows用、iRemoconリモコンアプリになります。

こちらは、iRemocon Wi-Fiのセンサー機能はまだ取り込んでないですが、ローカルIPさえ取得できれば、iRemocon Wi-Fiを操作することができます。
まとめ
このように、iRemocon Wi-Fiはアプリからでも操作できます。
僕は、Windowsのデスクトップアプリ用の言語は、Delphiしかまともに書けないので、マイナーな言語で申しわけないのですが、何かの参考になれば幸いです。
そして、他人まかせで申し訳ないですけど、誰かがもっと良いアプリを作ってくれて、より快適な生活が送れれば最高です。
最近、PHPや、Rubyのような、軽量プログラミング言語に慣れてしまったら、手間がかかるし面倒くさいデスクトップアプリで、新たに何か作る気が起きない…。

