Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crabby605s Weather Station #40

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions designs/weather_stations/Crabbys605's station/code/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#include <WiFi.h>
#include <HTTPClient.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <ArduinoJson.h>

#define TFT_RST 4
#define TFT_DC 2
#define TFT_CS 15

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* serverName = "https://api.open-meteo.com/v1/forecast?latitude=19.2403&longitude=73.1305&current_weather=true";

void parseWeatherData(String payload);

void setup() {
Serial.begin(115200);

WiFi.begin(ssid, password);
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);

tft.println("Connecting to WiFi...");

while (WiFi.status() != WL_CONNECTED) {
delay(500);
tft.print(".");
}

tft.fillScreen(ILI9341_BLACK);
tft.println("Connected to WiFi");
Serial.println("Connected to WiFi");

tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 120);
tft.setTextSize(2);
tft.println("Made by Crabby 605");
delay(3000);
}

void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(serverName);

int httpResponseCode = http.GET();
Serial.print("HTTP Response Code: ");
Serial.println(httpResponseCode);

if (httpResponseCode > 0) {
String payload = http.getString();
Serial.println("Received Payload: ");
Serial.println(payload);

parseWeatherData(payload);
} else {
tft.fillScreen(ILI9341_BLACK);
tft.println("Error fetching data");
Serial.println("Error fetching data");
}

http.end();
} else {
tft.fillScreen(ILI9341_BLACK);
tft.println("WiFi disconnected");
Serial.println("WiFi disconnected");
}

delay(60000);
}

void parseWeatherData(String payload) {
tft.fillScreen(ILI9341_BLACK);

Serial.println("Parsing weather data...");

StaticJsonDocument<1024> doc;
DeserializationError error = deserializeJson(doc, payload);

if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.f_str());
return;
}

JsonObject currentWeather = doc["current_weather"];

float temperature = currentWeather["temperature"];
float windSpeed = currentWeather["windspeed"];
String time = currentWeather["time"];
int windDirection = currentWeather["winddirection"];
bool isDay = currentWeather["is_day"];
int weatherCode = currentWeather["weathercode"];

tft.setCursor(0, 0);
tft.println("Weather Dashboard");
tft.println("");
tft.print("Time: ");
tft.println(time);
tft.print("Temperature: ");
tft.print(temperature);
tft.println(" C");
tft.print("Wind Speed: ");
tft.print(windSpeed);
tft.println(" km/h");
tft.print("Wind Direction: ");
tft.print(windDirection);
tft.println("°");
tft.print("Day/Night: ");
tft.println(isDay ? "Day" : "Night");
tft.print("Weather Code: ");
tft.println(weatherCode);
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions designs/weather_stations/Crabbys605's station/pcb/pcb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading