jksoft が 2024年10月21日16時17分48秒 に編集
初版
タイトルの変更
Nest Watcher
タグの変更
RaspberryPiPICO
Arduino
enebular
LINE
Grove
メイン画像の変更
記事種類の変更
製作品
ライセンスの変更
(MIT) The MIT License
本文の変更
家族で暮らしてると外出先で、子どもがちゃんと家に帰っているか、夕食を何人分用意するか、考えることがあります。 そんなときこのNest Watcherというシステムを作り、実際に使ってみて便利だったので、紹介します。 Nest Watcherは、LINE Botに問い合わせることで、家に誰が居るかわかるシステムです。 ついでに家の中の気温や湿度がどのぐらいか確認できるようにしました。 将来的には、エアコンを付けたり、消し忘れたテレビや暖房を消したりできるようにしたいと思っています。 製作したセンサーキーボックス ![キャプションを入力できます](https://camo.elchika.com/15ce539a7ef64a301264746c0fab2f06ef9a95ce/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f65306661366265332d633431372d346430352d613764372d3532633938646565633766662f61666264386135382d303765652d343733392d383063302d353962356435666237363230/) LINE Botの画面 ![キャプションを入力できます](https://camo.elchika.com/681de80ba535e0505e270fbf04fb0303348fa222/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f65306661366265332d633431372d346430352d613764372d3532633938646565633766662f66383164383436352d623461662d343530662d613933382d303636333732333430316237/) 家の鍵にRFIDのタグを付け、キーボックスに出し入れする際にRFIDリーダーにタッチすることで誰の鍵が持ち出されたか、入れられたかを検知しています。焦電センサーで、人がいるかいないか # 部品 | 品名 | 個数 | 購入先 | |:---:|:---|:---| | Raspberry Pi Pico W | 1 | https://www.switch-science.com/products/8171 | | Pi Pico v1.0用Grove シールド | 1 | https://www.switch-science.com/products/7109 | | GROVE - デジタル温度・湿度センサ(DHT20) | 1 | https://www.switch-science.com/products/7946 | | GROVE - ミニPIRモーションセンサ | 1 | https://www.switch-science.com/products/3584 | | M5Stack用WS1850S搭載 RFID 2ユニット | 1 | https://www.switch-science.com/products/8301 | | GROVE - ロードセル用ADコンバータモジュール(HX711) | 1 | https://www.switch-science.com/products/8534 | | Grove - Wrapper 1 x 2 青(4個パック)| 1 | https://www.switch-science.com/products/6999 (実際に使用しているのは緑) | | Grove - Wrapper 1 x 1 青(4個パック)| 1 | https://www.switch-science.com/products/6998 (実際に使用しているのは緑) | | ロードセル シングルポイント(ビーム型) 2kg | 1 | 秋月電子 販売コード:113041(他のものでもOK) | | アクリル板、ネジ等 | - | 100円ショップなど | # 必要な環境 - [Arduino IDE](https://www.arduino.cc/en/software/) 今回使用しているのは、v2.3.3 - [enebular](https://www.enebular.com/ja/)のアカウント及びプロジェクト(無料の範囲でOK) - [LINE公式アカウント](https://entry.line.biz/start/jp/)(無料枠でOK) # 設計図 ## センサーキーボックス配線図 ![キャプションを入力できます](https://camo.elchika.com/7c32d792c52ce0853104af1c1a8a387c752e0360/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f65306661366265332d633431372d346430352d613764372d3532633938646565633766662f32663461346234362d396135612d346163642d613936342d646264353431366233316334/) ## 構成図 ![キャプションを入力できます](https://camo.elchika.com/2c98b3783e76b295b8baab761da1c920544452ba/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f65306661366265332d633431372d346430352d613764372d3532633938646565633766662f64633732303765632d646433312d343135662d396634342d343734316562373132623932/) # ソースコード ## センサーキーボックス(Arduino) ### ボード定義 - [Arduino-pico](https://github.com/earlephilhower/arduino-pico) v4.1.1 ### 使用しているライブラリ - [PicowGuidebook](https://github.com/jksoft-main/PicowGuidebook) v1.1.0 - [HX711 Arduino Library](https://github.com/bogde/HX711) v0.7.5 - [Grove_Temperature_And_Humidity_Sensor](https://github.com/Seeed-Studio/Grove_Temperature_And_Humidity_Sensor) v2.0.2 - [MFRC522_I2C](https://github.com/kkloesener/MFRC522_I2C) v1.0 ### スケッチ ```c++ #include "ConnectWifi.h" #include <HTTPClient.h> #include "HX711.h" #include "DHT.h" #include "MFRC522_I2C.h" // クラウド実行環境のパス #define ENEBULAR_CLOUD_PATH "--- クラウド実行環境のパスを記入 ---" // センサー値をPOSTするURL #define SENSOR_POST_URL "https://lcdp002.enebular.com/" ENEBULAR_CLOUD_PATH "/sensor" // キーの値をPOSTするURL #define KEY_POST_URL "https://lcdp002.enebular.com/" ENEBULAR_CLOUD_PATH "/key" // ロードセル用変換回路が接続されているピン const int HX711_DOUT_PIN = 19; const int HX711_SCK_PIN = 18; // 人感センサーが接続されているピン const int PIR_SENSOR_PIN = 20; // 温湿度センサDHT20のI2Cピン const int DHT20_SDA_PIN = 8; const int DHT20_SCL_PIN = 9; // RFIDリーダのI2Cピン const int RFID_SDA_PIN = 6; const int RFID_SCL_PIN = 7; // センサー値をPOSTする間隔 const unsigned long interval = 3000000; ConnectWifi connect; HX711 scale; DHT dht20(DHT20); MFRC522_I2C *mfrc522; // 基準の重さ long baseScale = 0; // 最後にタッチされたRFID char lastTouchId[256] = ""; // 最後に処理を実行した時間を記録 unsigned long previousMillis = millis() + interval; // センサーをクラウドにPOSTする関数 void sensorPost( float temperature, float humidity ){ if(connect.isConnected()){ HTTPClient https; https.setInsecure(); if (https.begin(SENSOR_POST_URL)) { https.addHeader("Content-Type", "application/json"); char body[256]; sprintf(body,"["); sprintf(body+strlen(body),"{\"key\":\"temperature\",\"name\":\"室内気温\",\"value\":%5.1f,\"unit\":\"℃\"},",temperature); sprintf(body+strlen(body),"{\"key\":\"humidity\",\"name\":\"室内湿度\",\"value\":%5.1f,\"unit\":\"%\"}",humidity); sprintf(body+strlen(body),"]"); Serial.println(body); int status = https.POST(body); if (status == 200){ Serial.println("センサー値POST成功"); } else { Serial.printf("センサー値POST失敗:%d", status); } https.end(); } } } // キーをクラウドにPOSTする関数 void keyPost( char* id, bool isAtHome ){ if(connect.isConnected()){ HTTPClient https; https.setInsecure(); if (https.begin(KEY_POST_URL)) { https.addHeader("Content-Type", "application/json"); char body[256]; sprintf(body,"{"); sprintf(body+strlen(body),"\"userId\":\"%s\",\"value\":%s",id,isAtHome ? "true" : "false"); sprintf(body+strlen(body),"}"); Serial.println(body); int status = https.POST(body); if (status == 200){ Serial.println("キー値POST成功"); } else { Serial.printf("キー値POST失敗:%d", status); } https.end(); } } } void setup() { delay(2000); // PicoのLEDピンを出力に設定 pinMode(LED_BUILTIN, OUTPUT); // 焦電センサー用のピンを入力に設定 pinMode(PIR_SENSOR_PIN, INPUT); // 重量センサーの初期設定 scale.begin(HX711_DOUT_PIN, HX711_SCK_PIN); // 温湿度センサーDHT20初期化 Wire.setSDA(DHT20_SDA_PIN); Wire.setSCL(DHT20_SCL_PIN); Wire.begin(); dht20.begin(); // RFIDリーダ初期化 Wire1.setSDA(RFID_SDA_PIN); Wire1.setSCL(RFID_SCL_PIN); Wire1.begin(); mfrc522 = new MFRC522_I2C(0x28,1,&Wire1); mfrc522->PCD_Init(); // Wi-Fiに接続 connect.begin(); } void loop() { // 現在の経過時間を取得 unsigned long currentMillis = millis(); // 定期的にセンサー値をPOST if (currentMillis - previousMillis >= interval) { // 現在の時間を記録 previousMillis = currentMillis; // 温度を読み込み float temperature = dht20.readTemperature(); // 湿度を読み込み float humidity = dht20.readHumidity(); // センサー値をPOST sensorPost(temperature,humidity); } // RFIDリーダーにRFIDがタッチされたらIDを保持する if(mfrc522->PICC_IsNewCardPresent() && mfrc522->PICC_ReadCardSerial()) { sprintf(lastTouchId, ""); for (byte i=0; i<mfrc522->uid.size; i++) { char tmp[2]; sprintf(tmp, "%02X", mfrc522->uid.uidByte[i]); strcat(lastTouchId, tmp); } // 重量の基準としてを保持 baseScale = scale.read(); // LEDを点灯 digitalWrite(LED_BUILTIN,HIGH); } // 重量センサーが正常かつ、RFIDがタッチ済み、人が離れたらPOSTする if (scale.is_ready()) { bool keyStatus = false; static bool pirSensingKeyStatus = false; // 重量センサー値を読み込み long reading = scale.read(); // 基準との差分を計算 long difference = abs(reading - baseScale); // 人感センサーの状態を読み込み int pirSensor = digitalRead(PIR_SENSOR_PIN); if(pirSensor == LOW && strcmp(lastTouchId,"") != 0){ // POST時に重量センサーが変化していたら在宅、していなかったら外出として扱う bool isAtHome = constrain(difference, -2000,2000) != difference; // キーのIDと在宅状態をクラウドへPOST keyPost(lastTouchId,isAtHome); sprintf(lastTouchId, ""); digitalWrite(LED_BUILTIN,LOW); } } delay(200); } ``` ## クラウド実行環境(enebular) ### 追加でインストールしたノード - [enebular-privatenode-contrib-ee-connect-v2](https://enebular.com/discover/privatenode/a34b2986-5340-488a-b89e-220e54ba9970)(基本、enebularのプロジェクト作成時に自動的に追加される) - [enebular-privatenode-contrib-lcdp-toolkit](https://enebular.com/discover/privatenode/7861b7c9-35cd-4ad7-bb0a-840251568a8d)(基本、enebularのプロジェクト作成時に自動的に追加される) - [node-red-contrib-line-messaging-api](https://flows.nodered.org/node/node-red-contrib-line-messaging-api)(パレット管理から追加) ### フロー ![キャプションを入力できます](https://camo.elchika.com/5dc3bfae3d77f0aa49fb7097d474dc457e00ef1e/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f65306661366265332d633431372d346430352d613764372d3532633938646565633766662f64663031333431632d303164622d346635662d383835362d303937386130373962353736/) ```json [{"id":"1eb01f482bb8b6b6","type":"tab","label":"フロー1","disabled":false,"info":"","env":[]},{"id":"35a42226c71c17b7","type":"subflow","name":"HTTPin","info":"","category":"","in":[],"out":[{"x":860,"y":80,"wires":[{"id":"637bfc289390744a","port":0}]}],"env":[],"meta":{},"color":"#DDAA99"},{"id":"c4283138f2a1c1ca","type":"subflow","name":"HTTPresponse","info":"","category":"","in":[{"x":20,"y":120,"wires":[{"id":"c5dda3b91d42d701"},{"id":"257d3d9216ceca4d"}]}],"out":[],"env":[],"meta":{},"color":"#DDAA99"},{"id":"508a86ca1b4616ef","type":"junction","z":"1eb01f482bb8b6b6","x":1560,"y":680,"wires":[["148723647c61c823"]]},{"id":"148723647c61c823","type":"junction","z":"1eb01f482bb8b6b6","x":2020,"y":680,"wires":[["3d022fb764cc4319"]]},{"id":"53c913709dfa7762","type":"datastore-config","name":"datastore-config","tableIdType":"env","tableIdConstValue":"TABLE_ID"},{"id":"f2b7414ec88b5e9b","type":"LCDP-in","z":"35a42226c71c17b7","name":"","x":190,"y":80,"wires":[["06429d018802bf34"]]},{"id":"c80e65f536b5a4f5","type":"httpin","z":"35a42226c71c17b7","name":"","url":"/line-bot","method":"post","upload":false,"swaggerDoc":"","x":210,"y":220,"wires":[["06429d018802bf34"]]},{"id":"637bfc289390744a","type":"function","z":"35a42226c71c17b7","name":"最後のパスを抽出","func":"consturl=msg.req.url;\nconstpaths=url.split('/');\nconsttmpPath=paths.filter(Boolean).pop();\nconstlastPath=tmpPath?.split('?')[0]??tmpPath;\n\nmsg.lastPath=lastPath;\n\nreturnmsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":80,"wires":[[]]},{"id":"088baf956f61e8ee","type":"httpin","z":"35a42226c71c17b7","name":"","url":"/sensor","method":"post","upload":false,"swaggerDoc":"","x":210,"y":180,"wires":[["06429d018802bf34"]]},{"id":"16a508f3e58dcb55","type":"httpin","z":"35a42226c71c17b7","name":"","url":"/key","method":"post","upload":false,"swaggerDoc":"","x":200,"y":140,"wires":[["06429d018802bf34"]]},{"id":"06429d018802bf34","type":"switch","z":"35a42226c71c17b7","name":"POSTのみ","property":"req.method","propertyType":"msg","rules":[{"t":"eq","v":"POST","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":490,"y":80,"wires":[["637bfc289390744a"]]},{"id":"257d3d9216ceca4d","type":"httpresponse","z":"c4283138f2a1c1ca","name":"","statusCode":"","headers":{},"x":170,"y":160,"wires":[]},{"id":"5e1a93a3fec415c3","type":"LCDP-out","z":"c4283138f2a1c1ca","name":"","x":330,"y":80,"wires":[]},{"id":"c5dda3b91d42d701","type":"switch","z":"c4283138f2a1c1ca","name":"","property":"uhuru","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":170,"y":80,"wires":[["5e1a93a3fec415c3"]]},{"id":"39ca4c5404052469","type":"complete","z":"1eb01f482bb8b6b6","name":"","scope":["b9229fe4c91b8aa1"],"uncaught":false,"x":1970,"y":520,"wires":[["3d022fb764cc4319"]]},{"id":"b9229fe4c91b8aa1","type":"ReplyMessage","z":"1eb01f482bb8b6b6","name":"","replyMessage":"","x":2180,"y":400,"wires":[]},{"id":"9b9c489aa87d6a09","type":"change","z":"1eb01f482bb8b6b6","name":"必要な情報を抽出","rules":[{"t":"set","p":"line","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"line.event","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"line.event","pt":"msg","to":"payload.events[0]","tot":"msg"},{"t":"set","p":"ts","pt":"msg","to":"payload.events[0].timestamp","tot":"msg"},{"t":"set","p":"userId","pt":"msg","to":"payload.events[0].source.userId","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"payload.events[0].message","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1030,"y":400,"wires":[["21e823fc7784eac2"]]},{"id":"91fc14fc26558c29","type":"switch","z":"1eb01f482bb8b6b6","name":"最後のパスで分岐","property":"lastPath","propertyType":"msg","rules":[{"t":"eq","v":"line-bot","vt":"str"},{"t":"eq","v":"sensor","vt":"str"},{"t":"eq","v":"key","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":750,"y":520,"wires":[["9b9c489aa87d6a09"],["b809eada7be4dbfa"],["dccbcf2d7fc9bfa0"]]},{"id":"44ae644ea70d582d","type":"subflow:35a42226c71c17b7","z":"1eb01f482bb8b6b6","name":"","x":560,"y":520,"wires":[["91fc14fc26558c29"]]},{"id":"21e823fc7784eac2","type":"switch","z":"1eb01f482bb8b6b6","name":"messageのみ","property":"line.event.type","propertyType":"msg","rules":[{"t":"eq","v":"message","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1220,"y":400,"wires":[["e4c88cda7cbd52a6"]]},{"id":"e4c88cda7cbd52a6","type":"switch","z":"1eb01f482bb8b6b6","name":"textのみ","property":"payload.type","propertyType":"msg","rules":[{"t":"eq","v":"text","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1380,"y":400,"wires":[["3e9a215180d256b7"]]},{"id":"3e9a215180d256b7","type":"switch","z":"1eb01f482bb8b6b6","name":"","property":"payload.text","propertyType":"msg","rules":[{"t":"eq","v":"環境は?","vt":"str"},{"t":"eq","v":"誰が居る?","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1510,"y":400,"wires":[["64f5f17cb123bf84"],["dd4c5cb1af09135e"]]},{"id":"64f5f17cb123bf84","type":"ds-easy-query-item","z":"1eb01f482bb8b6b6","name":"","inParams_tableIdType":"msg","inParams_mainKeyName":"type","inParams_mainKeyNameType":"str","inParams_mainKeyNameConstValue":"","inParams_mainKey":"sensor","inParams_mainKeyType":"str","inParams_mainKeyConstValue":"","inParams_subKeyName":"userId","inParams_subKeyNameType":"str","inParams_subKeyNameConstValue":"","inParams_subKeySelect":"less-than-or-equal-to","inParams_subKeySelectConstValue":"less-than-or-equal-to","inParams_subKey":"","inParams_subKeyType":"str","inParams_subKeyConstValue":"","inParams_subKey2":"subKey2","inParams_subKey2Type":"msg","inParams_subKey2ConstValue":"subKey2","inParams_orderSelect":"asc","inParams_orderSelectConstValue":"asc","inParams_limit":"limit","inParams_limitType":"msg","inParams_limitConstValue":"limit","inParams_startKey":"startKey","inParams_startKeyType":"msg","inParams_startKeyConstValue":"startKey","outParams1_destOfGottenItemsType":"msg","outParams1_destOfGottenItemsConstValue":"dsData","outParams1_destOfStartKeyType":"msg","outParams1_destOfStartKeyConstValue":"startKey","datastoreConfig":"53c913709dfa7762","x":1700,"y":380,"wires":[["e66c3985226e2cc2"]]},{"id":"e66c3985226e2cc2","type":"function","z":"1eb01f482bb8b6b6","name":"環境の返信用文章を作成","func":"letpayload=\"\";\n\nmsg.dsData.forEach(function(element){\npayload+=element.name;\npayload+=\"は\";\npayload+=element.value;\npayload+=element.unit;\npayload+=\"\"\n});\n\nif(payload!==\"\"){\npayload+=\"です\"\n}else{\npayload=\"情報がありません\"\n}\n\nmsg.payload=payload;\n\nreturnmsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1930,"y":380,"wires":[["b9229fe4c91b8aa1"]]},{"id":"dd4c5cb1af09135e","type":"ds-easy-query-item","z":"1eb01f482bb8b6b6","name":"","inParams_tableIdType":"msg","inParams_mainKeyName":"type","inParams_mainKeyNameType":"str","inParams_mainKeyNameConstValue":"","inParams_mainKey":"","inParams_mainKeyType":"str","inParams_mainKeyConstValue":"","inParams_subKeyName":"userId","inParams_subKeyNameType":"str","inParams_subKeyNameConstValue":"","inParams_subKeySelect":"less-than-or-equal-to","inParams_subKeySelectConstValue":"less-than-or-equal-to","inParams_subKey":"","inParams_subKeyType":"str","inParams_subKeyConstValue":"","inParams_subKey2":"subKey2","inParams_subKey2Type":"msg","inParams_subKey2ConstValue":"subKey2","inParams_orderSelect":"asc","inParams_orderSelectConstValue":"asc","inParams_limit":"limit","inParams_limitType":"msg","inParams_limitConstValue":"limit","inParams_startKey":"startKey","inParams_startKeyType":"msg","inParams_startKeyConstValue":"startKey","outParams1_destOfGottenItemsType":"msg","outParams1_destOfGottenItemsConstValue":"dsData","outParams1_destOfStartKeyType":"msg","outParams1_destOfStartKeyConstValue":"startKey","datastoreConfig":"53c913709dfa7762","x":1700,"y":420,"wires":[["322c19790e158947"]]},{"id":"322c19790e158947","type":"function","z":"1eb01f482bb8b6b6","name":"誰が居るの返信用文章を作成","func":"letpayload=\"\";\n\nmsg.dsData.forEach(function(element){\nif(element.type===\"key\"&&element.value){\nconstnames=msg.dsData.filter((data)=>data.type===\"name\"&&data.userId===element.userId);\npayload+=names[0].value;\npayload+=\"\";\n}\n});\n\nif(payload!==\"\"){\npayload+=\"が居ます\"\n}else{\npayload=\"誰もいません\"\n}\n\nmsg.payload=payload;\n\nreturnmsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1940,"y":420,"wires":[["b9229fe4c91b8aa1"]]},{"id":"3d022fb764cc4319","type":"subflow:c4283138f2a1c1ca","z":"1eb01f482bb8b6b6","name":"","x":2180,"y":520,"wires":[]},{"id":"09b707183301f9f2","type":"comment","z":"1eb01f482bb8b6b6","name":"LINEBot応答用の文章を作成","info":"","x":1060,"y":360,"wires":[]},{"id":"aded02cfbc997857","type":"ds-put-item","z":"1eb01f482bb8b6b6","name":"","inParams_tableIdType":"msg","inParams_puttingItem":"item","inParams_puttingItemType":"msg","inParams_puttingItemConstValue":"item","outParams1_destOfputItemType":"msg","outParams1_destOfputItemConstValue":"result","datastoreConfig":"53c913709dfa7762","x":1820,"y":580,"wires":[["04a2def1d546705d"]]},{"id":"b809eada7be4dbfa","type":"function","z":"1eb01f482bb8b6b6","name":"DSに書き込むデータに変換","func":"letitems=[];\n\nmsg.payload.forEach(function(element,index){\nitems[index]={\ntype:\"sensor\",\nuserId:element.key,\nname:element.name,\nvalue:element.value,\nunit:element.unit\n};\n});\n\nmsg.items=items;\n\nreturnmsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1060,"y":580,"wires":[["f0e9ee67b738820c"]]},{"id":"f0e9ee67b738820c","type":"change","z":"1eb01f482bb8b6b6","name":"","rules":[{"t":"set","p":"count","pt":"msg","to":"0","tot":"num"},{"t":"set","p":"countMax","pt":"msg","to":"items.length","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1280,"y":580,"wires":[["557448558a643b3a"]]},{"id":"557448558a643b3a","type":"switch","z":"1eb01f482bb8b6b6","name":"","property":"count","propertyType":"msg","rules":[{"t":"lt","v":"countMax","vt":"msg"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1450,"y":580,"wires":[["4d18fe239ce3709f"],["508a86ca1b4616ef"]]},{"id":"4d18fe239ce3709f","type":"change","z":"1eb01f482bb8b6b6","name":"","rules":[{"t":"set","p":"item","pt":"msg","to":"items[msg.count]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1630,"y":580,"wires":[["aded02cfbc997857"]]},{"id":"04a2def1d546705d","type":"change","z":"1eb01f482bb8b6b6","name":"","rules":[{"t":"set","p":"count","pt":"msg","to":"count+1","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1620,"y":520,"wires":[["557448558a643b3a"]]},{"id":"dccbcf2d7fc9bfa0","type":"change","z":"1eb01f482bb8b6b6","name":"","rules":[{"t":"set","p":"item","pt":"msg","to":"{\t\"type\":\"key\",\t\"userId\":payload.userId,\t\"value\":payload.value\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1010,"y":680,"wires":[["984ea06e223de6f4"]]},{"id":"984ea06e223de6f4","type":"ds-put-item","z":"1eb01f482bb8b6b6","name":"","inParams_tableIdType":"msg","inParams_puttingItem":"item","inParams_puttingItemType":"msg","inParams_puttingItemConstValue":"item","outParams1_destOfputItemType":"msg","outParams1_destOfputItemConstValue":"result","datastoreConfig":"53c913709dfa7762","x":1200,"y":680,"wires":[["508a86ca1b4616ef"]]},{"id":"fe1e3ee72be93985","type":"catch","z":"1eb01f482bb8b6b6","name":"","scope":["64f5f17cb123bf84","dd4c5cb1af09135e","aded02cfbc997857","984ea06e223de6f4"],"uncaught":false,"x":1750,"y":760,"wires":[["1d0955d103e89c0d"]]},{"id":"1d0955d103e89c0d","type":"change","z":"1eb01f482bb8b6b6","name":"","rules":[{"t":"set","p":"statusCode","pt":"msg","to":"500","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1940,"y":760,"wires":[["3d022fb764cc4319"]]},{"id":"64da13dbfaa6ab36","type":"comment","z":"1eb01f482bb8b6b6","name":"センサー値をDSに保存","info":"","x":1040,"y":540,"wires":[]},{"id":"bb7202fd4adab46c","type":"comment","z":"1eb01f482bb8b6b6","name":"キー値をDSに保存","info":"","x":1030,"y":640,"wires":[]},{"id":"b572fb4bcd01c726","type":"comment","z":"1eb01f482bb8b6b6","name":"エラーの場合は、500","info":"","x":1800,"y":720,"wires":[]}] ``` ### フローの変更箇所 - Replyノードのプロパティで、以下を設定して下さい - Secret:自分のLINE公式チャンネルのチャネルシークレット - Access Token:自分のLINE公式チャンネルのMessaging APIのチャネルアクセストークン ![キャプションを入力できます](https://camo.elchika.com/bb54431b03e83a95e9f39474aca78ac39c33d160/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f65306661366265332d633431372d346430352d613764372d3532633938646565633766662f31623162383065642d386635362d343931622d393432632d656465336232666336613131/) ### データストアの設定 - テーブル名:任意 - テーブルの種類:カスタム設定 - メインキー名:type - サブキー: - サブキー名:userId - データ型:文字列 ### クラウド実行環境の設定(デフォルトからの変更箇所のみ) - 名称:任意 - HTTPトリガー: - 状態:ON - URLのパス:任意の文字列(このURLを自分のLINE公式チャンネルのMessaging APIのWebhook URL及びArduinoスケッチに設定して下さい) - データストアへの接続: - 状態:ON - 環境変数: - キー:TABLE_ID - 値:作成したデータストアのID