Skip to content

Commit

Permalink
added readable wind directions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Federlin committed Apr 15, 2020
1 parent c6233fb commit cdfe4a9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
5 changes: 4 additions & 1 deletion Fonts/README.md
@@ -1,7 +1,10 @@
# Fonts
In order to get e.g. German "Umlauts" displayed on the display using the Adafruit GFX library,
you need to supply your own 8bit Font, which actually contains these symbols.
To create one, you can use the fontconvert utility delivered together with the GFX library.

You can use the ones included here by copying them to the GFX Fonts/ folder.

To create one yourself, you can use the fontconvert utility delivered together with the GFX library.

fontconvert is in .pio/libdeps/nodemcuv2/Adafruit GFX Library_ID13/fontconvert

Expand Down
15 changes: 14 additions & 1 deletion README.md
@@ -1,2 +1,15 @@
# 8266weatherdisplay
A weatherdisplay project
A weatherdisplay project based on http://educ8s.tv/art-deco-weather-forecast-display/

I improved it in a couple of ways:

- Created different areas to display the different information elements. This makes it a little easier to adapt the code to different screen sizes. As scaling of the weather bitmaps is not possible, this will only go so far.
- definitions for 80x160 / 128x160 and 240x240 screens are included
- added a description area in which the Weather description and wind direction and speed can be displayed
- fixed the JSON parsing and adapted it to ArduinoJSON 6
- Introduced 8bit Fonts in order to display German "Umlauts" in the weather description (see Fonts directory)
- As openweathermap transmits the weather description in UTF8 encoding, the tft.print function expects 8859-1 encoded data, I also had to add some code to to the conversion
- made the code a bit nicer in that it now uses a struct to store the weather data
- in fact, I made it an array of struct, to store the weather information of the next 24 hours and flip through them
- got rid of the busy waiting in the loop(). I'm looking to add functionality like flipping through the pages using a button or rotary encoder
- included the ezTime library for dealing with timezones more easily
42 changes: 24 additions & 18 deletions src/WeatherForecast.ino
@@ -1,4 +1,5 @@
//////////////////////////////////////////////
//////////////////////////////////////////////
// Based on //
// Art Deco Weather Forecast Display //
// //
// http://www.educ8s.tv //
Expand Down Expand Up @@ -41,9 +42,9 @@ long nextpoll;
long nextswitch;


const char* ssid = "Buschfunk"; // SSID of local network
const char* password = "FritzBoxIstTotalSuper"; // Password on network
String APIKEY = "fb1d7728528b56504cb6af0aba6c6fbc"; // change to your API Key
const char* ssid = "YOUR_SSID"; // SSID of local network
const char* password = "YOUR_PASSWORD"; // Password on network
String APIKEY = "YOUR_API_KEY"; // change to your API Key
String CityID = "2885397"; //change to place of choice

Timezone myTZ;
Expand Down Expand Up @@ -107,11 +108,9 @@ const int tempareah=35;
WiFiClient client;
char servername[]="api.openweathermap.org"; // remote server we will connect to


// TODO: currently unused, but needs to be populated based on hour for which forecast is valid
boolean night = false;
int counter = 360;
String weatherDescription ="";
String weatherLocation = "";
float Temperature;

struct weatherdata
{
Expand All @@ -122,18 +121,13 @@ struct weatherdata
char wind[14]; //270 @ 15 km/h
};

// typedef struct weatherdata Weatherdata;
// Weatherdata theWeatherdata;

struct weatherdata theWeatherdata[WEATHERDATA_SIZE];
int slot = 0;

extern unsigned char cloud[];
extern unsigned char thunder[];
extern unsigned char wind[];



// Init ST7735 80x160
// Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

Expand All @@ -146,7 +140,6 @@ static inline unsigned int to_latin9(const unsigned int code);
size_t utf8_to_latin9(char *const output, const char *const input, const size_t length);



void setup() {
Serial.begin(115200);

Expand Down Expand Up @@ -259,8 +252,9 @@ boolean getWeatherData() //client function to send/receive GET request data.
strcpy(theWeatherdata[cnt].description, description);

int winddir = root["list"][cnt]["wind"]["deg"];
char winddirchar[4];
itoa(winddir,winddirchar,10);
char winddirchar[3];
generateWindDir(winddir, winddirchar);
//itoa(winddir,winddirchar,10);
int windspeed = root["list"][cnt]["wind"]["speed"]; // m/s in metric
char windspeedchar[4];
sprintf(windspeedchar,"%.0f",windspeed*3.6); //convert to km/h
Expand Down Expand Up @@ -310,6 +304,17 @@ void generateTimeString(long dt, char *str){
Serial.println(str);
}

void generateWindDir(int d, char *winddirchar){
if (22 <= d && d < 67) strcpy(winddirchar, "NO");
if (67 <= d && d < 112) strcpy(winddirchar, "O");
if (112 <= d && d < 157) strcpy(winddirchar, "SO");
if (157 <= d && d < 202) strcpy(winddirchar, "S");
if (202 <= d && d < 247) strcpy(winddirchar, "SW");
if (247 <= d && d < 292) strcpy(winddirchar, "W");
if (292 <= d && d < 337) strcpy(winddirchar, "NW");
if (337 <= d || d < 22) strcpy(winddirchar, "N");
}

void printData(int slot)
{
clearScreen();
Expand Down Expand Up @@ -339,8 +344,9 @@ void printData(int slot)
tft.setTextSize(1);
tft.setFont(&FreeSans11pt8b);
if (descrarea){
drawCentreChar(theWeatherdata[slot].description, descrareax+descrareaw/2, descrareay);
drawCentreChar(theWeatherdata[slot].wind, descrareax+descrareaw/2, descrareay+20);
//the offset to descrareay might have to be changed based on font size used
drawCentreChar(theWeatherdata[slot].description, descrareax+descrareaw/2, descrareay+15);
drawCentreChar(theWeatherdata[slot].wind, descrareax+descrareaw/2, descrareay+35);
}
}

Expand Down

0 comments on commit cdfe4a9

Please sign in to comment.