Skip to content

Commit 62e3e7b

Browse files
committed
7.7.7.7 on Clock AP
1 parent 2dced6b commit 62e3e7b

File tree

4 files changed

+34
-28
lines changed

4 files changed

+34
-28
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,13 @@
22

33
![MAX7219 clock](https://i.imgur.com/NtAKrS4.jpg)
44

5-
Digital clock code with NTP sync for Arduino Nano 33 IoT and MAX7219 LED matrix
5+
Digital clock code with NTP sync for Arduino Nano 33 IoT and MAX7219 LED matrix
6+
7+
## Connecting to settings page
8+
9+
* Grab a device (computer/phone/tablet) with WiFi connectivity.
10+
* Hold **Select** for 5 seconds (or enter 'a' in the serial monitor).
11+
* If the clock **is not** connected to WiFi, it will display `7777` and broadcast a WiFi access point called “Clock”. Connect your device to “Clock” and browse to [7.7.7.7](http://7.7.7.7).
12+
* If the clock **is** connected to WiFi, it will flash its IP address (as a series of three 4-digit numbers). With your device on the same WiFi network, browse to that IP address.
13+
* To disconnect the clock from WiFi, hold Select for 15 seconds; it will revert to the “Clock” access point.
14+
* For security, the clock will stop serving the settings page (and “Clock” access point if applicable) after 2 minutes of inactivity.

display-MAX7219.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,19 @@ void displayTime(unsigned long mils, bool showSeconds){
7777
void displayClear(){
7878
for(int i=0; i<NUM_MAX; i++) { lc.clearDisplay(i); }
7979
}
80-
void displayByte(byte b){
80+
void displayInt(int n){
8181
int ci = (NUM_MAX*8)-1; //total column index - we will start at the last one and move backward
8282
//display index = (NUM_MAX-1)-(ci/8)
8383
//display column index = ci%8
8484
displayClear();
85-
for(int i=0; i<5; i++){ lc.setColumn((NUM_MAX-1)-(ci/8),ci%8, (b<100?0:bignum[(b/100) *5+i])); ci--; }
86-
for(int i=0; i<1; i++){ lc.setColumn((NUM_MAX-1)-(ci/8),ci%8, 0); ci--; } //1col gap
87-
for(int i=0; i<5; i++){ lc.setColumn((NUM_MAX-1)-(ci/8),ci%8, (b<10? 0:bignum[((b%100)/10)*5+i])); ci--; }
88-
for(int i=0; i<1; i++){ lc.setColumn((NUM_MAX-1)-(ci/8),ci%8, 0); ci--; } //1col gap
89-
for(int i=0; i<5; i++){ lc.setColumn((NUM_MAX-1)-(ci/8),ci%8, bignum[(b%10) *5+i]); ci--; }
90-
} //end fn displayByte
85+
for(int i=0; i<5; i++){ lc.setColumn((NUM_MAX-1)-(ci/8),ci%8, (n<1000? 0: bignum[(n/1000) *5+i]) ); ci--; }
86+
for(int i=0; i<1; i++){ lc.setColumn((NUM_MAX-1)-(ci/8),ci%8, 0 ); ci--; } //1col gap
87+
for(int i=0; i<5; i++){ lc.setColumn((NUM_MAX-1)-(ci/8),ci%8, (n<100? 0: bignum[((n%1000)/100) *5+i]) ); ci--; }
88+
for(int i=0; i<1; i++){ lc.setColumn((NUM_MAX-1)-(ci/8),ci%8, 0 ); ci--; } //1col gap
89+
for(int i=0; i<5; i++){ lc.setColumn((NUM_MAX-1)-(ci/8),ci%8, (n<10? 0: bignum[((n%100)/10) *5+i]) ); ci--; }
90+
for(int i=0; i<1; i++){ lc.setColumn((NUM_MAX-1)-(ci/8),ci%8, 0 ); ci--; } //1col gap
91+
for(int i=0; i<5; i++){ lc.setColumn((NUM_MAX-1)-(ci/8),ci%8, bignum[(n%10) *5+i] ); ci--; }
92+
} //end fn displayInt
9193

9294
int displayToggleBrightness(){
9395
switch(curBrightness){

display-MAX7219.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void displaySetup();
77
void displayLoop();
88
void displayTime(unsigned long mils, bool showSeconds);
99
void displayClear();
10-
void displayByte(byte b);
10+
void displayInt(int n);
1111
int displayToggleBrightness();
1212

1313
#endif

network-wifinina.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
//network-wifinina.cpp
22

3-
/*
4-
To access the admin menu:
5-
6-
Hold Select for 5 seconds. If you have already connected the clock to your WiFi network, it will flash its IP address (as a series of three 4-digit numbers), which you can now use to access the admin page.
7-
8-
If not, it will display a 4-digit number, and begin broadcasting a WiFi hotspot with that number (such as “Clock 1234”). Connect to this hotspot and browse to 192.168.1.1 to access the admin page – where, if you like, you can connect the clock to your WiFi network [which will discontinue the hotspot].
9-
10-
For security, the clock will stop serving the admin page (and hotspot if applicable) after 2 minutes of inactivity. To access it again, hold Select for 5 seconds as above. (It will stay connected to WiFi to continue requesting NTP syncs, weather forecasts, etc. I might add a password feature later, but I thought this physical limitation would be security enough for now.)
11-
12-
To change or forget the WiFi network the clock is connected to, use the admin page, or simply hold Select for 15 seconds (through the end of the IP address) to forget the network (the display will blink).
13-
*/
14-
153
#include "Arduino.h"
164
#include <SPI.h>
175
#include <WiFiNINA.h>
@@ -23,11 +11,12 @@ To change or forget the WiFi network the clock is connected to, use the admin pa
2311
#include RTC_H //definitions for the RTC for calling the display
2412

2513
//#include "secrets.h" //supply your own
26-
String ssid = "Riley";
14+
String ssid = "Riley"; //Stopping place: this should be empty and fillable via settings page. Then make it save in feeprom. Also ditch the fake rtc.
2715
String pass = "5802301644";
2816
//char ssid[] = SECRET_SSID; // your network SSID (name)
2917
//char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
3018
int keyIndex = 0; // your network key Index number (needed only for WEP)
19+
int WiFiEnabled = 0; //whether the customer wants to even use it TODO have this control the seconds display in part
3120

3221
unsigned int localPort = 2390; // local port to listen for UDP packets
3322
IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server
@@ -65,6 +54,7 @@ void networkLoop(){
6554

6655
void networkStartWiFi(){
6756
WiFi.disconnect(); //if AP is going, stop it
57+
if(ssid=="") return; //don't try to connect if there's no data
6858
checkForWiFiStatusChange(); //just for serial logging
6959
rtcDisplayTime(false); //display time without seconds
7060
Serial.println(); Serial.print(millis()); Serial.print(F(" Attempting to connect to SSID: ")); Serial.println(ssid);
@@ -87,6 +77,7 @@ void networkStartAP(){
8777
if(WiFi.beginAP("Clock")==WL_AP_LISTENING){ //Change "beginAP" if you want to create an WEP network
8878
Serial.print("SSID: "); Serial.println(WiFi.SSID());
8979
//by default the local IP address of will be 192.168.4.1 - override with WiFi.config(IPAddress(10, 0, 0, 1));
80+
WiFi.config(IPAddress(7,7,7,7));
9081
Serial.print("Access the admin page by browsing to http://"); Serial.println(WiFi.localIP());
9182
//server.begin() was formerly here
9283
}
@@ -167,13 +158,17 @@ unsigned long adminInputLast = 0; //for noticing when the admin page hasn't been
167158

168159
void networkStartAdmin(){
169160
adminInputLast = millis();
170-
if(WiFi.status()!=WL_CONNECTED) networkStartAP();
171161
//TODO display should handle its own code for displaying a type of stuff
172-
IPAddress theip = WiFi.localIP();
173-
displayByte(theip[0]); delay(2500);
174-
displayByte(theip[1]); delay(2500);
175-
displayByte(theip[2]); delay(2500);
176-
displayByte(theip[3]); delay(2500);
162+
if(WiFi.status()!=WL_CONNECTED){
163+
networkStartAP();
164+
displayInt(7777); delay(2500);
165+
} else { //use existing wifi
166+
IPAddress theip = WiFi.localIP();
167+
displayInt(theip[0]); delay(2500);
168+
displayInt(theip[1]); delay(2500);
169+
displayInt(theip[2]); delay(2500);
170+
displayInt(theip[3]); delay(2500);
171+
}
177172
displayClear();
178173
}
179174
void networkStopAdmin(){

0 commit comments

Comments
 (0)