Journal

/

Repurposed the e-reader into a news tracker

Repurposed the e-reader for regular use as a news, stocks, and weather dashboard.

front back
front

Swapped out the ESP-32-WROOM for an ESP32 NodeMCU D1—smaller, better form factor. Connected a DHT22 sensor for temperature and humidity data.

Weather: 26µs/50µs/70µs pulses from the DHT22’s single-wire protocol are too fast for ESP32 standard APIs. Ported this clever bit-banging from ESP8266 to ESP32:

static inline int dht_await_pin_state(int state, int timeout)
{
    int t;
    static const uint16_t delta = 1;

    for (t = 0; t < timeout; t += delta) {
        ets_delay_us(delta);
        if (gpio_get_level(DHT_PIN) == state)
            return t;
    }
    return 0;
}

static inline int dht_get_raw_data(unsigned char buf[BUFLEN])
{
    /* init code and preamble */

    for (i = 0; i < BUFLEN; i++) {
        if (!(pwl = dht_await_pin_state(1, 50))) {
            rc = 4;
            xQueueSend(dht_evt_queue, &rc, (TickType_t) 0);
            return 0;
        }
        if (!(pwh = dht_await_pin_state(0, 70))) {
            rc = 5;
            xQueueSend(dht_evt_queue, &rc, (TickType_t) 0);
            return 0;
        }
        buf[i] = pwh > pwl;
    }
    return 1;
}

Stocks: Obtained two weeks EOD data from Polygon.io—maximum possible with 512 KB RAM. Deployed a simple Flask API on VPS to manage the watchlist and relay the feed. Wrapped the API in FastCGI and exposed it through chroot-ed htpasswd + slowcgi + httpd—battle-tested OpenBSD base-system tools.

Rolled my own stepped graph for simplicity, but the code is hideous. Needed vTaskDelay() to prevent the watchdog timer from triggering. Will look into Bresenham’s in a future revision.

News: Used Channel NewsAsia RSS feed for news. Hand-coded the XML parsing in C—no Flask backend at the time. Now that I have one for stocks, will move the feed through the Flask backend in the next revision.

epd_init() stalled intermittently on first refresh() after flash. Toggling delay values in refresh() resolved it. If the first refresh succeeded, system remained stable. Could not find the root cause. Suspect noisy supply due to powering display via MCU.

Commit: a92c86a.