wallart

8x8 pixel display firmware
git clone https://git.woozle.org/neale/wallart.git

Neale Pickett  ·  2024-06-09

network.cpp

 1#include <FastLED.h>
 2#include <WiFiManager.h>
 3#include <WiFiManagerTz.h>
 4#include <esp_wifi.h>
 5#include <esp_sntp.h>
 6#include <HTTPClient.h>	
 7#include <WiFiClientSecure.h>
 8#include "network.h"
 9
10WiFiManager wfm;
11
12void network_reset() {
13  Serial.println("Resetting network");
14  wfm.resetSettings();
15}
16
17
18bool time_was_accurate_once = false;
19bool clock_is_set() {
20  return time_was_accurate_once;
21}
22
23void on_time_available(struct timeval *t) {
24  struct tm timeInfo;
25  getLocalTime(&timeInfo, 1000);
26  Serial.println(&timeInfo, "%A, %B %d %Y %H:%M:%S %Z %z ");
27  time_was_accurate_once = true;
28}
29
30void network_setup(char *password) {
31  String hostname = "WallArt";
32
33  WiFiManagerNS::NTP::onTimeAvailable(&on_time_available);
34  WiFiManagerNS::init(&wfm, nullptr);
35
36  std::vector<const char *> menu = {"wifi", "info", "custom", "param", "sep", "update", "restart", "exit"};
37  wfm.setMenu(menu);
38	wfm.setConfigPortalBlocking(false);
39	wfm.setHostname(hostname);
40	wfm.autoConnect(hostname.c_str(), password);
41}
42
43bool connected() {
44	return WiFi.status() == WL_CONNECTED;
45}
46
47bool timeConfigured = false;
48
49void pause(uint32_t dwMs) {
50  if (connected() && !timeConfigured) {
51    WiFiManagerNS::configTime();
52    timeConfigured = true;
53  }
54  if (!digitalRead(RESET_PIN)) {
55    network_reset();
56  }
57
58	for (uint32_t t = 0; t < dwMs; t += 10) {
59		wfm.process();
60		digitalWrite(LED_BUILTIN, !connected());
61		delay(10);
62	}
63}