Compare commits

..

5 Commits

Author SHA1 Message Date
willem oldemans
3e24b555c8 move to own remote 2020-10-01 21:25:37 +02:00
Marcel Stör
2133809f99 Calibrate NTP time and tune astronomy data 2019-02-24 21:44:08 +01:00
WJCarpenter
850f8fd13e Return explicit booleans (#98)
I was being prompted to calibrate on every power-up or reset. Returning explicit boolean values
from these methods fixed it for me.
2019-02-11 10:20:04 +01:00
WJCarpenter
086416bd62 Fix console formatting glitches (#99) 2019-02-11 00:48:29 +01:00
Marcel Stör
ba74e3c2a8 Fix l10n and WiFi connect issues 2018-09-16 22:25:25 +02:00
4 changed files with 60 additions and 55 deletions

View File

@@ -7,9 +7,10 @@ TouchControllerWS::TouchControllerWS(XPT2046_Touchscreen *touchScreen) {
bool TouchControllerWS::loadCalibration() {
// always use this to "mount" the filesystem
bool result = SPIFFS.begin();
Serial.println("SPIFFS opened: " + result);
Serial.print("SPIFFS opened: ");
Serial.println(result ? "OK" : "Failed");
// this opens the file "f.txt" in read-mode
// this opens the file in read-mode
File f = SPIFFS.open("/calibration.txt", "r");
if (!f) {
@@ -29,7 +30,7 @@ bool TouchControllerWS::loadCalibration() {
}
f.close();
return true;
}
bool TouchControllerWS::saveCalibration() {
@@ -39,6 +40,7 @@ bool TouchControllerWS::saveCalibration() {
File f = SPIFFS.open("/calibration.txt", "w");
if (!f) {
Serial.println("file creation failed");
return false;
}
// now write two lines in key/value style with end-of-line characters
f.println(dx);
@@ -47,6 +49,7 @@ bool TouchControllerWS::saveCalibration() {
f.println(ay);
f.close();
return true;
}
void TouchControllerWS::startCalibration(CalibrationCallback *calibrationCallback) {

View File

@@ -30,6 +30,7 @@ See more at https://blog.squix.org
#include <XPT2046_Touchscreen.h>
#include "TouchControllerWS.h"
#include "SunMoonCalc.h"
/***
@@ -95,6 +96,7 @@ OpenWeatherMapCurrentData currentWeather;
OpenWeatherMapForecastData forecasts[MAX_FORECASTS];
simpleDSTadjust dstAdjusted(StartRule, EndRule);
Astronomy::MoonData moonData;
//SunMoonCalc::Moon moonData;
void updateData();
void drawProgress(uint8_t percentage, String text);
@@ -122,8 +124,6 @@ int frameCount = 3;
int screenCount = 5;
long lastDownloadUpdate = millis();
String moonAgeImage = "";
uint8_t moonAge = 0;
uint16_t screen = 0;
long timerPress;
bool canBtnPress;
@@ -136,6 +136,7 @@ void connectWifi() {
Serial.print(WIFI_SSID);
Serial.print("/");
Serial.println(WIFI_PASS);
WiFi.disconnect();
WiFi.mode(WIFI_STA);
WiFi.hostname(WIFI_HOSTNAME);
WiFi.begin(WIFI_SSID,WIFI_PASS);
@@ -179,7 +180,6 @@ void setup() {
SPIFFS.format();
}
drawProgress(100,"Formatting done");
//SPIFFS.remove("/calibration.txt");
boolean isCalibrationAvailable = touchController.loadCalibration();
if (!isCalibrationAvailable) {
Serial.println("Calibration not available");
@@ -268,19 +268,22 @@ void loop() {
// Update the internet based information and update screen
void updateData() {
time_t now;
gfx.fillBuffer(MINI_BLACK);
gfx.setFont(ArialRoundedMTBold_14);
drawProgress(10, "Updating time...");
configTime(UTC_OFFSET * 3600, 0, NTP_SERVERS);
while(!time(nullptr)) {
Serial.print("#");
delay(100);
while((now = time(nullptr)) < NTP_MIN_VALID_EPOCH) {
Serial.print(".");
delay(300);
}
Serial.println();
Serial.printf("Current time: %d\n", now);
// calculate for time calculation how much the dst class adds.
dstOffset = UTC_OFFSET * 3600 + dstAdjusted.time(nullptr) - time(nullptr);
Serial.printf("Time difference for DST: %d", dstOffset);
dstOffset = UTC_OFFSET * 3600 + dstAdjusted.time(nullptr) - now;
Serial.printf("Time difference for DST: %d\n", dstOffset);
drawProgress(50, "Updating conditions...");
OpenWeatherMapCurrent *currentWeatherClient = new OpenWeatherMapCurrent();
@@ -302,12 +305,18 @@ void updateData() {
drawProgress(80, "Updating astronomy...");
Astronomy *astronomy = new Astronomy();
moonData = astronomy->calculateMoonData(time(nullptr));
float lunarMonth = 29.53;
moonAge = moonData.phase <= 4 ? lunarMonth * moonData.illumination / 2 : lunarMonth - moonData.illumination * lunarMonth / 2;
moonAgeImage = String((char) (65 + ((uint8_t) ((26 * moonAge / 30) % 26))));
moonData = astronomy->calculateMoonData(now);
moonData.phase = astronomy->calculateMoonPhase(now);
delete astronomy;
astronomy = nullptr;
astronomy = nullptr;
//https://github.com/ThingPulse/esp8266-weather-station/issues/144 prevents using this
// // 'now' has to be UTC, lat/lng in degrees not raadians
// SunMoonCalc *smCalc = new SunMoonCalc(now - dstOffset, currentWeather.lat, currentWeather.lon);
// moonData = smCalc->calculateSunAndMoonData().moon;
// delete smCalc;
// smCalc = nullptr;
Serial.printf("Free mem: %d\n", ESP.getFreeHeap());
delay(1000);
}
@@ -341,8 +350,7 @@ void drawTime() {
gfx.setTextAlignment(TEXT_ALIGN_CENTER);
gfx.setFont(ArialRoundedMTBold_14);
gfx.setColor(MINI_WHITE);
String date = ctime(&now);
date = date.substring(0,11) + String(1900 + timeinfo->tm_year);
String date = WDAY_NAMES[timeinfo->tm_wday] + " " + MONTH_NAMES[timeinfo->tm_mon] + " " + String(timeinfo->tm_mday) + " " + String(1900 + timeinfo->tm_year);
gfx.drawString(120, 6, date);
gfx.setFont(ArialRoundedMTBold_36);
@@ -350,22 +358,20 @@ void drawTime() {
if (IS_STYLE_12HR) {
int hour = (timeinfo->tm_hour+11)%12+1; // take care of noon and midnight
sprintf(time_str, "%2d:%02d:%02d\n",hour, timeinfo->tm_min, timeinfo->tm_sec);
gfx.drawString(120, 20, time_str);
} else {
sprintf(time_str, "%02d:%02d:%02d\n",timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
gfx.drawString(120, 20, time_str);
}
gfx.drawString(120, 20, time_str);
gfx.setTextAlignment(TEXT_ALIGN_LEFT);
gfx.setFont(ArialMT_Plain_10);
gfx.setColor(MINI_BLUE);
if (IS_STYLE_12HR) {
sprintf(time_str, "%s\n%s", dstAbbrev, timeinfo->tm_hour>=12?"PM":"AM");
gfx.drawString(195, 27, time_str);
} else {
sprintf(time_str, "%s", dstAbbrev);
gfx.drawString(195, 27, time_str); // Known bug: Cuts off 4th character of timezone abbreviation
}
gfx.drawString(195, 27, time_str); // Known bug: Cuts off 4th character of timezone abbreviation
}
// draws current weather information
@@ -433,7 +439,7 @@ void drawAstronomy() {
gfx.setFont(MoonPhases_Regular_36);
gfx.setColor(MINI_WHITE);
gfx.setTextAlignment(TEXT_ALIGN_CENTER);
gfx.drawString(120, 275, moonAgeImage);
gfx.drawString(120, 275, String((char) (97 + (moonData.illumination * 26))));
gfx.setColor(MINI_WHITE);
gfx.setFont(ArialRoundedMTBold_14);
@@ -443,23 +449,25 @@ void drawAstronomy() {
gfx.setTextAlignment(TEXT_ALIGN_LEFT);
gfx.setColor(MINI_YELLOW);
gfx.drawString(5, 250, "Sun");
gfx.drawString(5, 250, SUN_MOON_TEXT[0]);
gfx.setColor(MINI_WHITE);
time_t time = currentWeather.sunrise + dstOffset;
gfx.drawString(5, 276, "Rise:");
gfx.drawString(5, 276, SUN_MOON_TEXT[1] + ":");
gfx.drawString(45, 276, getTime(&time));
time = currentWeather.sunset + dstOffset;
gfx.drawString(5, 291, "Set:");
gfx.drawString(5, 291, SUN_MOON_TEXT[2] + ":");
gfx.drawString(45, 291, getTime(&time));
gfx.setTextAlignment(TEXT_ALIGN_RIGHT);
gfx.setColor(MINI_YELLOW);
gfx.drawString(235, 250, "Moon");
gfx.drawString(235, 250, SUN_MOON_TEXT[3]);
gfx.setColor(MINI_WHITE);
gfx.drawString(235, 276, String(moonAge) + "d");
float lunarMonth = 29.53;
// approximate moon age
gfx.drawString(235, 276, String(moonData.phase <= 4 ? lunarMonth * moonData.illumination / 2.0 : lunarMonth - moonData.illumination * lunarMonth / 2.0, 1) + "d");
gfx.drawString(235, 291, String(moonData.illumination * 100, 0) + "%");
gfx.drawString(200, 276, "Age:");
gfx.drawString(200, 291, "Illum:");
gfx.drawString(190, 276, SUN_MOON_TEXT[4] + ":");
gfx.drawString(190, 291, SUN_MOON_TEXT[5] + ":");
}
@@ -485,13 +493,6 @@ void drawCurrentWeatherDetail() {
drawLabelValue(4, "Pressure:", String(currentWeather.pressure) + "hPa");
drawLabelValue(5, "Clouds:", String(currentWeather.clouds) + "%");
drawLabelValue(6, "Visibility:", String(currentWeather.visibility) + "m");
/*gfx.setTextAlignment(TEXT_ALIGN_LEFT);
gfx.setColor(MINI_YELLOW);
gfx.drawString(15, 185, "Description: ");
gfx.setColor(MINI_WHITE);
gfx.drawStringMaxWidth(15, 200, 240 - 2 * 15, forecasts[0].forecastText);*/
}
void drawLabelValue(uint8_t line, String label, String value) {
@@ -639,4 +640,3 @@ String getTime(time_t *timestamp) {
sprintf(buf, "%02d:%02d", timeInfo->tm_hour, timeInfo->tm_min);
return String(buf);
}

View File

@@ -1,5 +1,7 @@
// Created by http://oleddisplay.squix.ch/ Consider a donation
// In case of problems make sure that you are using the font file with the correct version!
// Font face https://www.dafont.com/moon-phases.font
const char MoonPhases_Regular_36[] PROGMEM = {
0x24, // Width: 36
0x25, // Height: 37
@@ -424,4 +426,3 @@ const char MoonPhases_Regular_36[] PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFF,0xFF,0x3F,0x00,0xFE,0xFF,0xFF,0x3F,0x00,0xFE,0xFF,0xFF,0x3F,0x00,0xFE,0xFF,0xFF,0x3F,0x00,0x00,0x60,0x00,0x07,0x00,0x00,0x38,0x00,0x0E,0x00,0x00,0x1C,0x00,0x0E,0x00,0x00,0x1C,0x00,0x1C,0x00,0x00,0x0E,0x00,0x1C,0x00,0x00,0x0E,0x00,0x1C,0x00,0x00,0x0E,0x00,0x1C,0x00,0x00,0x0E,0x00,0x1E,0x00,0x00,0x1E,0x00,0x0F,0x00,0x00,0x7C,0xC0,0x0F,0x00,0x00,0xFC,0xFF,0x07,0x00,0x00,0xF8,0xFF,0x03,0x00,0x00,0xF0,0xFF,0x01,0x00,0x00,0xC0,0x3F, // 254
0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0xFE,0x07,0x00,0x00,0x00,0xFC,0x1F,0x00,0x00,0x38,0xE0,0xFF,0x00,0x00,0x38,0x00,0xFF,0x03,0x00,0x38,0x00,0xFC,0x1F,0x00,0x00,0x00,0xE0,0x3F,0x00,0x00,0x00,0x80,0x3F,0x00,0x00,0x00,0x80,0x3F,0x00,0x00,0x00,0xF0,0x0F,0x00,0x38,0x00,0xFC,0x01,0x00,0x38,0x80,0x7F,0x00,0x00,0x38,0xE0,0x1F,0x00,0x00,0x00,0xF8,0x03,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,0x06 // 255
};

View File

@@ -21,25 +21,25 @@ See more at http://blog.squix.ch
#include <simpleDSTadjust.h>
// Setup
#define WIFI_SSID "yourssid"
#define WIFI_PASS "yourpassw0rd"
#define WIFI_HOSTNAME "ThingPulse-weather-station-color"
#define WIFI_SSID "poes"
#define WIFI_PASS "Rijnstraat214"
#define WIFI_HOSTNAME "wifi-weather-station"
const int UPDATE_INTERVAL_SECS = 15 * 60; // Update every 10 minutes
const int SLEEP_INTERVAL_SECS = 0; // Going to Sleep after idle times, set 0 for dont sleep
const int UPDATE_INTERVAL_SECS = 10 * 60; // Update every 10 minutes
const int SLEEP_INTERVAL_SECS = 0; // Going to sleep after idle times, set 0 for insomnia
// OpenWeatherMap Settings
// Sign up here to get an API key: https://docs.thingpulse.com/how-tos/openweathermap-key/
String OPEN_WEATHER_MAP_APP_ID = "";
String OPEN_WEATHER_MAP_APP_ID = "d9b8d326bbc2bb13f9c024601afe8e5e";
/*
Go to https://openweathermap.org/find?q= and search for a location. Go through the
result set and select the entry closest to the actual location you want to display
data for. It'll be a URL like https://openweathermap.org/city/2657896. The number
at the end is what you assign to the constant below.
*/
String OPEN_WEATHER_MAP_LOCATION_ID = "2657896";
String DISPLAYED_CITY_NAME = "Zurich";
String OPEN_WEATHER_MAP_LOCATION_ID = "2747350";
String DISPLAYED_CITY_NAME = "'s-Hertogenbosch";
/*
Arabic -> ar, Bulgarian -> bg, Catalan -> ca, Czech -> cz, German -> de, Greek -> el,
English -> en, Persian (Farsi) -> fa, Finnish -> fi, French -> fr, Galician -> gl,
@@ -49,14 +49,15 @@ Portuguese -> pt, Romanian -> ro, Russian -> ru, Swedish -> se, Slovak -> sk,
Slovenian -> sl, Spanish -> es, Turkish -> tr, Ukrainian -> ua, Vietnamese -> vi,
Chinese Simplified -> zh_cn, Chinese Traditional -> zh_tw.
*/
String OPEN_WEATHER_MAP_LANGUAGE = "en";
String OPEN_WEATHER_MAP_LANGUAGE = "nl";
const uint8_t MAX_FORECASTS = 10;
// Adjust according to your language
const String WDAY_NAMES[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
const String MONTH_NAMES[] = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
const String MOON_PHASES[] = {"New Moon", "Waxing Crescent", "First Quarter", "Waxing Gibbous",
"Full Moon", "Waning Gibbous", "Third quarter", "Waning Crescent"};
const String WDAY_NAMES[] = {"zon", "maa", "din", "woe", "don", "vri", "zat"};
const String MONTH_NAMES[] = {"JAN", "FEB", "MAA", "APR", "MEI", "JUN", "JUL", "AUG", "SEP", "OKT", "NOV", "DEC"};
const String SUN_MOON_TEXT[] = {"Zon", "op", "onder", "Maan", "Age", "Illum"};
const String MOON_PHASES[] = {"Nieuwe Maan", "Waxing Crescent", "First Quarter", "Waxing Gibbous",
"Volle Maan", "Waning Gibbous", "Third quarter", "Waning Crescent"};
#define UTC_OFFSET +1
struct dstRule StartRule = {"CEST", Last, Sun, Mar, 2, 3600}; // Central European Summer Time = UTC/GMT +2 hours
@@ -73,11 +74,12 @@ const boolean IS_METRIC = true;
// Change for 12 Hour/ 24 hour style clock
bool IS_STYLE_12HR = false;
// change for different ntp (time servers)
// change for different NTP (time servers)
#define NTP_SERVERS "0.ch.pool.ntp.org", "1.ch.pool.ntp.org", "2.ch.pool.ntp.org"
// #define NTP_SERVERS "us.pool.ntp.org", "time.nist.gov", "pool.ntp.org"
// August 1st, 2018
#define NTP_MIN_VALID_EPOCH 1533081600
// Pins for the ILI9341
#define TFT_DC D2
@@ -92,4 +94,3 @@ bool IS_STYLE_12HR = false;
/***************************
* End Settings
**************************/