Skip to content

Instantly share code, notes, and snippets.

@Drunkar
Last active February 13, 2024 15:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Drunkar/95b8520053f3850376671fe7778f25f0 to your computer and use it in GitHub Desktop.
Save Drunkar/95b8520053f3850376671fe7778f25f0 to your computer and use it in GitHub Desktop.
PanasonicのドアベルVL-MWD501が鳴ったときにslackに通知します。slackはincoming webhookで投稿します。参考: https://qiita.com/yomori/items/ca213f1087c2a0e270e1#%E3%83%89%E3%82%A2%E3%83%9B%E3%83%B3%E3%81%8C%E9%B3%B4%E3%81%A3%E3%81%9F%E3%82%89googlehomeslackdiscord%E3%81%AB%E9%80%9A%E7%9F%A5%E3%81%99%E3%82%8B
#include <M5StickC.h>
#include <WiFi.h>
#include <ssl_client.h>
#include <HTTPClient.h>
#define PIN_SW 26
const char* ssid = "ssid";
const char* password = "pass";
const char* WEBHOOK_URL = "url";
bool is_calling = false;
int ncTimer = 0;
void setup() {
M5.begin();
M5.Lcd.setRotation(1);
Serial.begin(115200);
// 画面の輝度を下げる
M5.Axp.ScreenBreath(8);
// CPUの動作周波数を80MHzに設定 (80MHz未満ではWi-Fi使用不可)
setCpuFrequencyMhz(80);
delay(100);
// 無線LANへ接続
Serial.println("Connecting to ");
Serial.print(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi Connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
pinMode(PIN_SW,INPUT_PULLUP);
}
void loop() {
static int swBefore=1;
bool sw = digitalRead(PIN_SW);
Serial.println(sw);
if( sw != swBefore && !is_calling){
postMessage("来客です。");
is_calling = true;
}
if (sw == swBefore) {
is_calling = false;
}
if (WiFi.status() != WL_CONNECTED){
ncTimer++;
if (ncTimer > 60){
ESP.restart();
}
delay(1000);
}
else{
ncTimer = 0;
}
delay(10);
}
void postMessage(const char* message) {
HTTPClient http;
if (http.begin(WEBHOOK_URL))
{
String payload = String("{'text':'") + message + "'}"; //INPUT your original message
int httpCode = http.POST(payload);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment