263 lines
12 KiB
C++
263 lines
12 KiB
C++
/* ESP32 Weather Display using an EPD 7.5" 800x480 Display, obtains data from Open Weather Map, decodes and then displays it.
|
|
####################################################################################################################################
|
|
This software, the ideas and concepts is Copyright (c) David Bird 2018. All rights to this software are reserved.
|
|
|
|
Any redistribution or reproduction of any part or all of the contents in any form is prohibited other than the following:
|
|
1. You may print or download to a local hard disk extracts for your personal and non-commercial use only.
|
|
2. You may copy the content to individual third parties for their personal use, but only if you acknowledge the author David Bird as the source of the material.
|
|
3. You may not, except with my express written permission, distribute or commercially exploit the content.
|
|
4. You may not transmit it or store it in any other website or other form of electronic retrieval system for commercial purposes.
|
|
|
|
The above copyright ('as annotated') notice and this permission notice shall be included in all copies or substantial portions of the Software and where the
|
|
software use is visible to an end-user.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" FOR PRIVATE USE ONLY, IT IS NOT FOR COMMERCIAL USE IN WHOLE OR PART OR CONCEPT. FOR PERSONAL USE IT IS SUPPLIED WITHOUT WARRANTY
|
|
OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
See more at http://www.dsbird.org.uk
|
|
*/
|
|
// For voltage
|
|
// extern "C" int rom_phy_get_vdd33();
|
|
|
|
#include "time.h" // Built-in
|
|
#include <SPI.h> // Built-in
|
|
//#include "epaper_fonts.h"
|
|
#include "WiFiClient.h"
|
|
#include "common.h"
|
|
#include "Ecran.h"
|
|
#include "Ctrl.h"
|
|
|
|
Ctrl p; // = Ctrl::getSingletonInstance();
|
|
Ctrl * ctrl = &p;
|
|
|
|
Ecran ecran;
|
|
// WiFiClient client; // wifi client object
|
|
|
|
#include "Connect.h"
|
|
// Change to your WiFi credentials
|
|
Connect connect(& ecran, "Livebox-37cc", "8A6060920A8A86896F770F2C47");
|
|
|
|
#include "Timer.h"
|
|
Timer timer(& ecran, & connect, "CET-1CEST,M3.5.0,M10.5.0/3");
|
|
|
|
|
|
#include "Domoticz.h"
|
|
Domoticz domo(& ecran, & connect, "192.168.1.3", "81");
|
|
Room rooms[NB_ROOMS] = {
|
|
// name, Temperature_idx, Consigne_idx, Volet_idx, Temperature, Consigne, open, presence_idx
|
|
{"Chambre", "Chambre", "ConsigneConfortChambre", "VoletChambreVirtuel", 0, 0, false, "Domi"},
|
|
{"Theo", "ChambreTheo", "ConsigneConfortTheo", "VoletTheoVirtuel", 0, 0, false, "Theo"},
|
|
{"Manon", "ChambreManon", "ConsigneConfortTheo", "VoletManonVirtuel", 0, 0, false, "Manon"},
|
|
{"Salon", "TemperatureSalon", "ConsigneConfortSalon", "VoletPorteSalon", 0, 0, false, ""},
|
|
{"Bureau", "Bureau", "ConsigneConfortBureau", "VoletVelux", 0, 0, false, "Moi"},
|
|
{"Cuisine", "TemperatureCuisine", "ConsigneConfortCuisine", "VoletCuisine", 0, 0, false, ""},
|
|
{"Cheminee", "Cheminee", "ConsigneConfortSalon", "VoletSalonTele", 0, 0, false, ""},
|
|
//{"Sdb", 952, 0, 0, 0, 0, false, 0}
|
|
{"Grenier", "TemperatureGrenier", "ConsigneConfortGrenier", "", 0, 0, false, ""}
|
|
};
|
|
|
|
//Room rooms[NB_ROOMS] = {
|
|
// // name, Temperature_idx, Consigne_idx, Volet_idx, Temperature, Consigne, open, presence_idx
|
|
// {"Chambre", 916, 213, 824, 0, 0, false, 316},
|
|
// {"Theo", 1150, 211, 823, 0, 0, false, 319},
|
|
// {"Manon", 1178, 212, 822, 0, 0, false, 246},
|
|
// {"Salon", 675, 210, 701, 0, 0, false, 0},
|
|
// {"Bureau", 668, 214, 0, 0, 0, false, 318},
|
|
// {"Cuisine", 917, 1171, 684, 0, 0, false, 0},
|
|
// {"Cheminee", 1152, 210, 699, 0, 0, false, 0},
|
|
// {"Sdb", 952, 0, 0, 0, 0, false, 0}
|
|
//};
|
|
|
|
// #include "Energy.h"
|
|
// Energy energy(& ecran, & connect, "https://conso.boris.sh", "80");
|
|
|
|
#include "Meteo.h"
|
|
// Use your own API key by signing up for a free developer account at https://openweathermap.org/
|
|
// Your _ISO-3166-1_two-letter_country_code country code, on OWM find your nearest city and the country code is displayed
|
|
// https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
|
|
Meteo meteo(& ecran, & connect, & timer, "feba3f4d926db3b358a25ec782bd1c8b", "api.openweathermap.org", "La Gacilly", "FR");
|
|
|
|
#include "Designer.h"
|
|
Designer designer(& ecran, & meteo, & connect, & domo, & timer);
|
|
|
|
RTC_DATA_ATTR int boucle = 0;
|
|
// RTC_NOINIT_ATTR int boucle = 0;
|
|
|
|
//#########################################################################################
|
|
void setup() {
|
|
timer.SleepDuration = 30;
|
|
timer.StartTime = millis();
|
|
// meteo.timer = & timer;
|
|
|
|
ctrl->connect = & connect;
|
|
ctrl->ecran = & ecran;
|
|
ctrl->designer = & designer;
|
|
ctrl->timer = & timer;
|
|
ctrl->domoticz = & domo;
|
|
|
|
for (int i = 0; i < NB_ROOMS; i++) {
|
|
domo.rooms[i] = &rooms[i];
|
|
}
|
|
|
|
Serial.begin(115200);
|
|
ecran.initialise();
|
|
ecran.clear();
|
|
|
|
float voltage = analogRead(35) / 4096.0 * 7.46;
|
|
|
|
if (connect.start() == WL_CONNECTED) { // && timer.setupTime() == true) {
|
|
|
|
String v = domo.getVariableValue(76);
|
|
boucle = v.toInt();
|
|
|
|
timer.loadCurrentTime();
|
|
if (debug || (timer.CurrentHour >= timer.WakeupTime && timer.CurrentHour <= timer.SleepTime)) {
|
|
|
|
if (debug) Serial.println("After Timer : " + String((millis() - timer.StartTime) / 1000.0, 3) + "-secs");
|
|
|
|
bool meteo_loaded = meteo.loadData();
|
|
|
|
if (debug) Serial.println("After Meteo : " + String((millis() - timer.StartTime) / 1000.0, 3) + "-secs");
|
|
|
|
|
|
domo.loadData();
|
|
|
|
if (debug) Serial.println("After Domo : " + String((millis() - timer.StartTime) / 1000.0, 3) + "-secs");
|
|
|
|
//domo.loadLinky(idx, "");
|
|
// connect->loadBitmap("192.168.1.36", "80", "/e-paper/Ragnard.bmp");
|
|
if (meteo_loaded) { // Only if received both Weather or Forecast proceed
|
|
boucle ++;
|
|
domo.setVariableValue(76, String(boucle));
|
|
connect.stop(); // Reduces power consumption
|
|
do {
|
|
designer.displayWeather(boucle);
|
|
if (debug) Serial.println("After Display : " + String((millis() - timer.StartTime) / 1000.0, 3) + "-secs");
|
|
} while (ecran._display->nextPage());
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
|
|
ecran.fonts.setFont(FONT_36);
|
|
|
|
ecran.drawString(100, 100, "Wifi", CENTER, GxEPD_BLACK);
|
|
|
|
int epaisseur = 8;
|
|
int width = 240;
|
|
int height = 60;
|
|
int angle = 120;
|
|
int x = (SCREEN_WIDTH - width) / 2 ;
|
|
int y = (SCREEN_HEIGHT - height) / 2;
|
|
|
|
int x0 = 300;;
|
|
int y0 = 120;
|
|
int nb_space = 4;
|
|
int ep_wifi = 6;
|
|
int rayon = 10 * ep_wifi + 5;
|
|
for (int j = 0; j < nb_space * 2; j++) {
|
|
if (j % 2 == 0) {
|
|
for (int i = 0; i < ep_wifi; i++) {
|
|
ecran.drawArc(x0, y0 + i + (j * ep_wifi), rayon -i - j * ep_wifi, -150, -30, GxEPD_BLACK);
|
|
}
|
|
}
|
|
}
|
|
ecran._display->fillCircle(x0,y0 + ep_wifi + (2 * nb_space - 1) * ep_wifi, 10, GxEPD_BLACK);
|
|
|
|
//float voltage = ((float)rom_phy_get_vdd33()) / 1000;
|
|
|
|
// Serial.print("voltage=");
|
|
|
|
// Serial.println(voltage);
|
|
|
|
do {
|
|
for (int i = 0; i < epaisseur; i++) {
|
|
ecran._display->drawRoundRect(x - i, y - i, width + 2 * i, height + 2 * i, 10 + i, GxEPD_BLACK);
|
|
}
|
|
ecran._display->fillRect(x + width, y + 10, 20, height - 20, GxEPD_BLACK);
|
|
ecran.fonts.setFont(FONT_18);
|
|
ecran.drawString(x + width / 2 - 20, y + height / 2, "Batterie faible", CENTER, GxEPD_RED);
|
|
ecran._display->fillRect(x, y, 20, height, GxEPD_BLACK);
|
|
|
|
ecran.fonts.setFont(FONT_36);
|
|
ecran.drawString(x - 50, y + 2 * height, "Voltage " + String(voltage, 2) + "V", CENTER, GxEPD_BLACK);
|
|
|
|
if (debug) Serial.println("After Display : " + String((millis() - timer.StartTime) / 1000.0, 3) + "-secs");
|
|
} while (ecran._display->nextPage());
|
|
//timer.shutDown();
|
|
}
|
|
timer.sleep();
|
|
}
|
|
|
|
//#########################################################################################
|
|
void loop() { // this will never run!
|
|
}
|
|
|
|
/*
|
|
Version 16.0 reformatted to use u8g2 fonts
|
|
1. Added ß to translations, eventually that conversion can move to the lang_xx.h file
|
|
2. Spaced temperature, pressure and precipitation equally, suggest in DE use 'niederschlag' for 'Rain/Snow'
|
|
3. No-longer displays Rain or Snow unless there has been any.
|
|
4. The nn-mm 'Rain suffix' has been replaced with two rain drops
|
|
5. Similarly for 'Snow' two snow flakes, no words and '=Rain' and '"=Snow' for none have gone.
|
|
6. Improved the Cloud Cover icon and only shows if reported, 0% cloud (clear sky) is no-report and no icon.
|
|
7. Added a Visibility icon and reported distance in Metres. Only shows if reported.
|
|
8. Fixed the occasional sleep time error resulting in constant restarts, occurred when updates took longer than expected.
|
|
9. Improved the smaller sun icon.
|
|
10. Added more space for the Sunrise/Sunset and moon phases when translated.
|
|
|
|
Version 16.1 Correct timing errors after sleep - persistent problem that is not deterministic
|
|
1. Removed Weather (Main) category e.g. previously 'Clear (Clear sky)', now only shows area category of 'Clear sky' and then ', caterory1' and ', category2'
|
|
2. Improved accented character displays
|
|
|
|
Version 16.2 Correct comestic icon issues
|
|
1. At night the addition of a moon icon overwrote the Visibility report, so order of drawing was changed to prevent this.
|
|
2. RainDrop icon was too close to the reported value of icon_64x64_10d moved right. Same for Snow Icon.
|
|
3. Improved large sun icon sun rays and improved all icon drawing logic, rain drops now use common shape.
|
|
5. Moved MostlyCloudy Icon down to align with the rest, same for MostlySunny.
|
|
6. Improved graph axis alignment.
|
|
|
|
Version 16.3 Correct comestic icon issues
|
|
1. Reverted some aspects of UpdateLocalTime() as locialisation changes were unecessary and can be achieved through lang_aa.h files
|
|
2. Correct configuration mistakes with moon calculations.
|
|
|
|
Version 16.4 Corrected time server addresses and adjusted maximum time-out delay
|
|
1. Moved time-server address to the credentials file
|
|
2. Increased wait time for a valid time setup to 10-secs
|
|
3. Added a lowercase conversion of hemisphere to allow for 'North' or 'NORTH' or 'nOrth' entries for hemisphere
|
|
4. Adjusted graph y-axis alignment, redcued number of x dashes
|
|
|
|
Version 16.5 Clarified connections for Waveshare ESP32 driver board
|
|
1. Added SPI.end(); and SPI.begin(CLK, MISO, MOSI, CS); to enable explicit definition of pins to be used.
|
|
|
|
Version 16.6 changed GxEPD2 initialisation from 115200 to 0
|
|
1. Display.init(115200); becomes ecran._display->init(0); to stop blank screen following update to GxEPD2
|
|
|
|
Version 16.7 changed u8g2 fonts selection
|
|
1. Omitted 'FONT(' and added _tf to font names either Regular (R) or Bold (B)
|
|
|
|
Version 16.8
|
|
1. Added extra 20-secs of sleep to allow for slow ESP32 RTC timers
|
|
|
|
Version 16.9
|
|
1. Added probability of precipitation display e.g. 17%
|
|
|
|
Version 16.10
|
|
1. Updated display inittialisation for 7.5" T7 display type, which iss now the standard 7.5" display type.
|
|
|
|
Version 16.11
|
|
1. Adjusted graph drawing for negative numbers
|
|
2. Correct offset error for precipitation
|
|
|
|
Version 16.12
|
|
1. Modified to enable 1/2 buffer display of 3-colour displays
|
|
|
|
Version 18.00
|
|
1 refactoring all code to create objects
|
|
2 add colors in writeString
|
|
3 connect to domoticz
|
|
|
|
|
|
*/
|