Created
April 16, 2020 01:02
-
-
Save TakehikoShimojima/3daee38ef433a78d5b6a43d344a7174d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <M5StickC.h> | |
#include <WiFi.h> | |
#include "Ambient.h" | |
const char* ssid = "ssid"; // この場所のSSID(2.4GHzの) | |
const char* password = "password"; // SSIDに対応するパスワード | |
const char* userKey = "ユーザーキー"; | |
char devKey[20]; | |
unsigned int channelId; | |
char writeKey[20]; | |
WiFiClient client; | |
Ambient am; // Ambientオブジェクトを作る | |
void setup() { | |
M5.begin(); | |
uint8_t mac[6]; | |
esp_read_mac(mac, ESP_MAC_WIFI_STA); // Wi-FiのMACアドレスを取得する | |
sprintf(devKey, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); | |
Serial.println(devKey); | |
WiFi.begin(ssid, password); // Wi-Fi APに接続する | |
while (WiFi.status() != WL_CONNECTED) { // Wi-Fi AP接続待ち | |
delay(500); | |
Serial.print('.'); | |
} | |
Serial.print("\r\nWiFi connected\r\n"); | |
if (am.getchannel(userKey, devKey, channelId, writeKey, sizeof(writeKey), &client) == false) { | |
Serial.printf("Cannot get channelId. Please set DeviceKey (%s) to Ambient.\r\n", devKey); | |
while (true) { | |
delay(0); | |
} | |
} | |
Serial.printf("channelId: %d, writeKey: %s\r\n", channelId, writeKey); | |
am.begin(channelId, writeKey, &client); | |
} | |
void loop() { | |
// センサーを読む | |
am.set(1, 1); // センサーデーターをセットし、 | |
am.send(); // Ambientに送信する | |
delay(5 * 60 * 1000); // 5分待つ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment