{"id":1764,"date":"2020-05-05T15:46:55","date_gmt":"2020-05-05T06:46:55","guid":{"rendered":"https:\/\/www.amano-labo.jp\/pages\/?p=1764"},"modified":"2020-05-06T10:28:41","modified_gmt":"2020-05-06T01:28:41","slug":"%e5%ae%a4%e6%b8%a9%e3%83%bb%e6%b9%bf%e5%ba%a6%e3%83%a2%e3%83%8b%e3%82%bfiot%e3%81%ae%e3%83%a9%e3%83%94%e3%83%83%e3%83%89%e3%83%97%e3%83%ad%e3%83%88%e3%82%bf%e3%82%a4%e3%83%94%e3%83%b3%e3%82%b0","status":"publish","type":"post","link":"https:\/\/www.amano-labo.jp\/pages\/blog\/1764\/","title":{"rendered":"\u5ba4\u6e29\u30fb\u6e7f\u5ea6\u30e2\u30cb\u30bfIoT\u306e\u30e9\u30d4\u30c3\u30c9\u30d7\u30ed\u30c8\u30bf\u30a4\u30d4\u30f3\u30b0\uff08\u6b7b\u6d3b\u76e3\u8996\u6a5f\u80fd\u3082\u8ffd\u52a0\uff09"},"content":{"rendered":"<div class=\"amano- amano-entity-placement\" id=\"amano-2690534529\"><div id=\"amano-817489638\"><a href=\"https:\/\/www.amano-labo.jp\/pages\/blog\/1941\/\" aria-label=\"amls2\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/09\/amls2.png\" alt=\"\"  srcset=\"https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/09\/amls2.png 1000w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/09\/amls2-300x24.png 300w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/09\/amls2-768x61.png 768w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/09\/amls2-100x8.png 100w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/09\/amls2-150x12.png 150w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/09\/amls2-200x16.png 200w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/09\/amls2-450x36.png 450w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/09\/amls2-600x48.png 600w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/09\/amls2-900x72.png 900w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" width=\"1000\" height=\"80\"   \/><\/a><\/div><\/div>\n<p>\u5728\u5b85\u52e4\u52d9\u304c\u5897\u52a0\u3059\u308b\u3068\u3001\u52e4\u52d9\u5148\u306e\u72b6\u6cc1\u304c\u6c17\u306b\u306a\u308a\u307e\u3059\u3002\u305d\u3053\u3067\u5ba4\u6e29\u3068\u6e7f\u5ea6\u3092\u8a08\u6e2c\u3001\u8a18\u9332\u3092\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u4e0a\u3067\u8a18\u9332\u3059\u308bIoT\u3092\u30e9\u30d4\u30c3\u30c9\u30d7\u30ed\u30c8\u30bf\u30a4\u30d4\u30f3\u30b0\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"450\" src=\"https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/05\/20200505_iot.jpg\" alt=\"\" class=\"wp-image-1765\" srcset=\"https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/05\/20200505_iot.jpg 800w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/05\/20200505_iot-300x169.jpg 300w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/05\/20200505_iot-768x432.jpg 768w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/05\/20200505_iot-100x56.jpg 100w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/05\/20200505_iot-150x84.jpg 150w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/05\/20200505_iot-200x113.jpg 200w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/05\/20200505_iot-450x253.jpg 450w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2020\/05\/20200505_iot-600x338.jpg 600w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p>\u88c5\u7f6e\u306fM5StickC\u3068grove\u63a5\u7d9a\u306e\u6e7f\u5ea6\u30bb\u30f3\u30b5\u30fc\uff08DHT11\uff09\u3067\u3059\u3002Amazon\u3067\u5165\u624b\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u8a18\u9332\u5074\u306fGoogle Apps Script\u3092\u7528\u3044\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002Spreadsheet\u306b1\u884c\u305a\u3064\u3001\u8a08\u6e2c\u30c7\u30fc\u30bf\u3092\u8ffd\u8a18\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nfunction doPost(ee) {\n  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()&#x5B;0];\n  var values = JSON.parse(ee.postData.getDataAsString());\n  sheet.appendRow(&#x5B;new Date(), values.humi, values.temp]);\n}\n<\/pre><\/div>\n\n\n<p>\u30c7\u30fc\u30bf\u7528\u306e\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3092\u4f5c\u6210\u3057\u3001\u30c4\u30fc\u30eb\u2192\u30b9\u30af\u30ea\u30d7\u30c8\u30a8\u30c7\u30a3\u30bf\u3067\u3001\u4e0a\u8a18\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3092\u8a18\u5165\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u306e\u5f8c\u3001\u516c\u958b\u2192Web\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3068\u3057\u3066\u5c0e\u5165\u3057\u3001\u305d\u306eURL\u3092\u30e1\u30e2\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>M5StickC\u5074\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u3082\u306e\u306b\u306a\u308a\u307e\u3059\u3002DHT11\u7528\u306eAdafruit\u793e\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u3042\u3089\u304b\u3058\u3081\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &amp;lt;M5StickC.h&gt;\n#include &amp;lt;WiFi.h&gt;\n#include &amp;lt;HTTPClient.h&gt;\n#include &amp;lt;Wire.h&gt;\n#include &quot;DHT.h&quot;\n \n#define DHTPIN 33\n#define DHTTYPE DHT11\n\nconst char* ssid = &quot;!!! input WiFi SSID Name !!!&quot;;\nconst char* password = &quot;!!! input WiFi Password !!!&quot;;\nconst char* published_url = &quot;!!! input Google Spreadsheet scripts web application URL !!!&quot;;\n\nDHT dht(DHTPIN, DHTTYPE);\n \nvoid setup() {\n  M5.begin();\n\n  M5.Lcd.setRotation(3);\n  M5.Lcd.print(&quot;wifi connect...&quot;);\n\n  WiFi.mode(WIFI_STA);\n  WiFi.disconnect(true);\n  delay(1000);\n\n  WiFi.begin(ssid, password);\n  while (WiFi.status() != WL_CONNECTED) {\n    delay(100);\n    Serial.print(&quot;.&quot;);\n  }\n    \n  Serial.println(&quot;DHT11 init...&quot;);\n  dht.begin();\n  \n  delay(1000);\n}\n\nvoid loop() {\n  M5.update();\n  \n  float h = dht.readHumidity();\n  float t = dht.readTemperature();\n  if (isnan(h) || isnan(t)) {\n      Serial.println(F(&quot;Failed to read from DHT sensor!&quot;));\n  } else {\n    Serial.print(h);\n    Serial.print(&quot;&quot; );\n    Serial.println(t);\n  \n    M5.Lcd.setCursor(0, 0);\n    M5.Lcd.print(&quot;humi : &quot;);\n    M5.Lcd.print(h);\n    M5.Lcd.print(&quot; temp : &quot;);\n    M5.Lcd.println(t);\n  \n    char json&#x5B;64];\n    sprintf(json, &quot;{\\&quot;humi\\&quot;: \\&quot;%f\\&quot; , \\&quot;temp\\&quot;: \\&quot;%f\\&quot; }&quot;, h, t);\n  \n    HTTPClient http;\n  \n    http.begin(published_url);\n    int httpCode = http.POST(json);\n    if (httpCode &gt; 0) {\n      if (httpCode == HTTP_CODE_OK) {\n        String payload = http.getString();\n        Serial.println(payload);\n      }\n    } else {\n      Serial.println(&quot;http fail&quot;);\n    }\n   \n    http.end();\n  }\n  \n  delay(60000);\n}\n<\/pre><\/div>\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f1\u5206\u3054\u3068\u306b\u8a08\u6e2c\u5024\u3092\u9001\u4fe1\u3057\u3066\u3044\u307e\u3059\u3002\u672b\u5c3e\u306edelay\u306e\u5f15\u6570(ms)\u304c\u305d\u308c\u3092\u6c7a\u3081\u3066\u3044\u307e\u3059\u3002\u901a\u5e38\u306f\u5ba4\u6e29\u3084\u6e7f\u5ea6\u306f\u305d\u3093\u306a\u306b\u6025\u6fc0\u306b\u5909\u5316\u3057\u306a\u3044\u306e\u3067\u3001\u3082\u3063\u3068\u9577\u3081\u3067\u3082\u3088\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>Google Apps Script\u3067\u66f4\u306b\u5b9a\u671f\u7684\u306b\u30c7\u30fc\u30bf\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308c\u3070\u6b7b\u6d3b\u76e3\u8996\u3082\u3067\u304d\u307e\u3059\u306d\u3001\u3068\u3057\u307e\u3057\u305f\u304c\u3001\u6b7b\u6d3b\u76e3\u8996\u3082\u4f5c\u6210\u3057\u307e\u3057\u305f(2020\/05\/06)\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nvar PROPERTY_NAME = &quot;humi_rec_locationname_prevResult&quot;;\n\nfunction healthCheck() {\n  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()&#x5B;0];\n  var lastRow = sheet.getLastRow();\n  var lastDate = sheet.getRange(lastRow, 1).getValue();\n  var diffDateMinutes = ((new Date()).getTime() - lastDate.getTime()) \/ (1000 * 60);\n  \n  var properties = PropertiesService.getScriptProperties();\n  var prevResult = properties.getProperty(PROPERTY_NAME);\n  if (prevResult == null) {\n    prevResult = &quot;success&quot;;\n  }\n  if (diffDateMinutes &gt; 60) {\n    if (prevResult == &quot;success&quot;) {\n      const recipient = &#039;\u9001\u4fe1\u5148\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9&#039;;\n      const subject = &#039;Is your Humi IoT device stopped?&#039;;\n      const body = &#039;Plase check your Humi IoT device. There has been no communication since then for over 60 minutes.&#039;;\n      \n      GmailApp.sendEmail(recipient, subject, body);\n      properties.setProperty(PROPERTY_NAME, &quot;fail&quot;);\n      console.log(&quot;success to fail : send mail&quot;);\n    } else {\n      console.log(&quot;fail to fail : nothing&quot;);\n    }\n  } else {\n    properties.setProperty(PROPERTY_NAME, &quot;success&quot;);\n    if (prevResult == &quot;success&quot;) {\n      console.log(&quot;success to success : nothing&quot;);\n    } else {\n      console.log(&quot;fail to success : nothing&quot;);\n    }\n  }\n}\n<\/pre><\/div>\n\n\n<p>\u5148\u306edoPost\u95a2\u6570\u306e\u5f8c\u306b\u4e0a\u3092\u66f8\u304d\u307e\u3059\u3002\u3053\u306e\u4f8b\u3067\u306f\u6210\u529f\u2192\u5931\u6557\u6642\u306b\u30e1\u30fc\u30eb\u3067\u901a\u77e5\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002\u5931\u6557\u3059\u308b\u305f\u3073\u306b\u9001\u4fe1\u3059\u308b\u3068\u5927\u91cf\u306e\u30e1\u30fc\u30eb\u304c\u5c4a\u3044\u3066\u305f\u3044\u3078\u3093\u306a\u3053\u3068\u306b\u306a\u308b\u306e\u3067\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u7528\u3044\u3066\u524d\u56de\u306e\u30c1\u30a7\u30c3\u30af\u7d50\u679c\u3092\u53c2\u7167\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u306e\u4e0a\u3067\u3001\u4e00\u5ea6\u52d5\u4f5c\u8a66\u9a13\u3092\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u30e1\u30fc\u30eb\u9001\u4fe1\u306e\u305f\u3081\u306e\u6a29\u9650\u304c\u5897\u3048\u308b\u306e\u3067\u305d\u306e\u30c1\u30a7\u30c3\u30af\u304c\u5165\u308a\u307e\u3059\u3002\u9014\u7d76\u3048\u305f\u5834\u5408\u306e\u51e6\u7406\u3092\u691c\u8a3c\u3059\u308b\u306b\u306f\u6642\u9593\u5dee\u3092\u6c42\u3081\u3066\u3044\u308b\u884c\u3067\uff0b100\u306a\u3069\u3057\u3066\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\uff08\u623b\u3059\u3053\u3068\u3092\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\uff09\u3002<\/p>\n\n\n\n<p>\u6b21\u306b\u300c\u7de8\u96c6\u300d\u2192\u300c\u73fe\u5728\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30c8\u30ea\u30ac\u30fc\u300d\u3092\u30af\u30ea\u30c3\u30af\u3057\u3001\u300c\u30c8\u30ea\u30ac\u30fc\u3092\u8ffd\u52a0\u300d\u3057\u307e\u3059\u3002\u4f5c\u6210\u3057\u305f\u300chealthCheck\u300d\u95a2\u6570\u3092\u3001\u6642\u9593\u4e3b\u5c0e\u578b\u3001\u5206\u30d9\u30fc\u30b9\u300130\u5206\u304a\u304d\u3001\u4eca\u3059\u3050\u901a\u77e5\u3092\u53d7\u3051\u4ed8\u3051\u308b\u3001\u3042\u305f\u308a\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u57c3\u304b\u3089\u9632\u3050\u305f\u3081\u306e\u30b1\u30fc\u30b9\u306fM5StickC\u306e\u5165\u3063\u3066\u3044\u305f\u30b1\u30fc\u30b9\u3092\u305d\u306e\u307e\u307e\u518d\u5229\u7528\u3057\u307e\u3057\u305f\u3002\u3042\u307e\u308a\u767a\u71b1\u306f\u3057\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u5ba4\u6e29\uff65\u6c17\u6e29\u304c\u9069\u5207\u306b\u8a08\u6e2c\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u3001\u7a7a\u6c17\u306e\u6d41\u308c\u3092\u78ba\u4fdd\u3067\u304d\u308b\u3088\u3046\u306b\u4e21\u5074\u306b\u7a74\u3092\u958b\u3051\u307e\u3057\u305f\u3002<\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5b85\u52e4\u52d9\u304c\u5897\u52a0\u3059\u308b\u3068\u3001\u52e4\u52d9\u5148\u306e\u72b6\u6cc1\u304c\u6c17\u306b\u306a\u308a\u307e\u3059\u3002\u305d\u3053\u3067\u5ba4\u6e29\u3068\u6e7f\u5ea6\u3092\u8a08\u6e2c\u3001\u8a18\u9332\u3092\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u4e0a\u3067\u8a18\u9332\u3059\u308bIoT\u3092\u30e9\u30d4\u30c3\u30c9\u30d7\u30ed\u30c8\u30bf\u30a4\u30d4\u30f3\u30b0\u3057\u3066\u307f\u307e\u3057\u305f\u3002 \u88c5\u7f6e\u306fM5StickC\u3068grove\u63a5\u7d9a\u306e\u6e7f\u5ea6\u30bb\u30f3\u30b5\u30fc\uff08DHT11\uff09 <a class=\"more-link\" href=\"https:\/\/www.amano-labo.jp\/pages\/blog\/1764\/\">\u7d9a\u304d\u3092\u8aad\u3080\u2026<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[31,43],"class_list":["post-1764","post","type-post","status-publish","format-standard","hentry","category-blog","tag-google-apps-script","tag-iot"],"_links":{"self":[{"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/posts\/1764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/comments?post=1764"}],"version-history":[{"count":7,"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/posts\/1764\/revisions"}],"predecessor-version":[{"id":1779,"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/posts\/1764\/revisions\/1779"}],"wp:attachment":[{"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/media?parent=1764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/categories?post=1764"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/tags?post=1764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}