Skip to content

Instantly share code, notes, and snippets.

@jffry
Last active September 1, 2024 15:55
Show Gist options
  • Save jffry/251284f91f5866193b3ec673d188ab8e to your computer and use it in GitHub Desktop.
Save jffry/251284f91f5866193b3ec673d188ab8e to your computer and use it in GitHub Desktop.
Inkplate 10 code to show current hurricane forecast
/*
Shows the current Atlantic tropical weather outlook from the National Hurricane Center,
which is a part of the US NOAA. Refreshes hourly to ensure the image is up to date
(the actual forecast usually updates twice per day)
Automatically sleeps between refreshes so this is extremely battery efficient.
Written by Jeffrey Stanton; I release this code under the terms of CC0-1.0
(https://creativecommons.org/publicdomain/zero/1.0) in the hopes you will
find something useful in here for your own cool projects!
*/
#include "HTTPClient.h"
#include "Inkplate.h"
#include "WiFi.h"
Inkplate display(INKPLATE_3BIT);
const char *WIFI_SSID = "SSID_REDACTED";
const char *WIFI_PASSWORD = "PASSWORD_REDACTED";
const char *IMAGE_URL = "https://www.nhc.noaa.gov/xgtwo/two_atl_2d0.png";
const int IMAGE_W = 900;
const int IMAGE_H = 665;
const int IMAGE_X = (E_INK_WIDTH - IMAGE_W) / 2;
const int IMAGE_Y = (E_INK_HEIGHT - IMAGE_H) / 2;
const uint64_t US_PER_SECOND = 1000000;
const uint64_t SLEEP_MINUTES = 60;
const uint64_t SLEEP_US = SLEEP_MINUTES * 60 * US_PER_SECOND;
void connectWifi() {
WiFi.mode(WIFI_MODE_STA);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
}
}
void drawHurricaneChart() {
if (!display.drawPngFromWeb(IMAGE_URL, IMAGE_X, IMAGE_Y, true)) {
display.println("Failed to load image");
}
}
void drawVoltage() {
float batteryV = display.readBattery();
display.setCursor(10, 10);
display.setTextSize(2);
display.setTextColor(0x0000, 0xffff); //5-6-5 bits (foreground, background)
display.print(batteryV, 3);
display.println("V / 4.2V");
}
//runs first time board boots and also during wakeup (on timer or due to button press)
void setup() {
esp_sleep_enable_timer_wakeup(SLEEP_US);
esp_sleep_enable_ext0_wakeup(GPIO_NUM_36, LOW); //wakeup if user presses wake button on left side
connectWifi();
display.begin();
display.clearDisplay();
drawHurricaneChart();
drawVoltage();
display.display();
WiFi.mode(WIFI_OFF);
esp_deep_sleep_start();
}
//must be present to compile, but I don't use this for anything
void loop() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment