diff --git a/examples/3. Projects/1-Weather_station_example/1-Weather_station_example.ino b/examples/3. Projects/1-Weather_station_example/1-Weather_station_example.ino index bd4c678..63b489b 100644 --- a/examples/3. Projects/1-Weather_station_example/1-Weather_station_example.ino +++ b/examples/3. Projects/1-Weather_station_example/1-Weather_station_example.ino @@ -6,59 +6,51 @@ https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/ This example will show you how you can use Inkplate 6 to display API data, - e.g. Metaweather public weather API + in this example Metaweather public weather API which provide weather info. + As a result, you get a functional weather station which shows today's + forecast and 3 days forecast on your Inkplate display. IMPORTANT: - Make sure to change your desired city, timezone and wifi credentials below - Also have ArduinoJSON installed in your Arduino libraries + Make sure you have changed your desired city, timezone and WiFi credentials below. + You will also need to install ArduinoJSON library. + Download from here: https://github.com/bblanchon/ArduinoJson Want to learn more about Inkplate? Visit www.inkplate.io Looking to get support? Write on our forums: http://forum.e-radionica.com/en/ 28 July 2020 by e-radionica.com */ -// ---------- CHANGE HERE -------------: +// ---------------- CHANGE HERE ---------------: -// Time zone for adding hours -int timeZone = 2; +int timeZone = 2; //Update your timezone here. 2 means UTC+2 -// City search query -char city[128] = "ZAGREB"; +char city[128] = "SHENZHEN"; //Enter city name you wish to get forecast for -// Change to your wifi ssid and password -char *ssid = ""; -char *pass = ""; +// Change to your WiFi SSID and password +char *ssid = "e-radionica.com"; +char *pass = "crodusino"; -// ---------------------------------- +#define DELAY_MS 15000 //Delay between screen refreshes goes here + +// ---------------------------------------------- -// Include Inkplate library to the sketch #include "Inkplate.h" - -// Header file for easier code readability -#include "Network.h" - -// Including fonts used +#include "Network.h" //Header file for easier code readability +//Include custom fonts & icons used #include "Fonts/Roboto_Light_48.h" #include "Fonts/Roboto_Light_36.h" #include "Fonts/Roboto_Light_120.h" +#include "icons.h" //Generated using embedded iconConvert.py script -// Including icons generated by the py file -#include "icons.h" +Inkplate display(INKPLATE_1BIT); //Inkplate object -// Delay between API calls -#define DELAY_MS 15000 +Network network; // All our network functions are in this object, see Network.h -// Inkplate object -Inkplate display(INKPLATE_1BIT); - -// All our network functions are in this object, see Network.h -Network network; - -// Contants used for drawing icons +//Constants used for drawing icons char abbrs[32][16] = {"sn", "sl", "h", "t", "hr", "lr", "s", "hc", "lc", "c"}; const uint8_t *logos[16] = {icon_sn, icon_sl, icon_h, icon_t, icon_hr, icon_lr, icon_s, icon_hc, icon_lc, icon_c}; -// Variables for storing temperature +//Variables for storing temperature char temps[8][4] = { "0F", "0F", @@ -66,7 +58,7 @@ char temps[8][4] = { "0F", }; -// Variables for storing days of the week +//Variables for storing days of the week char days[8][4] = { "", "", @@ -74,18 +66,13 @@ char days[8][4] = { "", }; -// Variable for counting partial refreshes -long refreshes = 0; +long refreshes = 0; //Variable for counting partial refreshes +const int fullRefresh = 10; //Constant to determine when to full update -// Constant to determine when to full update -const int fullRefresh = 10; - -// Variables for storing current time and weather info +//Variables for storing current time and weather info char currentTemp[16] = "0F"; char currentWind[16] = "0m/s"; - char currentTime[16] = "9:41"; - char currentWeather[32] = "-"; char currentWeatherAbbr[8] = "th"; @@ -98,18 +85,18 @@ void drawTime(); void setup() { - // Begin serial and display + //Begin serial and and begin display Serial.begin(115200); - display.begin(); + display.begin(); //Call this function only once! - // Initial cleaning of buffer and physical screen + //Initial cleaning of buffer and physical screen display.clearDisplay(); display.clean(); - // Calling our begin from network.h file + //Calling our begin from network.h file network.begin(city); - // If city not found, do nothing + //If city not found, write error message and stop if (network.location == -1) { display.setCursor(50, 290); @@ -120,57 +107,57 @@ void setup() ; } - // Welcome screen + //Welcome screen display.setCursor(50, 290); display.setTextSize(3); display.print(F("Welcome to Inkplate 6 weather example!")); display.display(); - // Wait a bit before proceeding - delay(5000); + //Wait a bit before proceeding + delay(3000); } void loop() { - // Clear display + //Clear display display.clearDisplay(); - // Get all relevant data, see Network.cpp for info + //Get all relevant data, see Network.cpp for info network.getTime(currentTime); network.getDays(days[0], days[1], days[2], days[3]); network.getData(city, temps[0], temps[1], temps[2], temps[3], currentTemp, currentWind, currentTime, currentWeather, currentWeatherAbbr); - // Draw data, see functions below for info + //Draw data, see functions below in Network.cpp for info drawWeather(); drawCurrent(); drawTemps(); drawCity(); drawTime(); - // Refresh full screen every fullRefresh times, defined above + //Refresh full screen every fullRefresh times if (refreshes % fullRefresh == 0) display.display(); else display.partialUpdate(); - // Go to sleep before checking again + //Go to sleep before checking again esp_sleep_enable_timer_wakeup(1000L * DELAY_MS); (void)esp_light_sleep_start(); ++refreshes; } -// Function for drawing weather info +//Function for drawing weather info void drawWeather() { // Searching for weather state abbreviation for (int i = 0; i < 10; ++i) { - // If found draw specified icon + //If found draw specified icon, draw it if (strcmp(abbrs[i], currentWeatherAbbr) == 0) display.drawBitmap(50, 50, logos[i], 152, 152, BLACK); } - // Draw weather state + //Draw current weather state display.setTextColor(BLACK, WHITE); display.setFont(&Roboto_Light_36); display.setTextSize(1); @@ -178,10 +165,10 @@ void drawWeather() display.println(currentWeather); } -// Function for drawing current time +//Function for drawing current time void drawTime() { - // Drawing current time + //Drawing current time stored in currentTime variable display.setTextColor(BLACK, WHITE); display.setFont(&Roboto_Light_36); display.setTextSize(1); @@ -190,10 +177,10 @@ void drawTime() display.println(currentTime); } -// Function for drawing city name +//Function for drawing city name void drawCity() { - // Drawing city name + //Drawing city name display.setTextColor(BLACK, WHITE); display.setFont(&Roboto_Light_36); display.setTextSize(1); @@ -202,10 +189,10 @@ void drawCity() display.println(city); } -// Function for drawing temperatures +//Function for drawing temperatures void drawTemps() { - // Drawing 4 black rectangles in which temperatures will be written + //Drawing 4 black rectangles into which temperatures will be written int rectWidth = 150; int rectSpacing = (800 - rectWidth * 4) / 5; @@ -216,6 +203,7 @@ void drawTemps() int textMargin = 6; + //Setting font specifics, writing the actual weather info display.setFont(&Roboto_Light_48); display.setTextSize(1); display.setTextColor(WHITE, BLACK); @@ -232,7 +220,7 @@ void drawTemps() display.setCursor(4 * rectSpacing + 3 * rectWidth + textMargin, 300 + textMargin + 70); display.println(days[3]); - // Drawing temperature values into black rectangles + //Drawing temperature values into black rectangles display.setFont(&Roboto_Light_48); display.setTextSize(1); display.setTextColor(WHITE, BLACK); @@ -254,10 +242,10 @@ void drawTemps() display.println(F("C")); } -// Current weather drawing function +//Current weather drawing function void drawCurrent() { - // Drawing current information + //Drawing current information // Temperature: display.setFont(&Roboto_Light_120); @@ -276,7 +264,7 @@ void drawCurrent() display.setCursor(x, y); display.println(F("C")); - // Wind: + //Wind: display.setFont(&Roboto_Light_120); display.setTextSize(1); display.setTextColor(BLACK, WHITE); @@ -293,7 +281,7 @@ void drawCurrent() display.setCursor(x, y); display.println(F("m/s")); - // Labels underneath + //Labels underneath display.setFont(&Roboto_Light_36); display.setTextSize(1);