都内で働くSEの技術的なひとりごと / Technical soliloquy of System Engineer working in Tokyo

都内でサラリーマンやってます。SQL Server を中心とした (2023年からは Azure も。) マイクロソフト系(たまに、OSS系などマイクロソフト以外の技術も...)の技術的なことについて書いています。日々の仕事の中で、気になったことを技術要素関係なく気まぐれに選んでいるので記事内容は開発言語、インフラ等ばらばらです。なお、当ブログで発信、発言は私個人のものであり、所属する組織、企業、団体等とは何のかかわりもございません。ブログの内容もきちんと検証して使用してください。英語の勉強のため、英語の

I wrote a code to control Nature Remo in C# because I saw the article about Sony DSC-QX10 that I wrote in the past.

I bought Nature Remo mini on impulse.

Nature Remo mini 家電コントロ-ラ- REMO2W1

Nature Remo mini 家電コントロ-ラ- REMO2W1

 

 

Simple.

f:id:koogucc11:20190505202344j:plain

Nature Remo mini

 

Nature Remo is in simple box.

f:id:koogucc11:20190505202400j:plain

Simple Box

Nature Remo mini is a bit bigger than Airpods.

f:id:koogucc11:20190505202444j:plain

Nature Remo mini and AirPods

 

The cause of impulse buying is the following article. I wanted to control Nature Remo mini like Sony DSC-QX10.

ryuchan.hatenablog.com

 

I would like to operate Nature Remo mini with C # referring to the blog above and the Nature Remo API. Based on the following sources used in the operation of Sony DSC-QX10, I will change it to Nature Remo mini version.

static async void DoPost()
{
    string jsonparams = "{\"method\": \"actTakePicture\"," +
                        "\"params\": []," +
                        "\"id\": 1," +
                        "\"version\": \"1.0\"}";
string url = "http://10.0.0.1:10000/sony/camera"; var httpclient = new HttpClient(); var jsoncontent = new StringContent(jsonparams, Encoding.UTF8, "application/json"); httpclient.MaxResponseContentBufferSize = int.MaxValue; var response = await httpclient.PostAsync(url, jsoncontent); String text = await response.Content.ReadAsStringAsync(); }

 

It is a DVD deck to control. The remote controller is as shown below.

f:id:koogucc11:20190506082720j:plain

Remote Controller

 

In order to control the device, you need to get the device id. It can be obtained by sending a request to Nature Remo mini using the code below. Please get the access token here.

static async void DoGet()
{
    string token = "Bearer " + "{access token}";
    string url = "https://api.nature.global/1/appliances";
    var httpclient = new HttpClient();
    
    httpclient.DefaultRequestHeaders.Add("Authorization", token);

    var response = await httpclient.GetAsync(url);
}

 

Since you can get the device id, use that the device id to control the power of a DVD deck.

f:id:koogucc11:20190506084126p:plain

device id

The acquired id ( e1ac8815-1480-4914-bd77-a42c5037659b) is specified as follows, and the source is rewritten for POST request. A status code is returned in 200, it will succeed. I think It is able to write the code of the GET code and the POST code beautifully by using HttpRequestMessage and SendAsync.

static async void DoPost()
{
    string token = "Bearer " + "{access token}";
    string url = "https://api.nature.global/1/signals/e1ac8815-1480-4914-bd77-a42c5037659b/send";
    var httpclient = new HttpClient();
    var httpreqmsg = new HttpRequestMessage(HttpMethod.Post, url);

    httpreqmsg.Headers.Add("Authorization", token);

    var response = await httpclient.SendAsync(httpreqmsg);
}

 

Because I want to make the sample source code as simple as possible, I do not specify HEADER information and other necessary information neatly. For full-fledged use, please refer carefully to the Nature Remo API specification.

A programming of device is fun. I noticed after Nature Remo mini arrived at my house, but the second generation of Nature Remo has humidity, human feeling, and light sensor. I should have bought the second generation of Nature Remo!

Nature Remo 第2世代モデル 家電コントロ-ラ- REMO1W2

Nature Remo 第2世代モデル 家電コントロ-ラ- REMO1W2

 

It looks fun to control Philips Hue.