{"id":1068,"date":"2026-05-22T17:12:58","date_gmt":"2026-05-22T08:12:58","guid":{"rendered":"https:\/\/sakae-shokai.com\/wordpress\/?p=1068"},"modified":"2026-05-22T17:12:59","modified_gmt":"2026-05-22T08:12:59","slug":"node-red%e3%81%a7iot-%e3%81%9d%e3%81%ae%ef%bc%92%e3%80%80%e3%83%87%e3%83%bc%e3%82%bf%e5%8f%8e%e9%9b%86","status":"publish","type":"post","link":"https:\/\/sakae-shokai.com\/wordpress\/?p=1068","title":{"rendered":"NODE-RED\u3067IoT  &#8212; \u305d\u306e\uff12\u3000\u30c7\u30fc\u30bf\u53ce\u96c6"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u305d\u308c\u3067\u306f\u3001\u6b21\u306bnode-red\u3092\u4f7f\u7528\u3057\u3066modbus\u901a\u4fe1\u95a2\u9023\u306e\u30c7\u30e2\u6a5f\u306e\u69cb\u7bc9\u3092\u9032\u3081\u3066\u884c\u304d\u307e\u3059\u3002<br>\u81ea\u5b85\u306b\u904a\u3073\u5012\u3057\u305f\u30e9\u30ba\u30d1\u30a4\uff13B\u3068\u30bb\u30f3\u30b5\u30fcBME680\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u3053\u308c\u3092\u4f7f\u7528\u3057\u3066\u3001\u5ba4\u6e29\u3001\u6e7f\u5ea6\u3001\u6c17\u5727\u3001\u30ac\u30b9\u6fc3\u5ea6\u3092\u5b9a\u671f\u7684\u306b\u63a1\u53d6\u3057\u3066\u3053\u308c\u3092NODE-RED\u3067\u53ce\u96c6\u3057\u3001modbus\u306b\u3066\u30c7\u30fc\u30bf\u3092\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u5185\u306b\u6d41\u3057\u307e\u3059\u3002<br>\u307e\u305a\u306f\u3001BME680\u306e\u30c7\u30fc\u30bf\u3092\u63a1\u53d6\u3059\u308b\u5de5\u7a0b\u3067\u3059\u304c\u3001NODE-RED\u3067\u3082node-red-contrib-bme680-rpi\u3068\u3044\u3046\u3001\u30ce\u30fc\u30c9\u304c\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u30a4\u30de\u30a4\u30c1\u30c7\u30fc\u30bf\u3092\u53d6\u308c\u306a\u3044\u305f\u3081\u3001python\u306b\u3066\u7121\u7406\u3084\u308a\u30c7\u30fc\u30bf\u3092POST\u3057\u3066\u3001\u3053\u308c\u3092\u53d6\u308a\u8fbc\u307f\u307e\u3059\u3002<br>\u307e\u305a\u306fBME680\u7528\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo pip3 install bme680<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b21\u306b\u30c7\u30fc\u30bf\u53ce\u96c6\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import bme680\nimport time\nimport requests\nimport json\n\n# \u30bb\u30f3\u30b5\u30fc\u521d\u671f\u8a2d\u5b9a\ntry:\n    sensor = bme680.BME680(bme680.I2C_ADDR_PRIMARY) # 0x76\u306e\u5834\u5408\nexcept (RuntimeError, IOError):\n    sensor = bme680.BME680(bme680.I2C_ADDR_SECONDARY) # 0x77\u306e\u5834\u5408\n\n# \u30d5\u30a3\u30eb\u30bf\u30fc\u8a2d\u5b9a\uff08\u5024\u3092\u5b89\u5b9a\u3055\u305b\u308b\uff09\nsensor.set_humidity_oversample(bme680.OS_2X)\nsensor.set_pressure_oversample(bme680.OS_4X)\nsensor.set_temperature_oversample(bme680.OS_8X)\nsensor.set_filter(bme680.FILTER_SIZE_3)\n\n# Node-RED\u306e\u5f85\u3061\u53d7\u3051URL\nurl = \"http:\/\/127.0.0.1:1880\/sensor-data\"\n\nprint(\"\u30c7\u30fc\u30bf\u9001\u4fe1\u3092\u958b\u59cb\u3057\u307e\u3059...\")\n\ntry:\n    while True:\n        if sensor.get_sensor_data():\n            # \u30c7\u30fc\u30bf\u306e\u6574\u5f62\n            payload = {\n                \"temperature\": round(sensor.data.temperature, 2),\n                \"humidity\": round(sensor.data.humidity, 2),\n                \"pressure\": round(sensor.data.pressure, 2),\n                \"gas\": round(sensor.data.gas_resistance, 2)\n            }\n            \n            # Node-RED\u306bPOST\u9001\u4fe1\n            try:\n                response = requests.post(url, json=payload)\n                print(f\"\u9001\u4fe1\u6210\u529f: {payload}\")\n            except Exception as e:\n                print(f\"\u9001\u4fe1\u30a8\u30e9\u30fc: {e}\")\n\n        time.sleep(5) # 5\u79d2\u304a\u304d\n\nexcept KeyboardInterrupt:\n    print(\"\u505c\u6b62\u3057\u307e\u3059\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u3001\/home\/sensor_project\/<code>bme680_to_nodered.py<\/code>\u306b\u4fdd\u5b58\u3057\u307e\u3059\u3002<br>systemd\u306b\u767b\u9332\u3057\u307e\u3059<br>sudo nano \/etc\/systemd\/system\/bme680_sensor.service\u306b\u8a18\u8f09\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;Unit]\nDescription=BME680 to Node-RED Gateway Service\nAfter=network.target\n\n&#91;Service]\nUser=****\nWorkingDirectory=\/home\/****\/sensor_project\/\nExecStart=\/usr\/bin\/python3 \/home\/****\/sensor_project\/bme680_to_nodered.py\nRestart=always\nRestartSec=5\n\n&#91;Install]\nWantedBy=multi-user.target<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">systemd\u306b\u8aad\u307f\u8fbc\u307e\u305b\u308b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl daemon-reload<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u81ea\u52d5\u8d77\u52d5\u5316\u3092\u6709\u52b9\u5316\u3001\u8d77\u52d5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable bme680_sensor.service\nsudo systemctl start bme680_sensor.service<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u30b5\u30fc\u30d3\u30b9\u306e\u6709\u52b9\u72b6\u614b\u3092\u78ba\u8a8d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status bme680_sensor.service\n\u25cf bme680_sensor.service - BME680 to Node-RED Gateway Service\nLoaded: loaded (\/etc\/systemd\/system\/bme680_sensor.service; enabled; pr>\nActive: active (running) since Wed 2026-04-15 19:03:56 JST; 3 weeks 2 >\nInvocation: 38ab551302044856abae85c8db00c824\nMain PID: 1141 (python3)\nTasks: 1 (limit: 756)\nCPU: 39min 21.059s\nCGroup: \/system.slice\/bme680_sensor.service\n\u2514\u25001141 \/usr\/bin\/python3 \/home\/suga777\/sensor_project\/bme680_to><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u305d\u3046\u3059\u308b\u3068\u3001\u30c7\u30fc\u30bf\u304c\u51fa\u59cb\u3081\u3066\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>temperature: 24.87\nhumidity: 41.39\npressure: 1011.13\ngas: 12535991.79<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u9577\u304f\u306a\u3063\u3066\u304d\u307e\u3057\u305f\u306e\u3067\u3001\u4eca\u65e5\u306f\u3053\u3053\u307e\u3067\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u305d\u308c\u3067\u306f\u3001\u6b21\u306bnode-red\u3092\u4f7f\u7528\u3057\u3066modbus\u901a\u4fe1\u95a2\u9023\u306e\u30c7\u30e2\u6a5f\u306e\u69cb\u7bc9\u3092\u9032\u3081\u3066\u884c\u304d\u307e\u3059\u3002\u81ea\u5b85\u306b\u904a\u3073\u5012\u3057\u305f\u30e9\u30ba\u30d1\u30a4\uff13B\u3068\u30bb\u30f3\u30b5\u30fcBME680\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u3053\u308c\u3092\u4f7f\u7528\u3057\u3066\u3001\u5ba4\u6e29\u3001\u6e7f\u5ea6\u3001\u6c17\u5727\u3001\u30ac\u30b9\u6fc3\u5ea6\u3092\u5b9a\u671f\u7684\u306b\u63a1\u53d6\u3057\u3066\u3053 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/sakae-shokai.com\/wordpress\/?p=1068\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;NODE-RED\u3067IoT  &#8212; \u305d\u306e\uff12\u3000\u30c7\u30fc\u30bf\u53ce\u96c6&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[142,143,15,8],"tags":[],"class_list":["post-1068","post","type-post","status-publish","format-standard","hentry","category-node-red","category-plc","category-15","category-archive"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1068","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1068"}],"version-history":[{"count":6,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1068\/revisions"}],"predecessor-version":[{"id":1074,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1068\/revisions\/1074"}],"wp:attachment":[{"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sakae-shokai.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}