Newer
Older
M5StickCPlus_FactoryTest2022 / SampleSrc / line01.ino
#include <WiFi.h>
#include <WiFiMulti.h>
#include <WiFiClient.h>
#include <HTTPClient.h>

WiFiMulti WiFiMulti;

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFiMulti.addAP("ics-ap", "jikkenics");

  // wait for WiFi connection
  Serial.print("Waiting for WiFi to connect...");
  while ((WiFiMulti.run() != WL_CONNECTED)) {
    Serial.print(".");
    delay(50);
  }
  Serial.println(" connected");
}

void loop() {
  HTTPClient http;

  if (http.begin("https://notify-api.line.me/api/notify")) {  // HTTPS
    http.addHeader("Authorization", "Bearer TOKENTOKENTOKEN"); // ここのTOKENTOKEN... の部分に、取得したTokenを指定する
    http.addHeader("Content-Type", "application/x-www-form-urlencoded"); // format of postdata
    String postdata = "message=日本語でも大丈夫です";
    int httpCode = http.POST(postdata);

    // httpCode will be negative on error
    if (httpCode > 0) {
      // HTTP header has been send and Server response header has been handled
      Serial.printf("[HTTP] GET... code: %d\n", httpCode);

      // file found at server
      if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
        String payload = http.getString();
        Serial.println(payload);
      }
    } else {
      Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
    }
    http.end();
  } else {
    Serial.printf("[HTTP] Unable to connect\n");
  }

  Serial.println();
  Serial.println("Waiting 2 minutes..."); 
  delay(60*2*1000); // 120秒まつ
}