{"id":710,"date":"2017-09-13T22:06:11","date_gmt":"2017-09-13T14:06:11","guid":{"rendered":"https:\/\/xujiwei.com\/blog\/?p=710"},"modified":"2017-09-13T22:06:11","modified_gmt":"2017-09-13T14:06:11","slug":"homeautomation-watersensor","status":"publish","type":"post","link":"https:\/\/xujiwei.com\/blog\/2017\/09\/homeautomation-watersensor\/","title":{"rendered":"\u73a9\u73a9\u667a\u80fd\u5bb6\u5c455\uff1aDIY\u6c34\u6d78\u4f20\u611f\u5668"},"content":{"rendered":"<p>\u4e4b\u524d\u603b\u662f\u62c5\u5fc3\u53a8\u623f\u6c34\u69fd\u4e0b\u6c34\u7ba1\u4f1a\u6f0f\u6c34\uff0c\u6240\u4ee5\u76f4\u63a5\u7528\u96e8\u6c34\u4f20\u611f\u5668\u505a\u4e86\u4e00\u4e2a\u6c34\u6d78\u4f20\u611f\u5668\uff0c\u8fd9\u6837\u5728\u6f0f\u6c34\u7684\u65f6\u5019\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u6536\u5230\u901a\u77e5\uff0c\u4ece\u800c\u53ca\u65f6\u53bb\u68c0\u67e5\u5e76\u4fee\u590d\u4e0b\u6c34\u7ba1\u6f0f\u6c34\u95ee\u9898\u3002<\/p>\n<p>\u8981 DIY \u4e00\u4e2a\u6c34\u6d78\u4f20\u611f\u5668\u8fd8\u662f\u5f88\u7b80\u5355\u7684\uff0c\u53ea\u9700\u8981\u4e00\u4e2a\u96e8\u6c34\u4f20\u611f\u5668\u548c\u4e00\u4e2a NodeMCU \u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p><strong>\u96e8\u6c34\u4f20\u611f\u5668<\/strong><\/p>\n<p><img loading=\"lazy\" src=\"https:\/\/xujiwei.com\/blog\/wp-content\/uploads\/2017\/09\/water-sensor.png\" alt=\"\" width=\"250\" height=\"250\" class=\"alignnone size-full wp-image-711\" \/><\/p>\n<p>\u7ed9 NodeMCU \u5237\u4e0a ESPEasy\uff0c\u914d\u7f6e\u4e00\u4e2a Switch \u8bbe\u5907\uff0c\u5c06 GPIO \u8bbe\u7f6e\u4e3a NodeMCU \u4e0e\u96e8\u6c34\u4f20\u611f\u5668 DO \u9488\u811a\u8fde\u63a5\u7684 IO \u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p><img src=\"https:\/\/xujiwei.com\/blog\/wp-content\/uploads\/2017\/09\/espeasy-water.png\" alt=\"\" width=\"574\" class=\"alignnone size-full wp-image-712\" \/><\/p>\n<p>\u7136\u540e\u518d\u5728 Domoticz \u4e2d\u914d\u7f6e\u597d\u4e00\u4e2a Virtual Sensor\uff0c\u7c7b\u578b\u6539\u4e3a Switch \u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<h2>\u62a5\u8b66\u58f0\u97f3<\/h2>\n<p>\u6709\u4e9b\u65f6\u5019\u63a8\u9001\u901a\u77e5\u4f1a\u6bd4\u8f83\u6162\uff0c\u53c8\u6216\u8005\u624b\u673a\u4e0d\u5728\u8eab\u8fb9\uff0c\u90a3\u4e48\u662f\u5426\u53ef\u4ee5\u76f4\u63a5\u5728 NodeMCU \u8fd9\u4e00\u7aef\u76f4\u63a5\u4f7f\u7528\u58f0\u97f3\u62a5\u8b66\u5462\uff1f\u8fd9\u5f88\u7b80\u5355\uff0c\u52a0\u4e2a\u8702\u9e23\u5668\u6a21\u5757\uff0c\u518d\u5199\u70b9\u4ee3\u7801\u5c31\u597d\u4e86\u3002<\/p>\n<p>\u5148\u7ed9 ESPEasy \u5199\u4e2a\u8702\u9e23\u5668\u63d2\u4ef6\uff0c\u5173\u952e\u4ee3\u7801\u5c31\u662f\u4f7f\u7528 Arduino \u7684 tone \u51fd\u6570\u4e86\uff1a<\/p>\n<pre><code>#define Plugin158_Do 262\n#define Plugin158_Re 294\n#define Plugin158_Mi 330\n#define Plugin158_Fa 349\n#define Plugin158_Sol 392\n#define Plugin158_La 440\n#define Plugin158_Si 494\n\nstatic int Plugin158_TonesFreq[] = { Plugin158_Do, Plugin158_Re, Plugin158_Mi, Plugin158_Fa, Plugin158_Sol, Plugin158_La, Plugin158_Si };\n\nstatic void Plugin158_PlayTones(int taskIndex) {\n  int pin = Settings.TaskDevicePin1[taskIndex];\n\n  char *tonesStr = \"616161\";\n\n  pinMode(pin, OUTPUT);\n  int len = strlen(tonesStr);\n  if (Plugin158_TonesPlayingCharIndex &lt; len) {\n    char c = tonesStr[Plugin158_TonesPlayingCharIndex];\n    int index = c - '0';\n    if (index &gt; 0 &amp;&amp; index &lt;= 7) {\n      tone(pin, Plugin158_TonesFreq[index]);\n    } else {\n      noTone(pin);\n    }\n  }\n\n  Plugin158_TonesPlayingCharIndex++;\n  if (Plugin158_TonesPlayingCharIndex &gt;= len) {\n    Plugin158_TonesPlayingCharIndex = 0;\n  }\n}\n<\/code><\/pre>\n<p>\u4e3a\u4e86\u80fd\u5728\u6709\u6f0f\u6c34\u65f6\uff0c\u9a6c\u4e0a\u62a5\u8b66\uff0c\u6216\u8005\u4e3a\u4e86\u5728\u6ca1\u6709\u7f51\u7edc\u60c5\u51b5\u4e0d\u597d\u65f6\u4e5f\u80fd\u9a6c\u4e0a\u4f7f\u7528\u58f0\u97f3\u62a5\u8b66\uff0c\u9700\u8981\u5728 ESPEasy \u7684\u672c\u5730\u89c4\u5219\u91cc\u68c0\u6d4b\u5230\u6f0f\u6c34\u65f6\u6765\u62a5\u8b66\u3002<\/p>\n<p>\u8981\u5b9e\u73b0\u8fd9\u4e2a\u529f\u80fd\uff0c\u53ea\u9700\u8981\u4f7f\u7528 ESPEasy \u7684 Rules \u529f\u80fd\uff0c\u5728 Rules \u91cc\u68c0\u6d4b\u5230\u6709\u6f0f\u6c34\u65f6\uff0c\u76f4\u63a5\u8c03\u7528\u8702\u9e23\u5668\u63d2\u4ef6\u8fdb\u884c\u62a5\u8b66\uff1a<\/p>\n<pre><code>on WATER#VAL=1 do\n    buzzer,2,1\nendon\non WATER#VAL=0 do\n    buzzer,2,0\nendon\n<\/code><\/pre>\n<h2>\u66f4\u597d\u7684\u9009\u62e9<\/h2>\n<p>\u5f53\u7136\uff0c\u5982\u679c\u5df2\u7ecf\u6709\u5c0f\u7c73\u7f51\u5173\u4e86\uff0c\u53ef\u4ee5\u76f4\u63a5\u8d2d\u4e70 Aqara \u6c34\u6d78\u4f20\u611f\u5668\uff0c\u4f7f\u7528\u7535\u6c60\uff0c\u65b9\u4fbf\u90e8\u7f72\uff0c\u8fd8\u7f8e\u89c2 \ud83d\ude48\u3002<\/p>\n<p>\u800c\u4e14\u5c0f\u7c73\u7684\u4e1c\u897f\u4e5f\u53ef\u4ee5\u4e0d\u501f\u52a9\u4e8e Domoticz \u76f4\u63a5\u4f7f\u7528\uff0c\u53ef\u4ee5\u5c06\u6c34\u6d78\u4f20\u611f\u5668\u8bbe\u7f6e\u81ea\u52a8\u5316\uff0c\u89e6\u53d1\u65f6\u76f4\u63a5\u4f7f\u7528\u5c0f\u7c73\u7f51\u5173\u64ad\u653e\u8b66\u62a5\u97f3\u3002<\/p>\n<h2>\u53c2\u8003\u8d44\u6599<\/h2>\n<ol>\n<li><a href=\"https:\/\/domoticz.com\/\">Domoticz<\/a><\/li>\n<li><a href=\"https:\/\/www.arduino.cc\/en\/Reference\/Tone\">Arduino - Tone<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u603b\u662f\u62c5\u5fc3\u53a8\u623f\u6c34\u69fd\u4e0b\u6c34\u7ba1\u4f1a\u6f0f\u6c34\uff0c\u6240\u4ee5\u76f4\u63a5\u7528\u96e8\u6c34\u4f20\u611f\u5668\u505a\u4e86\u4e00\u4e2a\u6c34\u6d78\u4f20\u611f\u5668\uff0c\u8fd9\u6837\u5728 &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/xujiwei.com\/blog\/2017\/09\/homeautomation-watersensor\/\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[167],"tags":[251,256,255,266,267,254],"_links":{"self":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts\/710"}],"collection":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/comments?post=710"}],"version-history":[{"count":0,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts\/710\/revisions"}],"wp:attachment":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/media?parent=710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/categories?post=710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/tags?post=710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}