Created
July 16, 2021 09:34
-
-
Save izawa/b69f7dcf83ef988025096e95326129a4 to your computer and use it in GitHub Desktop.
kintai.ico
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 利用者の環境によって変更すること | |
#define SSID_NAME "YOUR_SSID" | |
#define SSID_PASSWORD "YOUR_PASSWORD" | |
#define SLACK_HOOK_URL "/services/XXXXXXXXXXX/XXXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX" | |
// slackの仕様変更の際に要変更 | |
#define SLACK_HOST "hooks.slack.com" | |
const char* ca = "-----BEGIN CERTIFICATE-----\n" \ | |
"MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh\n" \ | |
"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" \ | |
"d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD\n" \ | |
"QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT\n" \ | |
"MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j\n" \ | |
"b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG\n" \ | |
"9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB\n" \ | |
"CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97\n" \ | |
"nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt\n" \ | |
"43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P\n" \ | |
"T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4\n" \ | |
"gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO\n" \ | |
"BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR\n" \ | |
"TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw\n" \ | |
"DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr\n" \ | |
"hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg\n" \ | |
"06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF\n" \ | |
"PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls\n" \ | |
"YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk\n" \ | |
"CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=\n" \ | |
"-----END CERTIFICATE-----\n"; | |
#include <M5Stack.h> | |
#include <WiFi.h> | |
#include <HTTPClient.h> | |
boolean working = false; | |
boolean afk = false; | |
int display_width = 0; | |
int display_height = 0; | |
void setup() { | |
M5.begin(); | |
M5.Lcd.clear(); | |
M5.Lcd.fillScreen(BLACK); | |
M5.Lcd.setCursor(0, 0); | |
M5.Lcd.setTextSize(2); | |
display_width = M5.Lcd.width(); | |
display_height = M5.Lcd.height(); | |
M5.Lcd.print("Wifi Connecting"); | |
WiFi.begin(SSID_NAME, SSID_PASSWORD); | |
while (WiFi.status() != WL_CONNECTED){ | |
delay(500); | |
M5.Lcd.print('.'); | |
} | |
M5.Lcd.print("\r\nWiFi connected\r\nIP address: "); | |
M5.Lcd.println(WiFi.localIP()); | |
delay(3000); | |
M5.Lcd.fillRect(0, 0, display_width, display_height, BLACK); | |
// SDカードからフォントのローディング | |
String f24 = "Ricty-Regular24"; | |
M5.Lcd.loadFont(f24, SD); | |
M5.Lcd.drawRect(0, 0, display_width, display_height-2, YELLOW); | |
M5.Lcd.drawRect(50, 50, display_width-100, display_height-120, WHITE); | |
M5.Lcd.drawString("勤怠状況電信くん1号", 40, 10); | |
M5.Lcd.drawString("出勤", 40, display_height-30); | |
M5.Lcd.drawString("離席/復帰", 110, display_height-30); | |
M5.Lcd.drawString("退勤", 230, display_height-30); | |
} | |
void loop() { | |
if (M5.BtnA.pressedFor(500)){ | |
if (!working) { | |
clsMain(); | |
Serial.println("ButtonA pressed for 500ms"); | |
M5.Lcd.drawString("勤務中", 120, 90); | |
slack("{\"text\":\"業務開始\",\"username\":\"kintai\"}"); | |
working = true; | |
} | |
} | |
else if (M5.BtnB.wasPressed()) { | |
if (working && afk){ | |
clsMain(); | |
Serial.println("ButtonB pressed (もどり)"); | |
M5.Lcd.drawString("勤務中", 120, 90); | |
slack("{\"text\":\"もどり\",\"username\":\"kintai\"}"); | |
afk = false; | |
} else if (working && !afk) { | |
clsMain(); | |
Serial.println("ButtonB pressed (離席)"); | |
M5.Lcd.drawString("離席中", 120, 90); | |
slack("{\"text\":\"離席\",\"username\":\"kintai\"}"); | |
afk = true; | |
} | |
} | |
else if (M5.BtnC.pressedFor(500) ) { | |
if (working) { | |
clsMain(); | |
Serial.println("ButtonC pressed for 500ms"); | |
M5.Lcd.drawString("退勤しました", 80, 90); | |
slack("{\"text\":\"業務終了\",\"username\":\"kintai\"}"); | |
working = false; | |
} | |
} | |
M5.update(); | |
} | |
// メインの状態表示部分をクリア | |
void clsMain() { | |
M5.Lcd.fillRect(51, 51, display_width-102, display_height-122, BLACK); | |
} | |
// slackにmsgを投稿 | |
void slack(char* msg) { | |
HTTPClient https; | |
Serial.printf("[HTTPS] SLACK_HOST %s\n", SLACK_HOST); | |
Serial.printf("[HTTPS] SLACK_HOOK_URL %s\n", SLACK_HOOK_URL); | |
https.begin(SLACK_HOST, 443, SLACK_HOOK_URL, ca); | |
https.addHeader("Content-Type", "application/json"); | |
Serial.printf("[HTTPS] messge [%s]\n", msg); | |
int response = https.POST((uint8_t*)msg, strlen(msg)); | |
if (response != HTTP_CODE_OK) { | |
Serial.printf("[HTTPS] response %d\n", response); | |
} | |
https.end(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment