{"id":1809,"date":"2024-11-13T13:50:28","date_gmt":"2024-11-13T04:50:28","guid":{"rendered":"https:\/\/rfsec.ddns.net\/db\/?p=1809"},"modified":"2024-11-20T21:18:33","modified_gmt":"2024-11-20T12:18:33","slug":"weather-station%e3%81%ae%e5%ae%a4%e5%a4%96%e3%83%87%e3%83%bc%e3%82%bf%e3%82%92-rtl_433-influxdb-graphana%e3%81%a7%e5%8f%af%e8%a6%96%e5%8c%96","status":"publish","type":"post","link":"https:\/\/rfsec.ddns.net\/db\/?p=1809","title":{"rendered":"Weather Station\u306e\u5ba4\u5916\u30c7\u30fc\u30bf\u3092 rtl_433, influxDB, grafana\u3067\u53ef\u8996\u5316"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>(myenv) mars@pi4Bu:~ $ cat<strong> weather-influx.py<\/strong>\n#coding: utf-8\n# encoding: utf-8\n\nimport sys\nimport subprocess\nimport json\nimport struct\nfrom influxdb import InfluxDBClient\n\nclient = InfluxDBClient(host='XXX.XXX.XXX.XXX', port=8086,\n                        username='root', password='XXXXX', database='iot01')\nmeasurement = 'weather-station'\ntags = {'place': 'leaf-weather', 'host': 'weather'}\n\ncmd = &#91;\n    \"rtl_433\",\n    \"-F\", \"json\"\n]\n\nprocess = subprocess.Popen(\n    cmd,\n    stdout=subprocess.PIPE,\n    universal_newlines=True\n)\n\nfor line in iter(process.stdout.readline, ''):\n    if \"time\" in line:\n        data = json.loads(line)\n        temp = round((float(data&#91;\"temperature_F\"])-32)\/1.8,1)\n        humi = data&#91;\"humidity\"]\n        wspd = round(float(data&#91;\"wind_avg_km_h\"])\/3600,1)\n        wdir = data&#91;\"wind_dir_deg\"]\n        rain = data&#91;\"rain_mm\"]\n    json_body = &#91;\n        {\n        'measurement': measurement,\n        'tags': tags,\n        'fields': {'temp': temp, 'humi': humi, 'wdir': wdir, 'wspd':wspd}\n        }\n    ]\n    client.write_points(json_body)\n    print(json_body)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1809","post","type-post","status-publish","format-standard","hentry","category-radio"],"featured_image_src":null,"author_info":{"display_name":"mars","author_link":"https:\/\/rfsec.ddns.net\/db\/?author=1"},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts\/1809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1809"}],"version-history":[{"count":3,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts\/1809\/revisions"}],"predecessor-version":[{"id":1847,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=\/wp\/v2\/posts\/1809\/revisions\/1847"}],"wp:attachment":[{"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rfsec.ddns.net\/db\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}