Skip to content

Commit

Permalink
Kleine Verbesserungen bei Wetter und Kalender
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Arlitt committed Jun 26, 2022
1 parent d661f8a commit 1ef9042
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 49 deletions.
22 changes: 12 additions & 10 deletions M5PaperCalendar.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
Inspired by this:
Calendar: https://github.com/SeBassTian23/ESP32-CalendarDisplay
Calendar: https://github.com/SeBassTian23/ESP32-CalendarDisplay / https://github.com/kristiantm/eink-family-calendar-esp32
PureClock: https://github.com/azw413/M5-Clock
Weather: https://github.com/mzyy94/M5PaperWeather/tree/jp-model
Expand All @@ -48,19 +48,20 @@
V0.6 22.12.2021: Worked on the today page
V0.7 23.12.2021: Added the next event to today page
V0.8 29.12.2021: Changed time - no more using the rtc because time is synced with ntp time server every new day
V0.9 03.04.2022: Some minor improvements on the weather page
Important note:
---------------
Due to changes in arduino-esp32 version 2.0.1.
change line 67 in M5EPD.cpp like this:
change line 67 in M5EPD.cpp and
Wire.begin(21, 22, (uint32_t)400000);
*********************************************************************/

#define FIRMWARE "0.8 - 2021-12-29"
#define FIRMWARE "0.9 - 2022-04-03"

/**************************************************************************************
** Libraries
Expand Down Expand Up @@ -111,8 +112,8 @@ const char* const PROGMEM monthNames[] = { "Error", "Januar", "Februar", "M\u00
const char* const PROGMEM monthShortNamesMMM[] = { "Jan", "Feb", "Mrz", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez" };

// internal temperature and humidity
int sht30Temperatur; // SHT30 temperature
int sht30Humidity; // SHT30 humidity
int sht30Temperatur; // SHT30 temperature
int sht30Humidity; // SHT30 humidity

// the calendar vars
const int calEntryCount = 10;
Expand Down Expand Up @@ -197,7 +198,7 @@ M5EPD_Canvas myWeather(&M5.EPD);

// the clients for weather and google
HTTPClient http;
WiFiClient client;
WiFiClientSecure client;

// include all the helpers
#include "Icons.h"
Expand All @@ -211,7 +212,9 @@ WiFiClient client;
/////////////////////////////// Setup /////////////////////////////////////////////////////////////////////////
void setup() {

M5.begin(false, false, true, true, false);
//M5.begin(false, false, true, true, false);
M5.begin();
M5.SHT30.Begin();

// Serial is initialised by M5.begin to 115200 baud
Serial.print("\nM5PaperCalendarWeatherClock started.\n");
Expand All @@ -220,9 +223,6 @@ void setup() {
Serial.println("SPIFFS Mount Failed");
}

M5.SHT30.Begin();
M5.RTC.begin();

M5.EPD.SetRotation(0);
M5.TP.SetRotation(0);

Expand Down Expand Up @@ -264,6 +264,8 @@ void setup() {
myToday.deleteCanvas();
printFrame();

getSHT30Values();

}
///////////////////// End Setup /////////////////////////////////////////////////////////////////////////

Expand Down
6 changes: 3 additions & 3 deletions M5PaperCalendar.vcxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Auf dem M5Paper werden auf 3 Seiten folgende Infos angezeigt:
2. Kalender: Datum, laufender Monat und die nächsten Termine. Die Termine werden vom Google Kalender abgefragt. Dazu ist ein separates Script erforderlich (stelle ich gelegentich hier ein)
4. Wetter: Die Wetterdaten für meinen Wohnort, die Daten kommen von OpenWeatherMap.

Sämtliche Passwörter, APP-Ids und URLs sind in Credentials nach folgenden Muster hinterlegt, Einbindung als Library:
Sämtliche Passwörter, APP-Ids und URLs sind in Credentials nach folgendem Muster hinterlegt, Einbindung als Library:
```
// My credentials
Expand Down
5 changes: 3 additions & 2 deletions __vm/.M5PaperCalendar.vsarduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
All non-arduino files created by visual micro and all visual studio project or solution files can be freely deleted and are not required to compile a sketch (do not delete your own code!).
Note: debugger breakpoints are stored in '.sln' or '.asln' files, knowledge of last uploaded breakpoints is stored in the upload.vmps.xml file. Both files are required to continue a previous debug session without needing to compile and upload again
Hardware: M5Stack-Paper, Platform=esp32, Package=m5stack
Hardware: M5Stack-Paper (m5stack_m5stack-paper), Platform=esp32, Package=m5stack
*/

#if defined(_VMICRO_INTELLISENSE)
Expand All @@ -20,8 +20,9 @@
#define WITH_POSIX
#define _GNU_SOURCE
#define ESP_PLATFORM
#define _POSIX_READER_WRITER_LOCKS
#define F_CPU 240000000L
#define ARDUINO 108016
#define ARDUINO 108019
#define ARDUINO_M5Stack_Paper
#define ARDUINO_ARCH_ESP32
#define ARDUINO_PARTITION_default_16MB
Expand Down
2 changes: 1 addition & 1 deletion __vm/Compile.vmps.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion __vm/Upload.vmps.xml

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion myCalendar.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,22 @@ void showClock() {
}

bool readCalendar() {
//WiFiClient client;
//HTTPClient http;

// Getting calendar from google script
Serial.println("Getting calendar");
Serial.println(calendarRequest);

if (!checkWiFi()) connectWiFi();

//client.stop();
http.end();
http.setTimeout(20000);
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
if (!http.begin(calendarRequest)) {
Serial.println("Cannot connect to google script");
//client.stop();
http.end();
return false;
}
Expand All @@ -206,7 +211,7 @@ bool readCalendar() {
int returnCode = http.GET();
Serial.print("Returncode: ");
Serial.println(returnCode);
if (returnCode != HTTP_CODE_OK) return false;
//if (returnCode != HTTP_CODE_OK) return false;

String response = http.getString();
Serial.print("Response: ");
Expand Down Expand Up @@ -274,6 +279,7 @@ bool readCalendar() {
}
}
}
//client.stop();
http.end();
Serial.println("Calendar read!");
return true;
Expand Down
24 changes: 3 additions & 21 deletions myUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,37 +94,19 @@ String getHourMinString(time_t rawtime) {
return (String)buff;
}

/* Convert the date part of the RTC timestamp */
String getRTCDateString() {
char buff[32];
rtc_date_t date_struct;
M5.RTC.getDate(&date_struct);
sprintf(buff, "%02d.%02d.%04d", date_struct.day, date_struct.mon, date_struct.year);
return (String)buff;
}

/* Convert the time part of the RTC timestamp */
String getRTCTimeString() {
char buff[32];
rtc_time_t time_struct;
M5.RTC.getTime(&time_struct);
sprintf(buff, "%02d:%02d", time_struct.hour, time_struct.min);
return (String)buff;
}

/* Convert the time_t to the date part MM/DD */
String getShortDayOfWeekString(time_t rawtime) {
return (String)dayShortNamesDD[weekday(rawtime)-1];
}


/* Read the SHT30 environment chip data */
bool getSHT30Values() {
void getSHT30Values() {
M5.SHT30.UpdateData();
if (M5.SHT30.GetError() == 0) {
sht30Temperatur = (int)M5.SHT30.GetTemperature();
sht30Humidity = (int)M5.SHT30.GetRelHumidity();
return true;
// return true;
}
return false;
// return false;
}
50 changes: 41 additions & 9 deletions myWeather.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bool Fill(const JsonObject& root) {
weather.hourlyTime[0] = LocalTime(root["current"]["dt"].as<int>());
weather.hourlyMaxTemp[0] = root["current"]["temp"].as<float>();
weather.hourlyMain[0] = root["current"]["weather"][0]["description"].as<char*>();
weather.hourlyRain[0] = root["current"]["rain"]["1h"].as<float>();
weather.hourlyRain[0] = max(root["current"]["rain"]["1h"].as<float>(), root["current"]["snow"]["1h"].as<float>());
weather.hourlyPop[0] = root["current"]["pop"].as<float>() * 100;
weather.hourlyPressure[0] = root["current"]["pressure"].as<float>();
weather.hourlyIcon[0] = root["current"]["weather"][0]["icon"].as<char*>();
Expand All @@ -77,7 +77,7 @@ bool Fill(const JsonObject& root) {
weather.hourlyTime[i] = LocalTime(hourly_list[i - 1]["dt"].as<int>());
weather.hourlyMaxTemp[i] = hourly_list[i - 1]["temp"].as<float>();
weather.hourlyMain[i] = hourly_list[i - 1]["weather"][0]["description"].as<char*>();
weather.hourlyRain[i] = hourly_list[i - 1]["rain"]["1h"].as<float>();
weather.hourlyRain[i] = max(hourly_list[i - 1]["rain"]["1h"].as<float>(), hourly_list[i - 1]["snow"]["1h"].as<float>());
weather.hourlyPop[i] = hourly_list[i - 1]["pop"].as<float>() * 100;
weather.hourlyPressure[i] = hourly_list[i - 1]["pressure"].as<float>();
weather.hourlyIcon[i] = hourly_list[i - 1]["weather"][0]["icon"].as<char*>();
Expand All @@ -99,7 +99,7 @@ bool Fill(const JsonObject& root) {
weather.forecastTime[i] = LocalTime(dayly_list[i]["dt"].as<int>());
weather.forecastMaxTemp[i] = dayly_list[i]["temp"]["max"].as<float>();
weather.forecastMinTemp[i] = dayly_list[i]["temp"]["min"].as<float>();
weather.forecastRain[i] = dayly_list[i]["rain"].as<float>();
weather.forecastRain[i] = max(dayly_list[i]["rain"].as<float>(), dayly_list[i]["snow"].as<float>());
weather.forecastPop[i] = dayly_list[i]["pop"].as<float>() * 100;
weather.forecastPressure[i] = dayly_list[i]["pressure"].as<float>();
weather.forecastIcon[i] = dayly_list[i]["weather"][0]["icon"].as<char*>();
Expand Down Expand Up @@ -278,13 +278,18 @@ void drawWindInfo(int x, int y, int dx, int dy)

/* Draw the M5Paper environment and RTC information */
void drawM5PaperInfo(int x, int y, int dx, int dy) {
char timeString[10];
char dateString[12];

myWeather.setTextSize(36);
myWeather.drawCentreString("Innen", x + dx / 2, y + 5, 1);
myWeather.drawLine(x, y + 35, x + dx, y + 35, MYBLACK);

myWeather.setTextSize(36);
myWeather.drawCentreString(getRTCDateString(), x + dx / 2, y + 50, 1);
myWeather.drawCentreString(getRTCTimeString(), x + dx / 2, y + 90, 1);
sprintf(timeString, "%02d:%02d", tm.tm_hour, tm.tm_min);
myWeather.drawCentreString(timeString, x + dx / 2, y + 50, 1);
sprintf(dateString, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900);
myWeather.drawCentreString(dateString, x + dx / 2, y + 90, 1);
myWeather.setTextSize(24);

myWeather.setTextSize(36);
Expand All @@ -305,7 +310,12 @@ void drawDaily(int x, int y, int dx, int dy, Weather& weather, int index) {
String icon = weather.forecastIcon[index];

myWeather.setTextSize(24);
if (weekday(time) == 1 || weekday(time) == 7) {
myWeather.setTextColor(MYBLACK, M5EPD_Canvas::G2);
myWeather.fillRect(x + 1, y + 1, dx - 1, 31, M5EPD_Canvas::G2);
}
myWeather.drawCentreString(index == 0 ? "Heute" : getShortDayOfWeekString(time), x + dx / 2, y + 5, 1);
myWeather.setTextColor(MYBLACK, MYWHITE);

int iconX = x + dx / 2 - 32;
int iconY = y + 20;
Expand Down Expand Up @@ -335,7 +345,7 @@ void drawDaily(int x, int y, int dx, int dy, Weather& weather, int index) {
}

/* Draw a graph with x- and y-axis and values */
void drawGraph(int x, int y, int dx, int dy, String title, int xMin, int xMax, int yMin, int yMax, float values[], float values2[]) {
void drawGraph(int x, int y, int dx, int dy, String title, int xMin, int xMax, int yMin, int yMax, float values[], float values2[], float nightZone1 = 0, float nightZone2 = 0) {
String yMinString = String(yMin);
String yMaxString = String(yMax);
int textWidth = 5 + max(yMinString.length() * 3.5, yMaxString.length() * 3.5);
Expand All @@ -357,6 +367,13 @@ void drawGraph(int x, int y, int dx, int dy, String title, int xMin, int xMax, i
myWeather.drawString(String(i), graphX + i * xStep, graphY + graphDY + 5);
}

if (nightZone1 > 0) {
myWeather.fillRect(graphX, graphY, nightZone1 * (float)graphDX / 12.F, graphDY, M5EPD_Canvas::G1);
}
if (nightZone2 > 0) {
myWeather.fillRect(max(graphX + graphDX - nightZone2 * (float)graphDX / 12.F, (float)graphX), graphY, min(nightZone2 * (float)graphDX / 12.F, (float)graphDX), graphDY, M5EPD_Canvas::G1);
}

myWeather.drawRect(graphX, graphY, graphDX, graphDY, MYBLACK);
if (yMin < 0 && yMax > 0) { // null line?
float yValueDX = (float)graphDY / (yMax - yMin);
Expand Down Expand Up @@ -409,7 +426,7 @@ void drawGraph(int x, int y, int dx, int dy, String title, int xMin, int xMax, i
}

/* Draw a dual graph */
void drawDualGraph(int x, int y, int dx, int dy, String title, int xMin, int xMax, int yMin, int yMax, float values[], int offset, int yMinB, int yMaxB, float valuesB[]) {
void drawDualGraph(int x, int y, int dx, int dy, String title, int xMin, int xMax, int yMin, int yMax, float values[], int offset, int yMinB, int yMaxB, float valuesB[], float nightZone1 = 0, float nightZone2 = 0) {
String yMinString = String(yMinB);
String yMaxString = String(yMaxB);
int textWidth = 5 + max(yMinString.length() * 3.5, yMaxString.length() * 3.5);
Expand All @@ -431,6 +448,13 @@ void drawDualGraph(int x, int y, int dx, int dy, String title, int xMin, int xMa
myWeather.drawString(String(i), graphX + i * xStep, graphY + graphDY + 5);
}

if (nightZone1 > 0) {
myWeather.fillRect(graphX, graphY, nightZone1 * (float)graphDX / 12.F, graphDY, M5EPD_Canvas::G1);
}
if (nightZone2 > 0) {
myWeather.fillRect(max(graphX + graphDX - nightZone2 * (float)graphDX / 12.F, (float)graphX), graphY, min(nightZone2 * (float)graphDX / 12.F, (float)graphDX), graphDY, M5EPD_Canvas::G1);
}

myWeather.drawRect(graphX, graphY, graphDX, graphDY, MYBLACK);
if (yMin < 0 && yMax > 0) { // null line?
float yValueDX = (float)graphDY / (yMax - yMin);
Expand Down Expand Up @@ -515,10 +539,18 @@ void showWeather() {
drawDaily(x, 286, 116, 122, weather, i);
myWeather.drawLine(x, 286, x, 408, MYBLACK);
}

float hoursUntilSunlize = 0, hoursAfterSunset = 0;
if (weather.currentTime < weather.sunrise) {
hoursUntilSunlize = (weather.sunrise - weather.currentTime) / 3600.0;
}
if (weather.currentTime + 12 * 60 * 60 > weather.sunset) {
hoursAfterSunset = (weather.currentTime + 12 * 60 * 60 - weather.sunset) / 3600.0;
}
myWeather.drawRect(15, 286, maxX - 30, 122, MYBLACK);

drawGraph(15, 408, 232, 122, "Temp 12h (C)", 0, 12, weather.hourlyTempRange[0], weather.hourlyTempRange[1], weather.hourlyMaxTemp, NULL);
drawDualGraph(247, 408, 232, 122, "Regen 12h (mm/%)", 0, 12, 0, 100, weather.hourlyPop, 1, 0, weather.hourlyMaxRain, weather.hourlyRain);
drawGraph(15, 408, 232, 122, "Temp 12h (C)", 0, 12, weather.hourlyTempRange[0], weather.hourlyTempRange[1], weather.hourlyMaxTemp, NULL, hoursUntilSunlize, hoursAfterSunset);
drawDualGraph(247, 408, 232, 122, "Regen 12h (mm/%)", 0, 12, 0, 100, weather.hourlyPop, 1, 0, weather.hourlyMaxRain, weather.hourlyRain, hoursUntilSunlize, hoursAfterSunset);
myWeather.drawLine(480, 408, 480, 530, MYBLACK);
drawGraph(481, 408, 232, 122, "Temp 7Tage (C)", 0, 7, weather.forecastTempRange[0], weather.forecastTempRange[1], weather.forecastMinTemp, weather.forecastMaxTemp);
drawDualGraph(713, 408, 232, 122, "Regen 7Tage (mm/%)", 0, 7, 0, 100, weather.forecastPop, 0, 0, weather.forecastMaxRain, weather.forecastRain);
Expand Down

0 comments on commit 1ef9042

Please sign in to comment.