Hardware components | ||||||
![]() |
| × | 1 | |||
![]() |
| × | 3 | |||
![]() |
| × | 1 | |||
Software apps and online services | ||||||
![]() |
| |||||
Hand tools and fabrication machines | ||||||
![]() |
| |||||
Do you have important family or friends who live far away?
You sometimes want to call, email, or get in touch with them.
But in your busy daily life, you tend to forget about them. Has that ever happened to you?
We've created a gadget to help you remember those important people.
1, IntroductionI wanted to make a gadget to display in my room.
Many of the ornaments I have in my room were purchased while traveling.
Looking at them reminds me of my travels.
I thought it would be interesting to have a gadget that would remind me of family and friends who are far away, so I made this piece.
2, How does it workTo remind you of your family and friends, the weather where they live is expressed through light, sound and wind.
Weather information is obtained using the OpenWeather(https://openweathermap.org) API.
By entering location information (latitude and longitude) into M5Stack, it will access the OpenWeather website via WiFi to obtain weather information for that location.
If the received weather information indicates severe weather such as heavy rain, thunder, or a storm, it will be expressed with LED (light), sound, and fan wind.
Rain: LED and Rain sound
Thunder: LED and Thunder sound
Storm: LED and Fan wind
Weather information is updated every 30 minutes.
Also, when entering location information, you can also enter the birthday of someone you want to remember.
When that day arrives, the M5Stack screen will notify you ("Congratulations")
If the change in weather reminds you of family and friends, why not get in touch with them after a long time?
3, HardwareThe equipment configuration is as follows:
- Set up WiFi to connect M5Stack to the internet.
- Create an OpenWeather account.
- MP3 file to play the sound.
- The housing is made using a 3D printer.
- Make a board that connects the LED, power wiring, and signal wiring
- The wind is generated using an M5 fan module.I removed the fan and installed it inside the case so that the wind would flow outside.
- Obtain the latitude and longitude information of the location you want to check the weather. You can find the latitude and longitude on Google Maps.
- Enter latitude and longitude using the M5Stack buttons (+, -, Enter).
- Enter the anniversary date.
- Once you've finished entering the information, you're done. If there are any changes in the weather, this gadget will notify you with light and sound. The weather is updated every 30 minutes.
- If you notice a light or sound, why not contact a family member or friend? It will be a happy occasion for both of you to have a conversation after a long time.
*Transration(Japanese)
●ストーリー
遠くに住んでいる、大切な家族や友人はいますか?
たまに電話をしたり、メールを出したり、連絡をしたくなるような。
しかし忙しい日常でその友人の事をわすれてしまう。そんなことはありませんか?
そのような大切な人の事を思い出すためにこのガジェットを作りました。
1, イントロダクション部屋に飾るガジェットを作りたいと思いました。
部屋に飾っているオーナメントは、旅行先で購入したものが多いです。
それを見ると、旅の事を思い出します。
そのように遠くにいる家族や友人を思い出すきっかけとなるガジェットがあれば面白いのではないかと思い、この作品を作りました。
2, 動作の説明家族や友人を思い出すきっかけとして、その人たちが住んでいる場所の天気を光や音、風で表現します。
天気情報の取得にはOpenWeather(https://openweathermap.org) のAPIを使用します。
場所の情報(緯度、経度)をM5Stackに入力すると、WiFiでOpenWeatherのサイトにアクセスして、その場所の天気情報を入手します。
入手した天候情報が、大雨、雷、嵐等激しい天候の場合、それをLEDと音声, ファンの風で表現します。
雨:LEDと雨音
雷:LEDと雷音
風:LEDとファンの風
天気情報は30分ごとに更新します。
また、場所の情報を入力する時に、思い出したい相手の誕生日等も入力しておきます。その日が来たらM5Stackの画面で知らせてくれます("Congratulations")
天候の変化で家族や友人の事を思い出したら、久しぶりに連絡を取ってみるのはどうでしょうか?
3, ハードウエア機器構成は上の画像を参照ください。
4, 使い方4.1, 事前準備・M5Stackをインターネットに繋ぐためWiFiの設定が必要になります。
・OpenWeatherのアカウントを作成する必要があります
・音を鳴らすためのMP3ファイルが必要になります。
4.2, 組立・筐体は3Dプリンタで作成します。
・LEDと電源線、M5StackのI/Oピン配線を載せた基板を作ります。
・風はM5のファンモジュールを使って発生させます。風が外部に流れるようにファンを外して筐体側に取り付けました。
4.3, 使い方1, 天気を調べたい場所の緯度、経度情報を入手します。緯度、経度はGoogleMapで調べる事が出来ます
2, 緯度と経度を入力します。入力はM5Stackの三つのボタン(+, -, Enter)を使います。
3, 記念日を入力します(記念日になると画面にCongraturationと表示されます)
4, 入力を終えたら終了です。あとは設定した場所で天気の変動があった場合に光や音であなたにお知らせします。天候の情報は30分ごとに更新されます。
5, 光や音に気づいたら、家族や友人に連絡を取ってみてはいかがでしょうか?久しぶりの会話はお互いにとって嬉しい出来事になるはずです♪
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <TimeLib.h>
#include "SD.h"
#include <M5Unified.h>
#include <m5_module_fan.hpp>
// Path of the WAV file on the TF card
static constexpr const char* WAV_FILE[] = {"/Thunder.wav","/Rain.wav"};
#define PIN_RAIN 5 //Rain LED_blue
#define PIN_THUNDER 2 //Thunder LED_yellow
#define PIN_WIND 26 //Wind LED_white
String pumi ="+";
float lata = 0;
int lats[6]={1,3,6,0,0,0};
float lona = 0;
int lons[7]={1,1,3,9,5,5,7};
int a = 36;
int iti = 0;
int id = 0;
int btd[2]={12,31};
int btdtr = 0;
int bdmt = 6;
int bdday = 20;
int bdhour =1;
int repeats_rain=0;
int repeats_thunder=0;
int repeats_wind = 0;
const char *ssid = "YOUR SSID"; //Wi-Fi setting
const char *password = "PASSWORD"; //Wi-Fi setting
const String endpoi1 = "https://api.openweathermap.org/data/3.0/onecall?lat=";
const String endpoi2 = "&lon=";
const String endpoi3 = "&exclude=curent&appid=";
const String key = "OPEN WEATHER API KEY"; //OpenWeather API-key
String endpoi4 ="";
String endpoi5 ="";
// Fan Module Instance
M5ModuleFan moduleFan;
// Fan module I2C address
uint8_t deviceAddr = MODULE_FAN_BASE_ADDR;
// Fan Duty Cycle(0-100%)
uint8_t dutyCycle = 80;
// Fan Status
bool fan_status = true;
//Sound file processing
static constexpr const size_t buf_num = 3;
static constexpr const size_t buf_size = 1024;
static uint8_t wav_data[buf_num][buf_size];
struct __attribute__((packed)) wav_header_t
{
char RIFF[4];
uint32_t chunk_size;
char WAVEfmt[8];
uint32_t fmt_chunk_size;
uint16_t audiofmt;
uint16_t channel;
uint32_t sample_rate;
uint32_t byte_per_sec;
uint16_t block_size;
uint16_t bit_per_sample;
};
struct __attribute__((packed)) sub_chunk_t
{
char identifier[4];
uint32_t chunk_size;
uint8_t data[1];
};
static bool playSdWav(const char* filename)
{
auto file = SD.open(filename);
if (!file) { return false; }
wav_header_t wav_header;
file.read((uint8_t*)&wav_header, sizeof(wav_header_t));
ESP_LOGD("wav", "RIFF : %.4s" , wav_header.RIFF );
ESP_LOGD("wav", "chunk_size : %d" , wav_header.chunk_size );
ESP_LOGD("wav", "WAVEfmt : %.8s" , wav_header.WAVEfmt );
ESP_LOGD("wav", "fmt_chunk_size : %d" , wav_header.fmt_chunk_size);
ESP_LOGD("wav", "audiofmt : %d" , wav_header.audiofmt );
ESP_LOGD("wav", "channel : %d" , wav_header.channel );
ESP_LOGD("wav", "sample_rate : %d" , wav_header.sample_rate );
ESP_LOGD("wav", "byte_per_sec : %d" , wav_header.byte_per_sec );
ESP_LOGD("wav", "block_size : %d" , wav_header.block_size );
ESP_LOGD("wav", "bit_per_sample : %d" , wav_header.bit_per_sample);
if ( memcmp(wav_header.RIFF, "RIFF", 4)
|| memcmp(wav_header.WAVEfmt, "WAVEfmt ", 8)
|| wav_header.audiofmt != 1
|| wav_header.bit_per_sample < 8
|| wav_header.bit_per_sample > 16
|| wav_header.channel == 0
|| wav_header.channel > 2
)
{
file.close();
return false;
}
file.seek(offsetof(wav_header_t, audiofmt) + wav_header.fmt_chunk_size);
sub_chunk_t sub_chunk;
file.read((uint8_t*)&sub_chunk, 8);
ESP_LOGD("wav", "sub id : %.4s" , sub_chunk.identifier);
ESP_LOGD("wav", "sub chunk_size : %d" , sub_chunk.chunk_size);
while(memcmp(sub_chunk.identifier, "data", 4))
{
if (!file.seek(sub_chunk.chunk_size, SeekMode::SeekCur)) { break; }
file.read((uint8_t*)&sub_chunk, 8);
ESP_LOGD("wav", "sub id : %.4s" , sub_chunk.identifier);
ESP_LOGD("wav", "sub chunk_size : %d" , sub_chunk.chunk_size);
}
if (memcmp(sub_chunk.identifier, "data", 4))
{
file.close();
return false;
}
int32_t data_len = sub_chunk.chunk_size;
bool flg_16bit = (wav_header.bit_per_sample >> 4);
size_t idx = 0;
while (data_len > 0) {
size_t len = data_len < buf_size ? data_len : buf_size;
len = file.read(wav_data[idx], len);
data_len -= len;
if (flg_16bit) {
M5.Speaker.playRaw((const int16_t*)wav_data[idx], len >> 1, wav_header.sample_rate, wav_header.channel > 1, 1, 0);
} else {
M5.Speaker.playRaw((const uint8_t*)wav_data[idx], len, wav_header.sample_rate, wav_header.channel > 1, 1, 0);
}
idx = idx < (buf_num - 1) ? idx + 1 : 0;
}
file.close();
return true;
}
//Sound file processing
void setup() {
auto cfg = M5.config();
cfg.output_power = true;
M5.begin(cfg);
Serial.begin(115200);
M5.Lcd.setTextSize(2);
// Speaker Volume(0-255)
M5.Speaker.setVolume(192);
// GPIO PIN Setting
pinMode(PIN_RAIN, OUTPUT);
pinMode(PIN_THUNDER, OUTPUT);
pinMode(PIN_WIND, OUTPUT);
digitalWrite(PIN_RAIN, LOW);
digitalWrite(PIN_THUNDER, LOW);
digitalWrite(PIN_WIND, LOW);
// Initializing the TF card
if (!SD.begin(GPIO_NUM_4, SPI, 25000000)) {
M5.Lcd.println("TF card initialization failed!");
return;
}
// Initialization Fan module
// I2C Address=deviceAddr、SDA=21、SCL=22、Speed=400000Hz
while (!moduleFan.begin(&Wire1, deviceAddr, 21, 22, 400000)) {
Serial.printf("Module FAN Init faile\r\n");
delay(1000);
}
// Run the fan at 80% duty cycle
moduleFan.setPWMDutyCycle(dutyCycle);
// Set the PWM frequency to 1KHz
moduleFan.setPWMFrequency(PWM_1KHZ);
// Fan Status First turn it OFF.
moduleFan.setStatus(MODULE_FAN_DISABLE);
// Latitude Setting
M5.Lcd.print("Latitude");
M5.Lcd.setCursor(0,40);
M5.Lcd.print(" **.***");
M5.Lcd.setCursor(64,220);
M5.Lcd.print("+ - Enter");
while(lata==0){
while(iti == 0){
M5.update();
M5.Lcd.setCursor(120,40);
M5.Lcd.setCursor(0,40);
M5.Lcd.print(pumi);
if (M5.BtnA.wasPressed()) { //Button A "+"
pumi ="+";
lats[iti]=1;
}
else if(M5.BtnB.wasPressed()) { //Button B "-"
pumi = "-";
lats[iti]=-1;
}
else if (M5.BtnC.wasPressed()) { //Button C "Enter"
M5.Lcd.print(pumi);
iti = 1;
}
}
while(iti == 1){
M5.update();
M5.Lcd.setCursor(12,40);
M5.Lcd.print(lats[iti]);
if (M5.BtnA.wasPressed()) { //Button A CountUP
if(lats[iti]>8){
lats[iti]=9; //Limit
}else{
lats[iti]=lats[iti]+1;
}
}
else if (M5.BtnB.wasPressed()) { //Button B Countdown
if(lats[iti]<1){
lats[iti]=0; //Limit
}else{
lats[iti]=lats[iti]-1;
}
}
else if (M5.BtnC.wasPressed()) {
iti = 2;
}
}
while(iti == 2){
M5.update();
M5.Lcd.setCursor(24,40);
M5.Lcd.print(lats[iti]);
if (M5.BtnA.wasPressed()) {
if(lats[iti]>8){
lats[iti]=9;
}else{
lats[iti]=lats[iti]+1;
}
}
else if (M5.BtnB.wasPressed()) {
if(lats[iti]<1){
lats[iti]=0;
}else{
lats[iti]=lats[iti]-1;
}
}
else if (M5.BtnC.wasPressed()) {
iti = 3;
M5.Lcd.setCursor(36,40);
M5.Lcd.print(".");
}
}
while(iti == 3){
M5.update();
M5.Lcd.setCursor(48,40);
M5.Lcd.print(lats[iti]);
if (M5.BtnA.wasPressed()) {
if(lats[iti]>8){
lats[iti]=9;
}else{
lats[iti]=lats[iti]+1;
}
}
else if (M5.BtnB.wasPressed()) {
if(lats[iti]<1){
lats[iti]=0;
}else{
lats[iti]=lats[iti]-1;
}
}
else if (M5.BtnC.wasPressed()) {
iti = 4;
}
}
while(iti == 4){
M5.update();
M5.Lcd.setCursor(60,40);
M5.Lcd.print(lats[iti]);
if (M5.BtnA.wasPressed()) {
if(lats[iti]>8){
lats[iti]=9;
}else{
lats[iti]=lats[iti]+1;
}
}
else if (M5.BtnB.wasPressed()) {
if(lats[iti]<1){
lats[iti]=0;
}else{
lats[iti]=lats[iti]-1;
}
}
else if (M5.BtnC.wasPressed()) {
iti = 5;
}
}
while(iti == 5){
M5.update();
M5.Lcd.setCursor(72,40);
M5.Lcd.print(lats[iti]);
if (M5.BtnA.wasPressed()) {
if(lats[iti]>8){
lats[iti]=9;
}else{
lats[iti]=lats[iti]+1;
}
}
else if (M5.BtnB.wasPressed()) {
if(lats[iti]<1){
lats[iti]=0;
}else{
lats[iti]=lats[iti]-1;
}
}
else if (M5.BtnC.wasPressed()) {
iti = 6;
}
}
lata = lats[0]*(lats[1]*10+lats[2]+lats[3]*0.1+lats[4]*0.01+lats[5]*0.001);
}
M5.Lcd.clear();
M5.Lcd.setCursor(0,0);
M5.Lcd.print("Latitude = ");
M5.Lcd.print(String(lata,3));
Serial.println(String(lata,3));
delay(500);
// Longitude Setting
M5.Lcd.setCursor(0,60);
M5.Lcd.println("Longitude");
iti = 0;
pumi ="+";
M5.Lcd.setCursor(0,90);
M5.Lcd.print(" ***.***");
M5.Lcd.setCursor(64,220);
M5.Lcd.print("+ - Enter");
while(lona==0){
while(iti == 0){
M5.update();
M5.Lcd.setCursor(140,90);
M5.Lcd.setCursor(0,90);
M5.Lcd.print(pumi);
if (M5.BtnA.wasPressed()) { //Button A "+"
pumi = "+";
lons[iti]=1;
}
else if(M5.BtnB.wasPressed()) { //Button B "-"
pumi = "-";
lons[iti]=-1;
}
else if (M5.BtnC.wasPressed()) { //Button C "Enter"
iti = 1;
}
}
while(iti == 1){
M5.update();
M5.Lcd.setCursor(12,90);
M5.Lcd.print(lons[iti]);
if (M5.BtnA.wasPressed()) {
lons[iti]=1;
}
else if (M5.BtnB.wasPressed()) {
lons[iti]=0;
}
else if (M5.BtnC.wasPressed()) {
iti = 2;
}
}
while(iti == 2){
M5.update();
M5.Lcd.setCursor(24,90);
M5.Lcd.print(lons[iti]);
if (M5.BtnA.wasPressed()) {
if(lons[iti]>8){
lons[iti]=9;
}else{
lons[iti]=lons[iti]+1;
}
}
else if (M5.BtnB.wasPressed()) {
if(lons[iti]<1){
lons[iti]=0;
}else{
lons[iti]=lons[iti]-1;
}
}
else if (M5.BtnC.wasPressed()) {
iti = 3;
}
}
while(iti == 3){
M5.update();
M5.Lcd.setCursor(36,90);
M5.Lcd.print(lons[iti]);
if (M5.BtnA.wasPressed()) {
if(lons[iti]>8){
lons[iti]=9;
}else{
lons[iti]=lons[iti]+1;
}
}
else if (M5.BtnB.wasPressed()) {
if(lons[iti]<1){
lons[iti]=0;
}else{
lons[iti]=lons[iti]-1;
}
}
else if (M5.BtnC.wasPressed()) {
iti = 4;
M5.Lcd.setCursor(48,90);
M5.Lcd.print(".");
}
}
while(iti == 4){
M5.update();
M5.Lcd.setCursor(60,90);
M5.Lcd.print(lons[iti]);
if (M5.BtnA.wasPressed()) {
if(lons[iti]>8){
lons[iti]=9;
}else{
lons[iti]=lons[iti]+1;
}
}
else if (M5.BtnB.wasPressed()) {
if(lons[iti]<1){
lons[iti]=0;
}else{
lons[iti]=lons[iti]-1;
}
}
else if (M5.BtnC.wasPressed()) {
iti = 5;
}
}
while(iti == 5){
M5.update();
M5.Lcd.setCursor(72,90);
M5.Lcd.print(lons[iti]);
if (M5.BtnA.wasPressed()) {
if(lons[iti]>8){
lons[iti]=9;
}else{
lons[iti]=lons[iti]+1;
}
}
else if (M5.BtnB.wasPressed()) {
if(lons[iti]<1){
lons[iti]=0;
}else{
lons[iti]=lons[iti]-1;
}
}
else if (M5.BtnC.wasPressed()) {
iti = 6;
}
}
while(iti == 6){
M5.update();
M5.Lcd.setCursor(84,90);
M5.Lcd.print(lons[iti]);
if (M5.BtnA.wasPressed()) {
if(lons[iti]>8){
lons[iti]=9;
}else{
lons[iti]=lons[iti]+1;
}
}
else if (M5.BtnB.wasPressed()) {
if(lons[iti]<1){
lons[iti]=0;
}else{
lons[iti]=lons[iti]-1;
}
}
else if (M5.BtnC.wasPressed()) {
iti = 7;
}
}
lona = lons[0]*(lons[1]*100+lons[2]*10+lons[3]*1+lons[4]*0.1+lons[5]*0.01+lons[6]*0.001);
Serial.println(String(lona,3));
}
M5.Lcd.clear();
M5.Lcd.setCursor(0,0);
M5.Lcd.print("Latitude= ");
M5.Lcd.print(String(lata,3));
Serial.println(String(lata,3));
M5.Lcd.setCursor(0,20);
M5.Lcd.print("Longitude= ");
M5.Lcd.print(String(lona,3));
Serial.println(String(lona,3));
iti = 0;
M5.Lcd.setCursor(0,90);
M5.Lcd.print("Celebration day");
M5.Lcd.setCursor(0,110);
M5.Lcd.print("**/**");
M5.Lcd.setCursor(64,220);
M5.Lcd.print("+ - Enter");
//Celebration Day
while(btdtr==0){
while(iti == 0){
M5.update();
if (btd[iti]<10){
M5.Lcd.setCursor(0,110);
M5.Lcd.print("0");
M5.Lcd.setCursor(12,110);
M5.Lcd.print(btd[iti]);
}else{
M5.Lcd.setCursor(0,110);
M5.Lcd.print(btd[iti]);
}
if (M5.BtnA.wasPressed()) { //Button A CountUP
if(btd[iti]>11){
btd[iti]=12;
}else{
btd[iti]=btd[iti]+1;
}
}
else if(M5.BtnB.wasPressed()) { //Button B CountDown
if(btd[iti]<2){
btd[iti]=1;
}else{
btd[iti]=btd[iti]-1;
}
}
else if (M5.BtnC.wasPressed()) {
Serial.println(btd[iti]);
iti = 1;
}
}
M5.Lcd.setCursor(24,110);
M5.Lcd.print("/");
while(iti == 1){
M5.update();
if (btd[iti]<10){
M5.Lcd.setCursor(36,110);
M5.Lcd.print("0");
M5.Lcd.setCursor(48,110);
M5.Lcd.print(btd[iti]);
}else{
M5.Lcd.setCursor(36,110);
M5.Lcd.print(btd[iti]);
}
if (M5.BtnA.wasPressed()) { //Button A CountUP
if(btd[iti]>30){
btd[iti]=31;
}else{
btd[iti]=btd[iti]+1;
}
}
else if(M5.BtnB.wasPressed()) { //Button B CountDown
if(btd[iti]<2){
btd[iti]=1;
}else{
btd[iti]=btd[iti]-1;
}
}
else if (M5.BtnC.wasPressed()) {
Serial.println(btd[iti]);
iti = 2;
}
}
btdtr = 1;
}
M5.Lcd.clear();
M5.Lcd.setCursor(0,0);
M5.Lcd.print("Latitude= ");
M5.Lcd.print(String(lata,3));
Serial.println(String(lata,3));
M5.Lcd.setCursor(0,20);
M5.Lcd.print("Longitude= ");
M5.Lcd.print(String(lona,3));
Serial.println(String(lona,3));
M5.Lcd.setCursor(0,40);
M5.Lcd.print("Celebration Day:");
M5.Lcd.print(btd[0]);
M5.Lcd.print("/");
M5.Lcd.println(btd[1]);
delay(2000);
endpoi4 = String(lata,3);
endpoi5 = String(lona,3);
M5.Lcd.println();
M5.Lcd.setTextSize(1);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED){
delay(500);
M5.Lcd.print('.');
}
M5.Lcd.print("\r\nWiFi connected\r\nIP address: ");
M5.Lcd.println(WiFi.localIP());
delay(5000);
M5.Lcd.clear();
}
void loop() {
M5.Lcd.setTextSize(1);
M5.Lcd.setTextColor(WHITE);
if ((WiFi.status() == WL_CONNECTED)) {
HTTPClient http;
http.begin(endpoi1 + endpoi4 + endpoi2 + endpoi5 + endpoi3 + key); //URL Setting
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString(); //JSON
Serial.println(payload);
StaticJsonDocument<1024> doc;
DeserializationError error = deserializeJson(doc, payload);
if (error) {
M5.Lcd.print(F("deserializeJson() failed: "));
M5.Lcd.println(error.f_str());
} else {
Serial.println("JSON Serialize OK");
String toshi=doc["timezone"];
id = doc["current"]["weather"][0]["id"];
float temp = doc["current"]["temp"].as<double>() - 273.15;
float pressure = doc["current"]["pressure"].as<double>();
float humidity = doc["current"]["humidity"].as<double>();
unsigned long dt = doc["current"]["dt"].as<unsigned long>()+32400;
unsigned long Sunrise = doc["current"]["sunrise"].as<unsigned long>()+32400;
unsigned long Sunset = doc["current"]["sunset"].as<unsigned long>()+32400;
Serial.println(id);
String weather;
if (id == 200 ){ weather = "thunderstorm with light rain"; }
else if (id == 201 ){ weather = "thunderstorm with rain"; }
else if (id == 202 ){ weather = "thunderstorm with heavy rain"; } //Thunder //Rain
else if (id == 210 ){ weather = "light thunderstorm"; }
else if (id == 211 ){ weather = "thunderstorm"; }
else if (id == 212 ){ weather = "heavy thunderstorm"; } //Thunder
else if (id == 221 ){ weather = "ragged thunderstorm"; } //Thunder
else if (id == 230 ){ weather = "thunderstorm with light drizzle"; } //Thunder
else if (id == 231 ){ weather = "thunderstorm with drizzle"; } //Thunder
else if (id == 232 ){ weather = "thunderstorm with heavy drizzle"; } //Thunder
else if (id == 300 ){ weather = "light intensity drizzle"; }
else if (id == 301 ){ weather = "drizzle"; }
else if (id == 302 ){ weather = "heavy intensity drizzle"; }
else if (id == 310 ){ weather = "light intensity drizzle rain"; }
else if (id == 311 ){ weather = "drizzle rain"; }
else if (id == 312 ){ weather = "heavy intensity drizzle rain"; }
else if (id == 313 ){ weather = "shower rain and drizzle"; }
else if (id == 314 ){ weather = "heavy shower rain and drizzle"; }
else if (id == 321 ){ weather = "shower drizzle"; }
else if (id == 500 ){ weather = "light rain"; }
else if (id == 501 ){ weather = "moderate rain"; }
else if (id == 502 ){ weather = "heavy intensity rain"; } //Rain
else if (id == 503 ){ weather = "very heavy rain"; } //Rain
else if (id == 504 ){ weather = "extreme rain"; } //Rain
else if (id == 511 ){ weather = "freezing rain"; }
else if (id == 520 ){ weather = "light intensity shower rain"; }
else if (id == 521 ){ weather = "shower rain"; }
else if (id == 522 ){ weather = "heavy intensity shower rain"; } //Rain
else if (id == 531 ){ weather = "ragged shower rain"; } //Rain
else if (id == 600 ){ weather = "light snow"; }
else if (id == 601 ){ weather = "snow"; }
else if (id == 602 ){ weather = "heavy snow"; }
else if (id == 611 ){ weather = "sleet"; }
else if (id == 612 ){ weather = "light shower sleet"; }
else if (id == 613 ){ weather = "shower sleet"; }
else if (id == 615 ){ weather = "light rain and snow"; }
else if (id == 616 ){ weather = "rain and snow"; }
else if (id == 620 ){ weather = "light shower snow"; }
else if (id == 621 ){ weather = "shower snow"; } //Wind
else if (id == 622 ){ weather = "heavy shower snow"; } //Wind
else if (id == 701 ){ weather = "mist"; }
else if (id == 711 ){ weather = "smoke"; }
else if (id == 721 ){ weather = "haze"; }
else if (id == 731 ){ weather = "sand/dust whirls"; }
else if (id == 741 ){ weather = "fog"; }
else if (id == 751 ){ weather = "sand"; }
else if (id == 761 ){ weather = "dust"; }
else if (id == 762 ){ weather = "volcanic ash"; }
else if (id == 771 ){ weather = "squalls"; }
else if (id == 781 ){ weather = "tornado"; } //Wind
else if (id == 800 ){ weather = "clear sky"; }
else if (id == 801 ){ weather = "few clouds"; }
else if (id == 802 ){ weather = "scattered clouds"; }
else if (id == 803 ){ weather = "broken clouds"; }
else if (id == 804 ){ weather = "overcast clouds"; }
else {weather = "Etc";}
//Unix time conversion
Serial.print("DATE:");
setTime(dt);
Serial.printf("%d-%d-%d %d:%d\n",year(),month(),day(),hour(),minute());
M5.Lcd.setCursor(0,220);
M5.Lcd.printf("%d-%d-%d %d:%d\n",year(),month(),day(),hour(),minute());
bdmt = int(month());
Serial.print("bdmt=");
Serial.println(bdmt);
Serial.print("btd[0]=");
Serial.println(btd[0]);
bdday = int(day());
Serial.print("bdday=");
Serial.println(bdday);
Serial.print("btd[1]=");
Serial.print(btd[1]);
bdhour = int(hour());
M5.Lcd.print("Location:");
M5.Lcd.print(toshi);
M5.Lcd.print(" Weather:");
M5.Lcd.print(weather);
}
}else {
Serial.println("Error on HTTP request");
}
http.end(); //Free the resources
}
//id = 202; //Test
if(id==202 && repeats_wind==0 && repeats_thunder==0){
digitalWrite(PIN_THUNDER, HIGH);
delay(500);
digitalWrite(PIN_THUNDER, LOW);
delay(300);
digitalWrite(PIN_THUNDER, HIGH);
delay(500);
digitalWrite(PIN_THUNDER, LOW);
delay(300);
digitalWrite(PIN_THUNDER, HIGH);
playSdWav(WAV_FILE[0]);
repeats_thunder = 1;
digitalWrite(PIN_THUNDER, LOW);
delay(100);
moduleFan.setStatus(MODULE_FAN_ENABLE);
digitalWrite(PIN_WIND, HIGH);
delay(2000);
moduleFan.setStatus(MODULE_FAN_DISABLE);
repeats_wind = 1;
digitalWrite(PIN_WIND, LOW);
}else if(id>501 && id<505 && repeats_rain==0){
digitalWrite(PIN_RAIN, HIGH);
playSdWav(WAV_FILE[1]);
repeats_rain = 1;
digitalWrite(PIN_RAIN, LOW);
}else if(id==522 && repeats_rain==0){
digitalWrite(PIN_RAIN, HIGH);
playSdWav(WAV_FILE[1]);
repeats_rain = 1;
digitalWrite(PIN_RAIN, LOW);
}else if(id==531 && repeats_rain==0){
digitalWrite(PIN_RAIN, HIGH);
playSdWav(WAV_FILE[1]);
repeats_rain = 1;
digitalWrite(PIN_RAIN, LOW);
}else if(id>211 && id<233 && repeats_thunder==0){
digitalWrite(PIN_THUNDER, HIGH);
delay(500);
digitalWrite(PIN_THUNDER, LOW);
delay(300);
digitalWrite(PIN_THUNDER, HIGH);
delay(500);
digitalWrite(PIN_THUNDER, LOW);
delay(300);
digitalWrite(PIN_THUNDER, HIGH);
delay(500);
digitalWrite(PIN_THUNDER, LOW);
delay(300);
digitalWrite(PIN_THUNDER, HIGH);
playSdWav(WAV_FILE[0]);
repeats_thunder = 1;
digitalWrite(PIN_THUNDER, LOW);
}else if(id==621 && repeats_wind==0){
moduleFan.setStatus(MODULE_FAN_ENABLE);
digitalWrite(PIN_WIND, HIGH);
delay(5000);
moduleFan.setStatus(MODULE_FAN_DISABLE);
repeats_wind = 1;
digitalWrite(PIN_WIND, LOW);
}else if(id==622 && repeats_wind==0){
moduleFan.setStatus(MODULE_FAN_ENABLE);
digitalWrite(PIN_WIND, HIGH);
delay(5000);
moduleFan.setStatus(MODULE_FAN_DISABLE);
repeats_wind = 1;
digitalWrite(PIN_WIND, LOW);
}else if(id==781 && repeats_wind==0){
moduleFan.setStatus(MODULE_FAN_ENABLE);
digitalWrite(PIN_WIND, HIGH);
delay(5000);
moduleFan.setStatus(MODULE_FAN_DISABLE);
repeats_wind = 1;
digitalWrite(PIN_WIND, LOW);
}else{
repeats_rain = 0;
repeats_thunder=0;
repeats_wind = 0;
}
delay(1000);
if(bdmt==btd[0] && bdday==btd[1]){
M5.Lcd.setTextSize(3);
M5.Lcd.setTextColor(BLUE);
M5.Lcd.setCursor(20,110);
M5.Lcd.print("Congratulations");
//M5.Lcd.drawPngFile(SD,"/celebration.png"); //Test
//}
}
delay(1800000); //Updated every 30 minutes
M5.Lcd.clear();
}








Comments