├── imgs └── board_128x32.jpg ├── README.md └── src ├── api └── api.php └── espweather └── espweather.ino /imgs/board_128x32.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deantonious/esp8266WeatherMonitor/HEAD/imgs/board_128x32.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## esp8266 WeatherMonitor 2 | Arduino code and PHP api for a simple ESP8266 weather monitor with 128x32 pixel oled display. 3 |

-------------------------------------------------------------------------------- /src/api/api.php: -------------------------------------------------------------------------------- 1 | main->temp; 13 | $temp_min = $weather->main->temp_min; 14 | $temp_max = $weather->main->temp_max; 15 | 16 | $temp = $temp - 273.15; 17 | $temp_min = $temp_min - 273.15; 18 | $temp_max = $temp_max - 273.15; 19 | $humidity = $weather->main->humidity; 20 | $pressure = $weather->main->pressure; 21 | $conditions = $weather->weather[0]->main; 22 | 23 | $date = getdate(); 24 | $weekday = date("D"); 25 | 26 | $data = array( 27 | "temp" => round($temp), 28 | "temp_min" => round($temp_min), 29 | "temp_max" => round($temp_max), 30 | "humidity" => $humidity, 31 | "pressure" => $pressure, 32 | "conditions" => $conditions, 33 | "weekday" => $weekday, 34 | "day" => $date["mday"], 35 | "month" => $date["mon"], 36 | "year" => $date["year"], 37 | "hours" => $date["hours"], 38 | "minutes" => $date["minutes"], 39 | "seconds" => $date["seconds"] 40 | ); 41 | 42 | echo json_encode($data); 43 | 44 | ?> -------------------------------------------------------------------------------- /src/espweather/espweather.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | /* OLED DETAILS */ 7 | #define PIN_RST D2 8 | #define PIN_SDA D4 9 | #define PIN_SCL D5 10 | 11 | U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, PIN_RST, PIN_SCL, PIN_SDA); 12 | 13 | /* WIFI DETAILS */ 14 | const char* ssid = "SSID"; 15 | const char* password = "PASSWORD"; 16 | const char* host_name = "HOST_NAME"; 17 | const char* api_url = "API_PHP_URL"; 18 | 19 | /* VARIABLES */ 20 | bool booted = false; 21 | int second_count = 0; 22 | int page = 0; 23 | 24 | /* WEATHER VARIABLES */ 25 | int temp; 26 | int temp_min; 27 | int temp_max; 28 | byte humidity; 29 | int pressure; 30 | String conditions; 31 | String weekday; 32 | byte day; 33 | byte month; 34 | int year; 35 | byte hours; 36 | byte minutes; 37 | byte seconds; 38 | 39 | void setup() { 40 | Serial.begin(115200); 41 | Serial.println(); 42 | 43 | WiFi.hostname(host_name); 44 | WiFi.mode(WIFI_STA); 45 | WiFi.begin(ssid, password); 46 | 47 | Serial.printf("Connecting to %s\n", ssid); 48 | while (WiFi.status() != WL_CONNECTED) { 49 | delay(500); 50 | Serial.print("."); 51 | } 52 | Serial.println("Succesfully connected!"); 53 | Serial.print("Host Name: "); 54 | Serial.println(WiFi.hostname()); 55 | Serial.print("IP address: "); 56 | Serial.println(WiFi.localIP()); 57 | 58 | u8g2.begin(); 59 | } 60 | 61 | void loop() { 62 | String string; 63 | 64 | if (!booted && second_count >= 4) { 65 | booted = true; 66 | page = 1; 67 | } 68 | 69 | u8g2.firstPage(); 70 | do { 71 | if (page == 0) { 72 | 73 | u8g2.setFont(u8g2_font_open_iconic_embedded_1x_t); 74 | u8g2.drawGlyph(60, 12, 0x0050); 75 | 76 | u8g2.setFont(u8g2_font_mozart_nbp_tf); 77 | u8g2.drawStr(26, 30, WiFi.localIP().toString().c_str()); 78 | 79 | } 80 | if (page == 1) { 81 | if (second_count >= 5) { 82 | second_count = 0; 83 | 84 | if (WiFi.status() == WL_CONNECTED) { 85 | 86 | HTTPClient http; 87 | http.begin(api_url); 88 | int httpCode = http.GET(); 89 | 90 | if (httpCode > 0) { 91 | 92 | const size_t bufferSize = JSON_OBJECT_SIZE(14); 93 | DynamicJsonBuffer jsonBuffer(bufferSize); 94 | JsonObject& root = jsonBuffer.parseObject(http.getString()); 95 | 96 | temp = root["temp"]; 97 | temp_min = root["temp_min"]; 98 | temp_max = root["temp_max"]; 99 | humidity = root["humidity"]; 100 | pressure = root["pressure"]; 101 | const char *a1 = root["conditions"]; 102 | conditions = String(a1); 103 | 104 | const char *a2 = root["weekday"]; 105 | weekday = String(a2); 106 | day = root["day"]; 107 | month = root["month"]; 108 | year = root["year"]; 109 | hours = root["hours"]; 110 | minutes = root["minutes"]; 111 | seconds = root["seconds"]; 112 | 113 | } 114 | http.end(); 115 | } 116 | } 117 | 118 | u8g2.setFont(u8g2_font_open_iconic_weather_4x_t); 119 | if (conditions.equals("Clear")) 120 | u8g2.drawGlyph(0, 32, 0x0045); 121 | if (conditions.equals("Clouds")) 122 | u8g2.drawGlyph(0, 32, 0x0041); 123 | if (conditions.equals("Drizzle")) 124 | u8g2.drawGlyph(0, 32, 0x0040); 125 | if (conditions.equals("Thunderstorm") || conditions.equals("Rain") || conditions.equals("Snow")) 126 | u8g2.drawGlyph(0, 32, 0x0043); 127 | 128 | u8g2.setFont(u8g2_font_mozart_nbp_tf); 129 | string = weekday + " " + day + "/" + month + " H:" + humidity + "%"; 130 | u8g2.drawStr(40, 12, string.c_str()); 131 | 132 | u8g2.setFont(u8g2_font_crox3h_tf); 133 | string = String(temp) + "°C"; 134 | u8g2.drawUTF8(40, 32, string.c_str()); 135 | 136 | u8g2.setFont(u8g2_font_crox1h_tf); 137 | string = String(temp_min) + "° / " + temp_max + "°"; 138 | u8g2.drawUTF8(84, 32, string.c_str()); 139 | } 140 | } while (u8g2.nextPage()); 141 | 142 | second_count++; 143 | delay(1000); 144 | } --------------------------------------------------------------------------------