Skip to content

Commit 3912cc4

Browse files
committed
openmeteo progress update
up
1 parent 8176dbc commit 3912cc4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+12819
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
Inkplate6 OpenMeteo Weather Station Example
3+
Compatible with Soldered Inkplate 6
4+
5+
Getting Started:
6+
For setup and documentation, visit: https://inkplate.readthedocs.io/en/latest/
7+
8+
Overview:
9+
This example demonstrates how to fetch and display weather data from the OpenMeteo API
10+
using the Inkplate 10 e-paper display.
11+
12+
Before You Start:
13+
- Enter your WiFi credentials carefully (they are case-sensitive).
14+
- Update the following variables for accurate local weather data:
15+
• timeZone
16+
• latitude
17+
• longitude
18+
Set your username and city with `myUsername` and `myCity` (for display only, not essential for the API).
19+
20+
Units:
21+
By default, the app uses the metric system.
22+
To switch to Imperial units, change the metricUnits to "bool metricUnits = false;"
23+
*/
24+
#include "src/includes.h" // Include necessary libraries and dependencies for Inkplate and networking
25+
26+
// --- WiFi Configuration ---
27+
const char *ssid = "Soldered-testingPurposes";
28+
const char *password = "Testing443";
29+
30+
// --- User and Location Info ---
31+
String myUsername = "Username"; // User's name to be displayed on screen
32+
String myCity = "Osijek"; // City name for weather data
33+
int timeZone =
34+
2; // timeZone is the number in (UTC + number) in your time zone UTC + 2 for Osijek, UTC - 4 for New York City
35+
float latitude = 45.5550; // Latitude of the city
36+
float longitude = 18.6955; // Longitude of the city
37+
38+
bool metricUnits = true; // set this to false if you wish to use Imperial units
39+
40+
const char* ntpServer = "pool.ntp.org"; // in case you want to use a different one
41+
42+
// --- Device and Data Objects ---
43+
Inkplate inkplate; // Create Inkplate display object (3-bit mode for partial grayscale)
44+
Network network; // Network utility for weather fetching
45+
Network::UserInfo userInfo; // Structure to hold user and device info (battery, last updated, etc.)
46+
WeatherData weatherData; // Structure to hold fetched weather data
47+
Gui gui(inkplate); // Drawing visuals and info
48+
49+
// --- Deep Sleep Configuration ---
50+
#define uS_TO_S_FACTOR 1000000 // Convert microseconds to seconds
51+
#define TIME_TO_SLEEP 1800 // Sleep time: 1800 seconds = 30 minutes
52+
53+
// --- Main Setup: Runs Once on Boot ---
54+
void setup()
55+
{
56+
Serial.begin(115200); // Initialize serial monitor for debugging
57+
inkplate.begin(); // Start the Inkplate display
58+
inkplate.clearDisplay(); // Clear the screen
59+
inkplate.setRotation(0);
60+
61+
// Attempt to connect to WiFi
62+
const unsigned long timeout = 30000;
63+
unsigned long startTime = millis();
64+
bool connected = false;
65+
66+
while (!connected && (millis() - startTime) < timeout)
67+
{
68+
connected = inkplate.connectWiFi(ssid, password, 10, true);
69+
}
70+
71+
// If WiFi failed, display error message
72+
if (!connected)
73+
{
74+
gui.wifiError();
75+
}
76+
else
77+
{
78+
configTime(timeZone * 3600, 0, ntpServer); // Set local time via NTP server
79+
// Gather battery and city info
80+
userInfo.voltage = inkplate.readBattery();
81+
userInfo.city = myCity;
82+
userInfo.username = myUsername;
83+
userInfo.useMetric = metricUnits;
84+
85+
// Fetch weather data for specified coordinates
86+
network.fetchWeatherData(&weatherData, &userInfo, &latitude, &longitude);
87+
88+
// Display if weather API call fails
89+
if (userInfo.apiError)
90+
{
91+
gui.apiError();
92+
}
93+
else
94+
{
95+
// Success: draw UI and data
96+
gui.drawBackground();
97+
gui.displayWeatherData(&weatherData, &userInfo);
98+
}
99+
}
100+
101+
// Sleep to save power; wakes every 30 minutes
102+
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP *
103+
uS_TO_S_FACTOR); // Activate wake-up timer -- wake up after 30mins here
104+
esp_deep_sleep_start(); // Put ESP32 into deep sleep.
105+
}
106+
107+
void loop()
108+
{
109+
// Nothing to do here - main logic runs once in setup()
110+
}
111+

0 commit comments

Comments
 (0)