CINXE.COM

市販の節電モニターから値を読みだしてグラフ化 | tech - 氾濫原

<!DOCTYPE html> <html lang="ja" data-auth="" data-permalink="1" itemscope itemtype="http://schema.org/BlogPosting" > <head> <meta charset="utf-8"> <title>市販の節電モニターから値を読みだしてグラフ化 | tech - 氾濫原</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=yes"> <meta name="theme-color" content="#000000"> <!-- link rel="shortcut icon" href="/images/favicon.ico" type="image/x-icon"/ --> <link rel="alternate" type="application/atom+xml" title="Feed" href="/feed"> <link rel="canonical" href="https://lowreal.net/2016/01/18/2"> <meta name="referrer" content="unsafe-url"> <meta property="og:title" content="市販の節電モニターから値を読みだしてグラフ化 | tech - 氾濫原"> <meta property="og:type" content="article"> <meta property="og:url" content="https://lowreal.net/2016/01/18/2"> <meta property="og:image" content="/images/entry/2016-01-18"> <meta property="og:email" content="cho45@lowreal.net" > <meta property="fb:admins" content="cho45" > <meta name="twitter:card" content="summary"> <meta name="twitter:url" content="https://lowreal.net/2016/01/18/2"> <meta name="twitter:title" content="氾濫原"> <meta name="twitter:description" content=" &lt;span itemscope itemtype=&quot;http://schema.org/Photograph&quot;&gt; &lt;a href=&quot;https://picasaweb.google.com/114431815111528304586/January182016#6240950…"> <meta name="twitter:image" content="/images/entry/2016-01-18"> <meta name="twitter:site" content="cho45"> <meta name="twitter:creator" content="cho45"> <link rel="stylesheet" href="/css/style.css"> <link rel="stylesheet" href="/css/github.css"> <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;700&display=swap" rel="stylesheet"> <link rel="preload" href="/api/similar?id=20559&" id="preload-similar-entries" as="fetch" crossorigin> <link rel="preload" href="/api/exif?id=20559&" id="preload-exif-entries" as="fetch" crossorigin> <!-- htmlmin:ignore --> <!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:foaf="http://xmlns.com/foaf/0.1/"> <rdf:Description rdf:about="https://lowreal.net/2016/01/18/2"> <foaf:maker rdf:parseType="Resource"> <foaf:holdsAccount> <foaf:OnlineAccount foaf:accountName="cho45"> <foaf:accountServiceHomepage rdf:resource="http://www.hatena.ne.jp/"/> </foaf:OnlineAccount> </foaf:holdsAccount> </foaf:maker> </rdf:Description> </rdf:RDF> --> <!-- htmlmin:ignore --> <!--[if lt IE 9]> <script src="https://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <script src="/js/daterelative.js" defer></script> <script src="/js/balancetext/tinysegmenter.js" defer></script> <script src="/js/balancetext/balance.js" defer></script> <script src="/js/abcjs_basic_5.1.1-min.js" defer></script> <script src="/js/nogag.js" defer></script> <!-- mathjax: false --> </head> <body> <header id="global-header"> <h1 id="header"> <a href="/"> <img src="/images/hanrangen.svg" width="60" height="50" style="margin: auto; display: block" alt="市販の節電モニターから値を読みだしてグラフ化 | tech - 氾濫原"> </a> </h1> </header> <nav id="global-navigation"> <ul> <li><a href="/">最新</a></li> <li><a href="/photo/">写真</a></li> <li><a href="https://www.lowreal.net/">誰?</a></li> </ul> </nav> <div id="content"> <div class="entries"> <div class="date"><a href="/2016/01/18/">2016年 01月 18日</a></div> <article id="post-1453084511" class="tech status-public" data-id="20559" > <header> <h2 itemprop="name"><a href="/2016/01/18/2" class="bookmark" rel="bookmark" itemprop="url">市販の節電モニターから値を読みだしてグラフ化</a></h2> <div class="metadata"> <a href="/tech/"><span itemprop="keywords">tech</span></a> | <time data-epoch="1453084511" datetime="2016-01-18T02:35:11Z" itemprop="datePublished"> 11:35 </time> | <div style="display: none"> <meta itemscope itemprop="mainEntityOfPage" itemType="https://schema.org/WebPage" content="/2016/01/18/2"> <span itemprop="headline">グラフ化した消費電力値。5:00 ぐらいにエアコンの電源が自動的に入るようになっていて急激に消費電力が増…</span> <span itemprop="author" itemscope itemtype="https://schema.org/Person"> <a href="http://www.lowreal.net/" itemprop="url"> <span itemprop="name">cho45</span> </a> </span> <div itemprop="publisher" itemscope itemtype="https://schema.org/Organization"> <div itemprop="logo" itemscope itemtype="https://schema.org/ImageObject"> <meta itemprop="url" content="https://www.lowreal.net/images/logo.png"> <meta itemprop="width" content="189"> <meta itemprop="height" content="105"> </div> <meta itemprop="name" content="cho45"> </div> <meta itemprop="datePublished" content="2016-01-18T02:35:11Z"> <meta itemprop="dateModified" content="2020-07-29T09:53:00Z"> <div itemprop="image" itemscope itemtype="https://schema.org/ImageObject"> <meta itemprop="url" content="/images/entry/2016-01-18"> <meta itemprop="width" content="800"> <meta itemprop="height" content="800"> </div> </div> </div> </header> <div class="content" itemprop="articleBody"> <p> <span itemscope itemtype=http://schema.org/Photograph> <a href=https://picasaweb.google.com/114431815111528304586/January182016#6240950407457589906 itemprop=url class=picasa><img alt=photo itemprop=image src="/images/entry/2016-01-18 08.54.27.png"></a> </span> <p>グラフ化した消費電力値。5:00 ぐらいにエアコンの電源が自動的に入るようになっていて急激に消費電力が増える。起床後は食洗機や洗濯乾燥機などが稼動してさらに増えていく。40A契約だが、一瞬ピークでそこまでいってる (これは原因不明)</p> <section class=level-1> <h3>節電モニター</h3> <p> </p> <figure class=amazon itemscope itemtype=http://schema.org/Review> <div class=image> <a href="https://www.amazon.co.jp/dp/B006CLL45Q?tag=nuso-22&linkCode=ogi&th=1&psc=1"><img alt="節電モニター - はやわかり" itemprop=image src=https://m.media-amazon.com/images/I/51Pt+gi9KUL._SL500_.jpg height=500 width=500></a> </div> <figcaption class=detail> <p class=title itemprop=itemReviewed itemscope itemtype=http://schema.org/Product> <a href="https://www.amazon.co.jp/dp/B006CLL45Q?tag=nuso-22&linkCode=ogi&th=1&psc=1" itemprop=url><span itemprop=name>節電モニター</span></a> <span itemprop=review itemscope itemtype=http://schema.org/Review> <span itemprop=author itemscope itemtype=https://schema.org/Person> <span itemprop=name>cho45</span> </span> </span> </p> <p class=author>はやわかり</p> <div class=rating data-rating=5.0 itemprop=reviewRating itemscope itemtype=http://schema.org/Rating> ★ <meta content=1.0 itemprop=worstRating> <span itemprop=ratingValue>5.0</span> / <span itemprop=bestRating>5.0</span> </div> <span itemprop=author itemscope itemtype=https://schema.org/Person style=display:none> <a href=http://www.lowreal.net/ itemprop=url> <span itemprop=name>cho45</span> </a> </span> </figcaption> </figure> <p> <p>(国内だと節電モニター「はやわかり」という商品名のもの)<p><a href=http://lowreal.net/2013/04/19/2>500 Can't connect to lowreal.net:443 (certificate verify failed)</a> のとき買って、設置をしてはいたものの、十分に活用していたとはいえない状態でした。電気使いすぎのときにアラートを鳴らしていて、ブレーカーが落ちる1歩手前で気付けるというのが現状では最大の活用でした。<p>しかし、せっかく USB 端子があってデータが読み出せるのだから、自動的にグラフ化したくなってきました。ちなみにこの製品には Windows 版のかなりデキの悪いソフトウェアが付属していますが、正直常用できるようなものではありません。</p> </section> <section class=level-1> <h3>製品の詳細を調べる</h3> <p>この製品はどうやら、以下のものと同一のようです。</p> <ul> <li><a href=http://www.theowl.com/energy-monitors/standalone-monitors/owl-usb/ >http://www.theowl.com/energy-monitors/standalone-monitors/owl-usb/</a></li> </ul><p>USB 接続してシステムプロファイラでベンダIDなどを調べて検索すると、<a href=http://jp.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx>Silicon Labs の USB シリアル変換のチップ</a>のようでした。</p><br> <p>実際プロトコルダンプして読みだしたりしている人がいます。</p> <ul> <li><a href=http://www.meintechblog.de/2013/10/smart-metering-mit-owl-usb-und-fhem-live-tracking-des-stromverbrauchs/ >http://www.meintechblog.de/2013/10/smart-metering-mit-owl-usb-und-fhem-live-tracking-des-stromverbrauchs/</a> <ul> <li>Perl のコードがある</li> </ul></li> <li><a href=http://sourceforge.net/projects/electricowl/ >http://sourceforge.net/projects/electricowl/</a> <ul> <li>Python のコードがある (Perl とほぼ同じコードだけど、こっちが先っぽい?)</li> </ul></li> <li><a href=http://douglass.customer.netspace.net.au/comms.html>http://douglass.customer.netspace.net.au/comms.html</a> <ul> <li>スニファ結果</li> </ul></li> </ul><p>思ったより情報があったので簡単そうです。</p> </section> <section class=level-1> <h3>Raspberry Pi で読みだす</h3> <p>ドライバの対応の関係上、Linux で読み出すのが一番簡単です。通常のドライバだと製品IDが登録されていないのですが、Linux の場合はこの製品のIDについても対応するドライバを使うようになっているので、特に苦労せずにシリアル通信ができます。<p>Raspberry Pi の場合、CP210x のドライバは最初から入っているようなので、特にインストールすることもなく、USB ケーブルを繋ぐだけでシリアルポートとして認識します。</p> </section> <section class=level-1> <h3>シリアルフォーマット</h3> <p>ボーレート 250000 8bit stopbit 1 parity 0 となっており、ボーレートが特殊なので、場合によって工夫が必要です。<p>Ruby を使って読みだすことにしましたが、これのせいで<a href=http://lowreal.net/2016/01/17/1>自力で ioctl を呼ぶハメ</a>になっています。</p> </section> <section class=level-1> <h3>データ形式</h3> <p>送られてくるのは常に、11バイト固定長で、こちらから送るのは \xA5 か \x5A だけです。解析結果のコードがあるので、その通り実装したらいいだけです。<p>ただ、フローコントロールをオフにせずに試していたところ、デフォルトだとソフトウェアフローコントロールが有効なようですが、データ欠けが発生して微妙に読みだせず4〜5時間ハマりました。どうやら必ずフローコントロールは完全にオフにする必要があるようです (ハードウェアフローコントロールだとデータ欠けは発生しないが、そもそも応答しなくなりました)</p> </section> <section class=level-1> <h3>コード</h3> <p>という感じのを Ruby で実装しました。といっても、プロトコル解析はされているし、 Python 実装もあったのでたいしたコードにはなっていません。<p><a href=https://github.com/cho45/CM160-rb>https://github.com/cho45/CM160-rb</a><p>とにかくフローコントロールが最大のハマリどころでした。</p> </section> <section class=level-1> <h3>備考</h3> <p>この製品は 315MHz帯の微弱電波機器 (免許・技適不要) となっていて、かなり電波が弱いです。うちはかなり狭い家(マンション)で、玄関上にある分電盤からリビングまで、10mもないと思いますが、これで電波がぎりぎり届きません。<p>なので、機器同士は比較的近くにおくようにして、Raspberry Pi などでネットに中継するほうが安定して便利そうです。広い家だとむしろ中継が必須な気がします。<p>とはいえ、そろそろスマートメータの設置もすすむので、こういうのも必要なくなるのかもしれません。</p> </section> <ol itemscope itemtype="http://schema.org/BreadcrumbList" ><li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem" ><a itemprop="item" href="/"><span itemprop="name">トップ</span></a> <meta itemprop="position" content="1"> </li> <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"> <a itemprop="item" href="/tech/"><span itemprop="name">tech</span></a> <meta itemprop="position" content="2"> </li> <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"> <a itemprop="item" href="https://lowreal.net/2016/01/18/2"><span itemprop="name">市販の節電モニターから値を読みだしてグラフ化</span></a> <meta itemprop="position" content="3"> </li> </ol> </div> <div class="content trackbacks"> <h3>このエントリを参照するエントリ</h3> <ul> <li data-id="20560"> <a href="/2016/01/18/3"> <b>コンセントごとの消費電力を知りたい人生</b><br> <span class="summary">分電盤にセンサーをつけて家庭内全体の消費電力を測るというのはやっていますが、実際のところ何がどう電力を食っているのは大本で計測してもわかり…</span> <time data-epoch="1453101095" datetime="2016-01-18T07:11:35Z" itemprop="datePublished"> 16:11 </time> </a> </li> </ul> <ul> <li data-id="20988"> <a href="/2016/12/31/1"> <b>今年やったことを自分で承認する</b><br> <span class="summary">日記を読みかえしてみたら今年もいろいろやっていた。年末にせめて自分で自分を承認してあげたい。おおまかには 高周波関係 アンテナアナライザ製作…</span> <time data-epoch="1483110272" datetime="2016-12-30T15:04:32Z" itemprop="datePublished"> 00:04 </time> </a> </li> </ul> </div> <div class="content similar-entries"> </div> <div class="social"> <span class="hatena-star"></span> <p class="share-buttons"> <a class="share-button" style="background: #3b5998" target="_blank" rel="noopener nofollow" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Flowreal.net%2F2016%2F01%2F18%2F2" onclick="ga('send', 'social', 'Facebook', 'Share', 'https://lowreal.net/2016/01/18/2')" > <img src="/images/sharebuttons/FB-f-Logo__white_50.png" width="18" height="18" alt="Facebook"> </a> <a class="share-button" style="background: #55acee" target="_blank" rel="noopener nofollow" href="https://twitter.com/intent/tweet?url=https%3A%2F%2Flowreal.net%2F2016%2F01%2F18%2F2&amp;text=%E5%B8%82%E8%B2%A9%E3%81%AE%E7%AF%80%E9%9B%BB%E3%83%A2%E3%83%8B%E3%82%BF%E3%83%BC%E3%81%8B%E3%82%89%E5%80%A4%E3%82%92%E8%AA%AD%E3%81%BF%E3%81%A0%E3%81%97%E3%81%A6%E3%82%B0%E3%83%A9%E3%83%95%E5%8C%96" onclick="ga('send', 'social', 'Twitter', 'Share', 'https://lowreal.net/2016/01/18/2')" > <img src="/images/sharebuttons/Twitter_logo_white_48.png" width="24" height="24" alt="Twitter"> </a> <!-- a class="share-button" style="box-shadow: none" target="_blank" rel="noopener nofollow" href="https://plus.google.com/share?url=https%3A%2F%2Flowreal.net%2F2016%2F01%2F18%2F2" onclick="ga('send', 'social', 'Google', 'Share', 'https://lowreal.net/2016/01/18/2')" > <img src="/images/sharebuttons/g+138.png" width="45" height="45" alt="Share on Google+"> </a --> <a class="share-button" style="" target="_blank" rel="noopener nofollow" href="http://line.me/R/msg/text/?%E5%B8%82%E8%B2%A9%E3%81%AE%E7%AF%80%E9%9B%BB%E3%83%A2%E3%83%8B%E3%82%BF%E3%83%BC%E3%81%8B%E3%82%89%E5%80%A4%E3%82%92%E8%AA%AD%E3%81%BF%E3%81%A0%E3%81%97%E3%81%A6%E3%82%B0%E3%83%A9%E3%83%95%E5%8C%96%5Cnhttps%3A%2F%2Flowreal.net%2F2016%2F01%2F18%2F2" onclick="ga('send', 'social', 'LINE', 'Share', 'https://lowreal.net/2016/01/18/2')" > <img src="/images/sharebuttons/linebutton_40x40_en.png" width="40" height="40" alt="LINE it!"> </a> <a class="share-button" style="background: #00a4de" target="_blank" rel="noopener nofollow" href="http://b.hatena.ne.jp/add?url=https%3A%2F%2Flowreal.net%2F2016%2F01%2F18%2F2" onclick="ga('send', 'social', 'Hatena::Bookmark', 'Share', 'https://lowreal.net/2016/01/18/2')" > <img src="/images/sharebuttons/hatenabookmark-logomark.svg" width="40" height="40" alt="はてなブックマーク"> </a> </p> </div> </article> </div> <div class="pager"> <a href="/2016/01/18/1" rel="next">&#x25C0; [tech] Ruby …</a> <a href="/2016/01/18/">&#x25B2; この日のエントリ</a> <a href="/2016/01/18/3" rel="prev">[tech] コンセ… &#x25B6;</a> </div> </div> <footer id="global-footer"> <h2>書いている人</h2> <div class="author"> <div class="image"> <img src="/images/profile.jpg" alt="Photo" width="160" height="160"> </div> <div class="desc"> <p> cho45 (<a href="https://www.lowreal.net/" rel="author">www.lowreal.net</a>) &lt;<a href="mailto:cho45@lowreal.net">cho45@lowreal.net</a>&gt; </p> <p> JavaScript, Perl, Ruby, HTML, CSS, Web etc </p> <p> <a class="button twitter-follow-button" href="https://twitter.com/intent/follow?&ref_src=twsrc%5Etfw&region=follow_link&screen_name=cho45&tw_p=followbutton" rel="nofollow" onclick="ga('send', 'social', 'Twitter', 'Follow', 'cho45')" ><i></i> <span class="label"> Follow <b>@cho45</b> </span> </a> <a class="button github-button" href="https://github.com/cho45" rel="nofollow" onclick="ga('send', 'social', 'GitHub', 'Follow', 'cho45')" ><i></i> <span class="label"> Follow <b>@cho45</b> </span> </a> <a class="google-plus-button" rel="me" href="https://plus.google.com/114431815111528304586?rel=author" onclick="ga('send', 'social', 'Google', 'Follow', 'cho45')" ><img src="//www.google.com/images/icons/ui/gprofile_button-16.png" width="16" height="16" alt="Google+"></a> </p> <p> <a href="/archive">アーカイブ</a> </p> </div> </div> </footer> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10