Ambientに送信して完成。 10分動いてなかったらPower offする機能も追加。
static void transfer_task(void*) { Ambient ambient; unsigned long sent_at = millis(); WiFiMulti wifiMulti; WiFiClient client; int power_off_count = 0; int power_off_min = 10; WiFi.disconnect(); WiFi.softAPdisconnect(true); WiFi.mode(WIFI_STA); wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD); #ifdef WIFI_SSID2 wifiMulti.addAP(WIFI_SSID2, WIFI_PASSWORD2); #endif #ifdef WIFI_SSID3 wifiMulti.addAP(WIFI_SSID3, WIFI_PASSWORD3); #endif ambient.begin(AMBIENT_CHANNEL_ID, AMBIENT_WRITE_KEY, &client); while(true) { if (wifiMulti.run() == WL_CONNECTED) { unsigned long now = millis(); if (now - sent_at >= 60000) { if (num_of_steps < 15) { if (++power_off_count >= power_off_min) { M5.Power.powerOff(); } } else { power_off_count = 0; } ambient.set(1, num_of_steps); ambient.send(); num_of_steps = 0; sent_at = now; } } } }