diff --git "a/\343\202\242\343\202\244\343\203\225\343\202\251\343\203\263\343\201\253\351\200\201\344\277\241" "b/\343\202\242\343\202\244\343\203\225\343\202\251\343\203\263\343\201\253\351\200\201\344\277\241" new file mode 100644 index 0000000..5168166 --- /dev/null +++ "b/\343\202\242\343\202\244\343\203\225\343\202\251\343\203\263\343\201\253\351\200\201\344\277\241" @@ -0,0 +1,59 @@ +#include +#include +#include + +const char* ssid = "elecom-a12f93"; // Wi-FiのSSID +const char* password = "9mrrywicmcfw"; // Wi-Fiのパスワード + +const char* lineToken = "GtaU4mxp7uxldFgS28s606Xpk86lVGgd5DtdS2CvexQ"; // Line Notifyのトークン + +void setup() { + M5.begin(); + Wire.begin(0, 26); + Wire1.begin(32, 33); + + // Wi-Fi接続 + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(1000); + Serial.println("Connecting to WiFi..."); + } + Serial.println("Connected to WiFi"); + + Serial.println("Setup complete"); +} + +void loop() { + M5.update(); + // ボタンAが押されたらLine Notifyに通知を送信 + if (M5.BtnA.wasReleased()) { + sendLineNotify("ボタンAが押されました!"); + } + + delay(100); +} + +void sendLineNotify(String message) { + HTTPClient http; + + // Line NotifyにPOSTリクエストを送信 + http.begin("https://notify-api.line.me/api/notify"); + http.addHeader("Content-Type", "application/x-www-form-urlencoded"); + http.addHeader("Authorization", "Bearer " + String(lineToken)); + + // メッセージを設定 + String data = "message=" + message; + + // リクエストを送信 + int httpResponseCode = http.POST(data); + + // レスポンスを確認 + if (httpResponseCode == 200) { + Serial.println("Line Notify: Message sent successfully"); + } else { + Serial.print("Line Notify: Error sending message. HTTP response code: "); + Serial.println(httpResponseCode); + } + + http.end(); +}