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

supercoolweatherstatieosdatng #39

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
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#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 = "";
// Charlotte weather
const char* serverName = "https://api.open-meteo.com/v1/forecast?latitude=35.2271&longitude=-80.8431&current=temperature_2m,relative_humidity_2m&forecast_days=1";

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("wifi connecting");

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

tft.fillScreen(ILI9341_BLACK);
tft.println("wifi connected");
Serial.println("wifi connected");

tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 120);
tft.setTextSize(2);
tft.println("Today's Weather!");
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(30000);
}

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

Serial.println("Weather Parse");

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"];

float temperature = currentWeather["temperature_2m"];
int humidity = currentWeather["relative_humidity_2m"];
String time = currentWeather["time"];

tft.setCursor(0, 0);
tft.setTextSize(2);
tft.println("Charlotte Weather");
tft.setTextSize(1);
tft.println("");

tft.print("Time: ");
tft.println(time);

tft.print("Temperature: ");
tft.print(temperature);
tft.println(" °C");

tft.print("Humidity: ");
tft.print(humidity);
tft.println(" %");
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# My Super Cool Weather Station!

![image](https://github.com/user-attachments/assets/ffc0935a-66c9-4125-a8d5-e90a2455ce4c)

## Features:
- Displays the current temperature and humidity.
- Fetches real-time data from [Open-Meteo](https://open-meteo.com/).
- Portable design powered by a LiPo battery

## Components:
- **C3 Mini**
- **TFT ST7735**
- **LiPo Battery and TP4056 Board**

## How It Works:
1. Connects to a Wi-Fi network to fetch data from Open-Meteo API.
2. Parses the received JSON payload for temperature, humidity, and time data.
3. Displays the parsed data on the tft screen
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"EXTRA_LAYERS": "", "ALL_ACTIVE_LAYERS": false, "EXTEND_EDGE_CUT": false, "ALTERNATIVE_EDGE_CUT": false, "AUTO TRANSLATE": true, "AUTO FILL": true, "EXCLUDE DNP": false}
Loading