ESP-WROOM-02を使ってLINEでインターホンが鳴ったら通知を受け取る

表題のとおりです。

2階にいるとインターホンが鳴っても聞こえないので作りました。

用意したもの

  • アイホン KL-66
  • ESP-WROOM-02 開発ボード
  • 降圧回路

接続

室内子機の外部スピーカー出力に降圧回路を挟んでESP-WROOM-02のTOUTとGNDを接続

スケッチ

analogReadの閾値は適当に調整してください

#include <ESP8266WiFi.h>

#include <WiFiClientSecure.h>

const char* ssid = “SSID”;

const char* password = “PreSharedKey”;

const char* lineApiToken = “LINENofityToken”;

const char* host = “notify-api.line.me”;

const String url = “/api/notify”;

const int httpsPort = 443;

WiFiClientSecure client;

void setup(){

  client.setInsecure();

  Serial.begin(9600);

  WiFi.mode(WIFI_STA);

  delay(100);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {

    delay(1000);

  }

  delay(1000);

}

void loop(){

  int analog;

  analog = analogRead(A0);

  if(analog > 40){

    String message = “インターホンが鳴っています”;

    lineNotify(message, 0, 0);

    delay(15000);

  }

  delay(200);

}

void lineNotify(String message, int stkpkgid, int stkid){

  if (!client.connect(host, httpsPort)) {

    return;

  }

/*  

  if (!client.verify(fingerprint, host)) {

    return;

  }

*/

  String lineMessage = “message=” + message;

  if((stkid != 0) && (stkpkgid != 0)){

    lineMessage += “&stickerPackageId=”;

    lineMessage += stkpkgid;

    lineMessage += “&stickerId=”;

    lineMessage += stkid;

  }

  String header = “POST ” + url + ” HTTP/1.1\r\n” +

               “Host: ” + host + “\r\n” +

               “User-Agent: ESP8266\r\n” +

               “Authorization: Bearer ” + lineApiToken + “\r\n” +

               “Connection: close\r\n” +

               “Content-Type: application/x-www-form-urlencoded\r\n” +

               “Content-Length: ” + lineMessage.length() + “\r\n”;

  client.print(header);

  client.print(“\r\n”);

  client.print(lineMessage + “\r\n”);

  String res = client.readString();

  client.stop();

}

LINENofityとかはここを参考にしました。というかコピペ

動作

chevron_left
chevron_right

Leave a comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

Comment
Name
Email
Website