Skip to content

Commit e63a35d

Browse files
committed
Update seven segment word clock to use the D1 instead of the ESP8266
1 parent 878d399 commit e63a35d

File tree

1 file changed

+63
-7
lines changed

1 file changed

+63
-7
lines changed

sevensegwordclock/sevensegwordclock.ino

+63-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
// Use "NodeMCU 0.9 (ESP-12) to program (NOT Generic8266)
1+
// Use "NodeMCU 0.9 (ESP-12)" or "WEMOS mini D1 (clone)" to program (NOT Generic8266)
22
#include "config.h"
3+
34
#include <ESP8266WiFi.h>
5+
#include <ESP8266mDNS.h>
6+
#include <WiFiUdp.h>
7+
#include <ArduinoOTA.h>
8+
49
#include <time.h>
510
#include <coredecls.h> // required for settimeofday_cb()
611

@@ -13,9 +18,11 @@ const char* pass = SECRET_PWD;
1318
// Timing parameters
1419
time_t present_timestamp;
1520

21+
int progressStatus = 0;
22+
1623
// Display
1724
#define NUM_DIGITS 8
18-
const byte dataPin = D1;
25+
const byte dataPin = D4;
1926
const byte loadPin = D2;
2027
const byte clockPin = D3;
2128

@@ -32,19 +39,21 @@ void setup() {
3239

3340
Serial.begin(115200);
3441

35-
Serial.println("Hello 7seg Clock serial");
36-
display.showTextScroll("Connecting");
42+
Serial.println("Hello 7seg Clock serial d1");
43+
display.showTextScroll("Connecting D1.... ");
3744

3845
WiFi.begin(ssid, pass); // send credentials
3946
Serial.println("Connecting");
4047
int dot = 0;
4148
// wait for connection
42-
while (WiFi.status() != WL_CONNECTED) {
49+
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
4350
delay(500);
4451
display.showText(".", dot++, 1);
4552
}
4653
Serial.println("Connected");
47-
display.showTextScroll("Connected");
54+
Serial.print("IP address: ");
55+
Serial.println(WiFi.localIP());
56+
display.showTextScroll("Connected!!! ");
4857
delay(1000);
4958

5059
// implement NTP update of timekeeping (with automatic hourly updates)
@@ -54,13 +63,60 @@ void setup() {
5463
setenv("TZ", "EST+5EDT,M3.2.0/2:00:00,M11.1.0/2:00:00", 1);
5564

5665
// register a callback (execute whenever an NTP update has occurred)
57-
// DBP: Unclear if this is needed.
5866
settimeofday_cb(time_is_set);
67+
68+
// All sorts of OTA (over-the-air) updates.
69+
// Code mostly copied from https://randomnerdtutorials.com/esp8266-ota-updates-with-arduino-ide-over-the-air/
70+
ArduinoOTA.setPort(OTA_PORT);
71+
ArduinoOTA.setHostname("sevensegwordd1");
72+
ArduinoOTA.setPassword(OTA_PASSWORD);
73+
ArduinoOTA.onStart([]() {
74+
progressStatus = 0;
75+
display.showText("Start");
76+
digitalWrite(LED_BUILTIN, LOW);
77+
Serial.println("Start");
78+
});
79+
ArduinoOTA.onEnd([]() {
80+
digitalWrite(LED_BUILTIN, HIGH);
81+
display.showText("End");
82+
Serial.println("\nEnd");
83+
});
84+
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
85+
if (progressStatus == 0) {
86+
display.showText("Updating");
87+
}
88+
digitalWrite(LED_BUILTIN, progressStatus % 2);
89+
progressStatus++;
90+
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
91+
});
92+
ArduinoOTA.onError([](ota_error_t error) {
93+
digitalWrite(LED_BUILTIN, LOW);
94+
Serial.printf("Error[%u]: ", error);
95+
if (error == OTA_AUTH_ERROR) {
96+
display.showTextScroll("Auth failed");
97+
Serial.println("Auth Failed");
98+
} else if (error == OTA_BEGIN_ERROR) {
99+
display.showTextScroll("Begin failed");
100+
Serial.println("Begin Failed");
101+
} else if (error == OTA_CONNECT_ERROR) {
102+
display.showTextScroll("Connect failed");
103+
Serial.println("Connect Failed");
104+
} else if (error == OTA_RECEIVE_ERROR) {
105+
display.showTextScroll("Receive failed");
106+
Serial.println("Receive Failed");
107+
} else if (error == OTA_END_ERROR) {
108+
display.showTextScroll("End failed");
109+
Serial.println("End Failed");
110+
}
111+
delay(2000);
112+
});
113+
ArduinoOTA.begin();
59114
}
60115

61116
void loop() {
62117
// loop2();
63118
loopOrig();
119+
ArduinoOTA.handle();
64120
}
65121

66122
void loopOrig() {

0 commit comments

Comments
 (0)