{"id":5342,"date":"2024-05-07T18:02:29","date_gmt":"2024-05-07T09:02:29","guid":{"rendered":"https:\/\/blog.bitmeister.jp\/?p=5342"},"modified":"2024-05-07T22:46:32","modified_gmt":"2024-05-07T13:46:32","slug":"how-to-use-momonga","status":"publish","type":"post","link":"https:\/\/blog.bitmeister.jp\/?p=5342","title":{"rendered":"How to Use Momonga"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/nbtk\/momonga\">Momonga<\/a>\u306fB\u30eb\u30fc\u30c8\u30b5\u30fc\u30d3\u30b9\u3092\u5229\u7528\u3057\u3066\u30b9\u30de\u30fc\u30c8\u30e1\u30fc\u30bf\u30fc\u3068\u901a\u4fe1\u3059\u308bPython\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u3059\u3002\u4eca\u65e5\u306f\u305d\u306e\u4f7f\u3044\u65b9\u3092\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<p><strong>0. \u96fb\u529b\u4f1a\u793e\u306bB\u30eb\u30fc\u30c8\u306e\u7533\u8acb<\/strong><br \/>\n\u514e\u306b\u3082\u89d2\u306b\u3082\u3001\u307e\u305aB\u30eb\u30fc\u30c8\u306eID\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5165\u624b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u6771\u4eac\u96fb\u529b\u3067\u306f\u81ea\u5b85\u306e\u30b9\u30de\u30fc\u30c8\u30e1\u30fc\u30bf\u30fc\u306a\u3089Web\u304b\u3089\u30d4\u30c3\u30d4\u3084\u308b\u3060\u3051\u3067\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p><strong>1. Wi-SUN\u30e2\u30b8\u30e5\u30fc\u30ebBP35C2\u3092\u8abf\u9054\u3059\u308b<\/strong><br \/>\n\u30e9\u30c8\u30c3\u30af\u30b7\u30b9\u30c6\u30e0\u306eUSB\u30c9\u30f3\u30b0\u30eb\u304cAmazon\u3067\u58f2\u3063\u3066\u307e\u3059\u3002USB\u30c9\u30f3\u30b0\u30eb\u3067\u3042\u308b\u5fc5\u8981\u306f\u7279\u306b\u306a\u3044\u306e\u3067UART\u3092\u4f7f\u3046\u30bf\u30a4\u30d7\u3067\u3082\u3088\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<p><strong>2. Raspberry Pi OS \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305fRPi\u306b\u30c9\u30f3\u30b0\u30eb\u3092\u633f\u3059<\/strong><br \/>\nRaspberry Pi\u3058\u3083\u306a\u304f\u3066\u3082\u30b7\u30ea\u30a2\u30eb\u901a\u4fe1\u3067\u304d\u308c\u3070\u306a\u3093\u3067\u3082\u3044\u3044\u3067\u3059\u3002Windows\u306f\u8a66\u3057\u3066\u306a\u3044\u3051\u3069\u52d5\u304f\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u3082\u3057\u52d5\u304b\u306a\u304b\u3063\u305f\u3089\u53c2\u8003\u307e\u3067\u306b\u6559\u3048\u3066\u4e0b\u3055\u3044\u3002<\/p>\n<p><strong>3. Momonga\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/strong><\/p>\n<pre class=\"brush: bash; gutter: false; title: ; notranslate\" title=\"\">\r\n$ pip install momonga\r\n<\/pre>\n<p><!--more--><br \/>\n\u3053\u3053\u3067\u3001\u30b7\u30ea\u30a2\u30eb\u30c7\u30d0\u30a4\u30b9\u304c\/dev\/ttyUSB0\u3068\u304b\u306b\u30de\u30a6\u30f3\u30c8\u3055\u308c\u3066\u308b\u3068\u601d\u3046\u306e\u3067\u3059\u304c\u3001\u3053\u306e\u30c7\u30d0\u30a4\u30b9\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u8aad\u66f8\u6a29\u9650\u3068\u3001Python\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u3042\u308bMomonga\u304c\u3069\u306e\u30e6\u30fc\u30b6\u30fc\u306e\u305f\u3081\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308b\u306e\u304b\u306b\u7559\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3064\u307e\u308a\u30e6\u30fc\u30b6\u30fc\u306b\u30c7\u30d0\u30a4\u30b9\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u8aad\u66f8\u6a29\u9650\u304c\u306a\u304f\u3001sudo\u3067python\u3092\u5b9f\u884c\u3057\u3088\u3046\u3068\u3057\u305f\u3068\u304d\u3001Momonga\u3082sudo\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u3063\u305f\u308a\u3057\u307e\u3059\u3002\u3057\u304b\u3057\u3001sudo\u3067\u74b0\u5883\u3092\u6c5a\u3059\u306e\u306f\u4e9b\u304b\u619a\u3089\u308c\u308b\u306e\u3067\u3001venv\u3092\u4f7f\u3046\u306e\u304c\u3088\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u3042\u308b\u3044\u306fDocker\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<p><strong>4. UDP\u30da\u30a4\u30ed\u30fc\u30c9\u3092ASCII\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3067\u51fa\u529b\u3059\u308b\u8a2d\u5b9a<\/strong><br \/>\nMomonga\u3092\u4f7f\u7528\u3059\u308b\u305f\u3081\u306b\u306f\u4e8b\u524d\u306bWi-SUN\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u30b7\u30ea\u30a2\u30eb\u63a5\u7d9a\u3057WOPT 01\\r\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066UDP\u30d1\u30b1\u30c3\u30c8\u306e\u30da\u30a4\u30ed\u30fc\u30c9\u3092ASCII\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3067\u51fa\u529b\u3059\u308b\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u6ce8\u610f: WOPT\u30b3\u30de\u30f3\u30c9\u306f\u5b9f\u884c\u56de\u6570\u306b\u5236\u9650\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u521d\u56de\u306e\u307f\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u8a2d\u5b9a\u306f\u4fdd\u5b58\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><strong>5. \u77ac\u9593\u96fb\u529b\u6e2c\u5b9a\u5024\u3092\u8868\u793a\u3057\u3066\u307f\u308b<\/strong><br \/>\n\u306f\u3058\u3081\u306f\u88cf\u3067\u306a\u306b\u304c\u8d77\u304d\u3066\u308b\u306e\u304b\u308f\u304b\u3089\u306a\u3044\u3068\u304a\u3082\u3046\u306e\u3067\u3001\u30ed\u30b0\u3092\u3059\u3079\u3066\u8868\u793a\u3057\u306a\u304c\u3089\u52d5\u304b\u3057\u3066\u307f\u308b\u306e\u304c\u3044\u3044\u3067\u3057\u3087\u3046\u3002rbid\u3068pwd\u306b\u306fB\u30eb\u30fc\u30c8\u306eID\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5165\u308c\u3066\u304f\u3060\u3055\u3044\u3002\u30c7\u30d0\u30a4\u30b9\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u30d1\u30b9\u306f\u74b0\u5883\u306b\u3088\u3063\u3066\u9055\u3044\u307e\u3059\u306e\u3067\u9069\u5b9c\u66f8\u304d\u63db\u3048\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: python; gutter: false; title: ; notranslate\" title=\"\">\r\nimport momonga\r\nimport time\r\nimport logging\r\n\r\nlog_fmt = logging.Formatter('%(asctime)s | %(levelname)s | %(name)s - %(message)s')\r\nlog_hnd = logging.StreamHandler()\r\nlog_hnd.setFormatter(log_fmt)\r\nmomonga.logger.addHandler(log_hnd)\r\nmomonga.logger.setLevel(logging.DEBUG)\r\nmomonga.session_manager_logger.addHandler(log_hnd)\r\nmomonga.session_manager_logger.setLevel(logging.DEBUG)\r\nmomonga.sk_wrapper_logger.addHandler(log_hnd)\r\nmomonga.sk_wrapper_logger.setLevel(logging.DEBUG)\r\n\r\nrbid = 'SET A ROUTE B ID'\r\npwd  = 'SET A ROUTE B PASSWORD'\r\ndev  = '\/dev\/ttyUSB0' # in a case of RaspberryPi OS\r\n\r\nwith momonga.Momonga(rbid, pwd, dev) as mo:\r\n    while True:\r\n        res = mo.get_instantaneous_power()\r\n        print('%0.1fW' % res)\r\n        time.sleep(60)\r\n<\/pre>\n<p>\u30a2\u30af\u30c6\u30a3\u30d6\u30b9\u30ad\u30e3\u30f3\u304c\u5931\u6557\u3057\u3066MomongaSkScanFailure\u304c\u9001\u51fa\u3055\u308c\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u306f\u4f7f\u3063\u3066\u3044\u308c\u3070\u5fc5\u767a\u3067\u3059\u3002\u3055\u3089\u306b\u5b9f\u7528\u3059\u308b\u306b\u3042\u305f\u3063\u3066\u306fPANA\u30bb\u30c3\u30b7\u30e7\u30f3\u306e\u78ba\u7acb\u306b\u5931\u6557\u3057\u305f\u3068\u304d\u306bMomongaSkJoinFailure\u3001\u518d\u9001\u3059\u308b\u3082\u5fdc\u7b54\u304c\u8fd4\u3089\u306a\u3044\u3068\u304d\u306bMomongaNeedToReopen\u304c\u9001\u51fa\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u3089\u3092\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3057\u3001\u9069\u5b9c\u518d\u63a5\u7d9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u305f\u3068\u3048\u3070\u3053\u3093\u306a\u3075\u3046\u306b\u3002<\/p>\n<pre class=\"brush: python; gutter: false; title: ; notranslate\" title=\"\">\r\nwhile True:\r\n    try:\r\n        with momonga.Momonga(rbid, pwd, dev) as mo:\r\n            while True:\r\n                res = mo.get_instantaneous_power()\r\n                print('%0.1fW' % res)\r\n                time.sleep(60)\r\n    except (momonga.MomongaSkScanFailure,\r\n            momonga.MomongaSkJoinFailure,\r\n            momonga.MomongaNeedToReopen) as e:\r\n        print('%s: %s' % (type(e).__name__, e), file=sys.stderr)\r\n        continue\r\n<\/pre>\n<p><strong>6. \u305d\u308c\u3092\u3053\u3046\u3057\u3066\u3053\u3046<\/strong><br \/>\n\u3067\u3001Momonga\u3067\u53ce\u96c6\u3057\u305f\u30c7\u30fc\u30bf\u3092InfluxDB\u306b\u7a81\u3063\u8fbc\u3093\u3067\u305d\u308c\u3092Grafana\u3067\u3053\u3046\u3057\u3066\u53ef\u8996\u5316\u3057\u3066\u3053\u3046\u3002\u306d\u3001\u7c21\u5358\u3067\u3057\u3087\uff1f<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-07-at-17.54.33-1024x904.png\" alt=\"\" width=\"730\" height=\"644\" class=\"aligncenter size-large wp-image-5346\" srcset=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-07-at-17.54.33-1024x904.png 1024w, https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-07-at-17.54.33-300x265.png 300w, https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-07-at-17.54.33-768x678.png 768w, https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-07-at-17.54.33-1200x1060.png 1200w, https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-07-at-17.54.33.png 1472w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><\/p>\n<p>\u7c21\u5358\u3058\u3083\u306a\u3044\u3068\u601d\u3063\u305f\u65b9\u3001\u308f\u305f\u304f\u3057\u3069\u3082\u304c\u304a\u4f5c\u308a\u3057\u307e\u3059\u3002\u305c\u3072\u3054\u7528\u547d\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Momonga\u306fB\u30eb\u30fc\u30c8\u30b5\u30fc\u30d3\u30b9\u3092\u5229\u7528\u3057\u3066\u30b9\u30de\u30fc\u30c8\u30e1\u30fc\u30bf\u30fc\u3068\u901a\u4fe1\u3059\u308bPython\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u3059\u3002\u4eca\u65e5\u306f\u305d\u306e\u4f7f\u3044\u65b9\u3092\u8aac\u660e\u3057\u307e\u3059\u3002 0. \u96fb\u529b\u4f1a\u793e\u306bB\u30eb\u30fc\u30c8\u306e\u7533\u8acb \u514e\u306b\u3082\u89d2\u306b\u3082\u3001\u307e\u305aB\u30eb\u30fc\u30c8\u306eID\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5165\u624b\u3057\u3066\u304f\u3060\u3055 [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5342","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts\/5342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5342"}],"version-history":[{"count":22,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts\/5342\/revisions"}],"predecessor-version":[{"id":5373,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts\/5342\/revisions\/5373"}],"wp:attachment":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}