#include <M5StickCPlus.h>
#include <WiFi.h>
#include <HTTPClient.h>
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();
}