From afa3c39fc322edb98d5cb1fa9f95d01cf91f4394 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 6 Dec 2023 10:50:31 -0700 Subject: [PATCH] TZ setup in UI --- README.md | 23 ++++++++++++++++++----- network.cpp | 29 ++++++++++++++++++++++++++--- network.h | 3 +++ wallart.ino | 48 ++++++------------------------------------------ 4 files changed, 53 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 44c7781..d49fdc9 100644 --- a/README.md +++ b/README.md @@ -20,14 +20,27 @@ Most people, after watching it for a bit, form different ideas about what it's displaying. That's cool. + +Setup +----- + +When you turn it on, +it will come up as a new access point, +called "WallArt". +Connect to that to configure. + +Please configure the clock before the WiFi: +this will set up your time zone, +so it doesn't blind you in the middle of the night. + + Reset ------ Plug the device in, -connect GND to pin A0, -and briefly press the reboot button. -It will flash orange and blue a few times -to let you know it has reset. +and connect GND to pin A0 (right next to GND). +The red LED on the Feather board should come on immediately, +indicating it needs the network set up again. WiFi @@ -98,7 +111,7 @@ Reset the device, and select the "Update" button instead of configuring WiFi. Then you can upload the new .bin firmware file. -You will have to reconfigure networking after this. +You may have to reconfigure networking after this. Philosophy diff --git a/network.cpp b/network.cpp index d738aff..2615af2 100644 --- a/network.cpp +++ b/network.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -8,13 +9,25 @@ WiFiManager wfm; void network_reset() { + Serial.println("Resetting network"); wfm.resetSettings(); } -void network_setup(char *password) { - String hostid = String(ESP.getEfuseMac(), HEX); - String hostname = "Wall Art " + hostid; +void on_time_available(struct timeval *t) +{ + struct tm timeInfo; + getLocalTime(&timeInfo, 1000); + Serial.println(&timeInfo, "%A, %B %d %Y %H:%M:%S %Z %z "); +} +void network_setup(char *password) { + String hostname = "WallArt"; + + WiFiManagerNS::NTP::onTimeAvailable(&on_time_available); + WiFiManagerNS::init(&wfm); + + std::vector menu = {"wifi", "info", "custom", "param", "sep", "restart", "exit"}; + wfm.setMenu(menu); wfm.setConfigPortalBlocking(false); wfm.setHostname(hostname); wfm.autoConnect(hostname.c_str(), password); @@ -24,7 +37,17 @@ bool connected() { return WiFi.status() == WL_CONNECTED; } +bool timeConfigured = false; + void pause(uint32_t dwMs) { + if (connected() && !timeConfigured) { + WiFiManagerNS::configTime(); + timeConfigured = true; + } + if (!digitalRead(RESET_PIN)) { + network_reset(); + } + for (uint32_t t = 0; t < dwMs; t += 10) { wfm.process(); digitalWrite(LED_BUILTIN, !connected()); diff --git a/network.h b/network.h index cb378fc..b919c58 100644 --- a/network.h +++ b/network.h @@ -1,5 +1,8 @@ #pragma once +// Short this to ground to reset the network +#define RESET_PIN 26 + void network_reset(); void network_setup(char *password); bool connected(); diff --git a/wallart.ino b/wallart.ino index 80ec608..ee44fdd 100644 --- a/wallart.ino +++ b/wallart.ino @@ -1,18 +1,16 @@ - #include +#include #include #include #include -#include #include #include "durations.h" -#include "timezones.h" #include "picker.h" #include "network.h" #define NEOPIXEL_PIN 32 #define GRIDLEN 64 #define WFM_PASSWORD "artsy fartsy" -#define TIMEZONE TZ_US_Mountain +#define TIMEZONE TZ_US_Eastern /* * The hours when the day begins and ends. @@ -34,47 +32,19 @@ #define HTTPS_TIMEOUT (2 * SECOND) -#define RESET_PIN 26 CRGB grid[GRIDLEN]; -WiFiUDP ntpUDP; -NTPClient timeClient(ntpUDP); - -void do_reset() { - for (int i = 0; i < 8; i++) { - for (int j = 0; j < 8; j += 1) { - grid[j] = ((i+j)%2) ? (CRGB::Orange) : (CRGB::Blue); - } - FastLED.show(); - digitalWrite(LED_BUILTIN, i%2); - delay(300 * MILLISECOND); - } - network_reset(); -} - void setup() { pinMode(RESET_PIN, INPUT_PULLUP); pinMode(LED_BUILTIN, OUTPUT); + Serial.begin(19200); FastLED.addLeds(grid, GRIDLEN); // Maybe it's the plexiglass, but for my build, I need to dial back the red FastLED.setCorrection(0xd0ffff); - if (!digitalRead(RESET_PIN)) { - do_reset(); - } network_setup(WFM_PASSWORD); } -bool updateTime() { - if (timeClient.update()) { - time_t now = timeClient.getEpochTime(); - time_t local = TIMEZONE.toLocal(now); - setTime(local); - return true; - } - return false; -} - void fade(int cycles = 2) { int reps = (cycles*GRIDLEN) + random(GRIDLEN); int hue = random(256); @@ -291,7 +261,6 @@ void displayTime(unsigned long duration = 20 * SECOND) { FastLED.clear(); while (millis() < end) { - updateTime(); int hh = hour(); int mmss = now() % 3600; uint8_t hue = HUE_YELLOW; @@ -337,14 +306,9 @@ void loop() { uint8_t getprob = 4; bool conn = connected(); bool day = true; + timeStatus_t ts = timeStatus(); - switch (timeStatus()) { - case timeNotSet: - case timeNeedsSync: - updateTime(); - break; - } - if (timeStatus() == timeSet) { + if (ts == timeSet) { int hh = hour(); day = ((hh >= DAY_BEGIN) && (hh < DAY_END)); } @@ -355,7 +319,7 @@ void loop() { getprob = 16; } - if (!day || p.Pick(4)) { + if ((ts == timeSet) && (!day || p.Pick(4))) { // At night, only ever show the clock displayTime(2 * MINUTE); } else if (p.Pick(getprob)) {