Smart Poi 3.0.0
WiFi Connected LED POV Poi
Loading...
Searching...
No Matches
initalize.ino File Reference

Functions

void eepromBrightnessChooser (int addr)
 Retrieves and sets the brightness from EEPROM.
 
void eepromRouterOptionChooser (int addr)
 Retrieves and sets the router option from EEPROM.
 
void eepromWifiModeChooser (int addr)
 Retrieves and sets the Wi-Fi mode from EEPROM.
 
void eepromPatternChooser (int addr)
 Retrieves and sets the pattern from EEPROM.
 
void readAnotherPatternEEProm ()
 Reads and increments the pattern from EEPROM.
 
void eepromReadChannelAndAddress (int addr1, int addr2, int addr3, int addr4, int addr5)
 Reads channel and address information from EEPROM.
 
void littleFSLoadSettings ()
 Loads settings from LittleFS file system.
 
void checkFilesInSetup ()
 Checks files in the LittleFS file system during setup.
 
void wifiChooser (char router_array[], char pwd_array[])
 Configures Wi-Fi settings based on the selected mode.
 
void fastLEDInit ()
 Initializes FastLED library and sets up LED strip.
 
void fastLEDIndicate ()
 Indicates Wi-Fi mode using FastLED library.
 
void fastLEDIndicateFast ()
 Indicates Wi-Fi mode using FastLED library with a faster sequence.
 

Function Documentation

◆ checkFilesInSetup()

void checkFilesInSetup ( )

Checks files in the LittleFS file system during setup.

This function iterates through all files in the root directory ("/"), checks their size, and deletes them if they exceed the maximum allowed size (maxPX). It also checks for file corruption by attempting to read a small portion of each file.

Parameters
None
Returns
None
Precondition
LittleFS must be initialized and mounted before calling this function.
Postcondition
Files exceeding maxPX size or detected as corrupted will be deleted.
Note
This function uses Serial for printing debug messages.
maxPX defines the maximum allowed file size.
353{
354 Dir dir = LittleFS.openDir("/");
355
356 while (dir.next())
357 {
358 String fileName = dir.fileName();
359 File file = dir.openFile("r");
360
361 // Check file size
362 size_t fileSize = file.size();
363 Serial.print("Checking file: ");
364 Serial.print(fileName);
365 Serial.print(" - Size: ");
366 Serial.println(fileSize);
367
368 // If file size exceeds maxPX, delete it
369 if (fileSize > maxPX)
370 {
371 Serial.print("File too large. Deleting: ");
372 Serial.println(fileName);
373 LittleFS.remove(fileName);
374 }
375 else
376 {
377 // Try to read a small portion of the file to detect corruption
378 uint8_t buffer[10];
379 if (file.read(buffer, sizeof(buffer)) != sizeof(buffer))
380 {
381 // File might be corrupted, unable to read
382 Serial.print("Corrupted file detected. Deleting: ");
383 Serial.println(fileName);
384 LittleFS.remove(fileName);
385 }
386 else
387 {
388 Serial.println("File is valid.");
389 }
390 }
391
392 file.close();
393 }
394}
const int maxPX
Definition main.ino:67

References maxPX.

Referenced by setup().

Here is the caller graph for this function:

◆ eepromBrightnessChooser()

void eepromBrightnessChooser ( int addr)

Retrieves and sets the brightness from EEPROM.

Reads the brightness value from EEPROM, checks for validity, and sets the brightness accordingly.

Parameters
addrThe EEPROM address where the brightness value is stored.
Returns
None
Precondition
EEPROM is initialized and ready for use.
Postcondition
Brightness is set to the retrieved value or a default value if invalid.
Note
This function is used to initialize the brightness setting from EEPROM.
Uses global variables such as newBrightness.
Calls other functions such as EEPROM.read(), EEPROM.write(), and FastLED.setBrightness().
18{
19 ////////////////////////////////////////////////////////Eeprom Brightness///////////////////////////////////////////////////////////////////////
20
21 // EEPROM.write(15, newBrightness); //testing only
22 // EEPROM.commit();
23 int readBRTeprom = int(EEPROM.read(addr)); // read channel info and change from ascii
24 newBrightness = readBRTeprom; // monitor this, had some problems with ascii
25 if (newBrightness > 254 || newBrightness < 1)
26 {
27 EEPROM.write(15, 20); // set back to default dim brightness
28 newBrightness = 20;
29 ////Serial.println("EEProm error, newBrightness reset to 200");
30 }
31 else
32 {
33 newBrightness = 20; // just start with low brightness please, better this way
34 ////Serial.print("newBrightness set to ");
35 ////Serial.println(newBrightness);
36 }
37
38 FastLED.setBrightness(newBrightness); // should I be removing this becos https://github.com/FastLED/FastLED/wiki/FastLED-Temporal-Dithering
39 FastLED.showColor(CRGB::Black);
40}
int newBrightness
Definition main.ino:39

References newBrightness.

Referenced by setup().

Here is the caller graph for this function:

◆ eepromPatternChooser()

void eepromPatternChooser ( int addr)

Retrieves and sets the pattern from EEPROM.

Reads the pattern value from EEPROM, checks for validity, and sets the pattern accordingly.

Parameters
addrThe EEPROM address where the pattern value is stored.
Returns
None
Precondition
EEPROM is initialized and ready for use.
Postcondition
Pattern is set to the retrieved value or a default value if invalid.
Note
This function is used to initialize the pattern setting from EEPROM.
Uses global variables such as patternChooser and pattern.
Calls other functions such as EEPROM.read(), EEPROM.write(), and readAnotherPatternEEProm().
Valid pattern values are 1-6, with 1 being the default.
If patternChooser is outside the valid range, pattern is set to 1 (default).
143{
144 patternChooser = int(EEPROM.read(addr));
145 if (patternChooser == 1)
146 {
147 pattern = 1;
148 EEPROM.write(10, 1);
149 }
150 if (patternChooser == 2)
151 {
152 pattern = 2;
153 EEPROM.write(10, 2);
154 }
155 if (patternChooser == 3)
156 {
157 pattern = 3;
158 EEPROM.write(10, 3);
159 }
160 if (patternChooser == 4)
161 {
162 pattern = 4;
163 EEPROM.write(10, 4);
164 }
165 if (patternChooser == 5)
166 {
167 pattern = 5;
168 EEPROM.write(10, 5);
169 }
170 if (patternChooser == 6) // hard coded, todo: need variable here to add more patterns?
171 {
172 EEPROM.write(10, 6);
173 readAnotherPatternEEProm(); // on/off switcher
174 }
175 if (patternChooser > 6)
176 {
177 EEPROM.write(10, 1); // set back to default
178 pattern = 1;
179 }
180 if (patternChooser < 1)
181 {
182 EEPROM.write(10, 1); // set back to default
183 pattern = 1;
184 }
185}
void readAnotherPatternEEProm()
Reads and increments the pattern from EEPROM.
Definition initalize.ino:203
int patternChooser
Definition main.ino:156
int pattern
Definition main.ino:157

References pattern, patternChooser, and readAnotherPatternEEProm().

Referenced by setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eepromReadChannelAndAddress()

void eepromReadChannelAndAddress ( int addr1,
int addr2,
int addr3,
int addr4,
int addr5 )

Reads channel and address information from EEPROM.

Retrieves channel and address values from EEPROM, performs validation, and sets global variables accordingly.

Parameters
addr1EEPROM address for channel information.
addr2EEPROM address for IP address octet D.
addr3EEPROM address for IP address octet A.
addr4EEPROM address for IP address octet B.
addr5EEPROM address for IP address octet C.
Returns
None
Precondition
EEPROM is initialized and ready for use.
Postcondition
Channel and address information is read and validated.
Note
only apChannel is actually relevant currently.
This function is used to initialize channel and address settings from EEPROM.
Uses global variables apChannel, addrNumD, addrNumA, addrNumB, and addrNumC.
Calls other function EEPROM.read().
Valid channel values are 1-11.
If channel is outside the valid range, it is set to 4 (default).
260{
261 int readAPEeprom = int(EEPROM.read(addr1)); // read channel info (from EEPROM13) and change
262 apChannel = readAPEeprom;
263
264 if (apChannel > 11 || apChannel < 1)
265 { // 13 for SA, is it 14 for Australia?
266 EEPROM.write(11, 1);
267 apChannel = 4;
268 }
269 else
270 {
271
272 }
273 // SET IP:
274 uint8_t readAddrEeprom = uint8_t(EEPROM.read(addr2));
275 addrNumD = readAddrEeprom;
276 readAddrEeprom = uint8_t(EEPROM.read(addr3));
277 addrNumA = readAddrEeprom;
278 readAddrEeprom = uint8_t(EEPROM.read(addr4));
279 addrNumB = readAddrEeprom;
280 readAddrEeprom = uint8_t(EEPROM.read(addr5));
281 addrNumC = readAddrEeprom;
282}
int apChannel
Definition main.ino:92
uint8_t addrNumB
Definition main.ino:105
uint8_t addrNumA
Definition main.ino:104
uint8_t addrNumC
Definition main.ino:106
uint8_t addrNumD
Definition main.ino:107

References addrNumA, addrNumB, addrNumC, addrNumD, and apChannel.

Referenced by setup().

Here is the caller graph for this function:

◆ eepromRouterOptionChooser()

void eepromRouterOptionChooser ( int addr)

Retrieves and sets the router option from EEPROM.

Reads the router option value from EEPROM, checks for validity, and sets the router option accordingly.

Parameters
addrThe EEPROM address where the router option value is stored.
Returns
None
Precondition
EEPROM is initialized and ready for use.
Postcondition
Router option is set to the retrieved value or a default value if invalid.
Note
This function is used to initialize the router option setting from EEPROM.
Uses global variables such as routerOption.
Calls other functions such as EEPROM.read() and EEPROM.write().
Valid router option values are 0 (disabled) or 1 (enabled).
60{
61 int newRouter = int(EEPROM.read(addr));
62 if (newRouter == 0 || newRouter > 1)
63 { // this should take care of first run as well, when eeprom is not set (usually 255 or 0)
64 newRouter = 0;
65 routerOption = false;
66 }
67 else
68 { // 1 for router
69 routerOption = true;
70 }
71
72 EEPROM.write(100, newRouter);
73 // EEPROM.commit(); //this is done later I think
74}
boolean routerOption
Definition main.ino:185

References routerOption.

Referenced by setup().

Here is the caller graph for this function:

◆ eepromWifiModeChooser()

void eepromWifiModeChooser ( int addr)

Retrieves and sets the Wi-Fi mode from EEPROM.

Reads the Wi-Fi mode value from EEPROM, checks for validity, and sets the Wi-Fi mode accordingly.

Parameters
addrThe EEPROM address where the Wi-Fi mode value is stored.
Returns
None
Precondition
EEPROM is initialized and ready for use.
Postcondition
Wi-Fi mode is set to the retrieved value or a default value if invalid.
Note
This function is used to initialize the Wi-Fi mode setting from EEPROM.
Uses global variables such as wifiModeChooser and routerOption.
Calls other functions such as EEPROM.read() and EEPROM.write().
Valid Wi-Fi mode values are 1 (main AP mode) and 2 (auxiliary AP mode).
If routerOption is false, Wi-Fi mode is set to 1 (main AP mode) by default.
wifiModeChooser used in wifiChooser()
96{
97 if (routerOption) // ok this is set to toggle between two modes - I guess to make sure I don't get stuck?
98 {
99 wifiModeChooser = int(EEPROM.read(addr));
100 wifiModeChooser++; // take this out and it stays on router?
101 if (wifiModeChooser == 2)
102 {
103 EEPROM.write(5, 2); // save
104 }
105 if (wifiModeChooser > 2)
106 {
107 wifiModeChooser = 1;
108 EEPROM.write(5, 1); // set back to default
109 wifiModeChooser = 1;
110 }
111 if (wifiModeChooser < 1)
112 { // never happens, except for first run...
113 wifiModeChooser = 1;
114 EEPROM.write(5, 1); // set back to default
115 wifiModeChooser = 1;
116 }
117 }
118 else
119 { // skip router option
120 wifiModeChooser = 1; // 1 means main AP mode, with auxillary connected to main.
121 }
122}
int wifiModeChooser
Definition main.ino:158

References routerOption, and wifiModeChooser.

Referenced by setup().

Here is the caller graph for this function:

◆ fastLEDIndicate()

void fastLEDIndicate ( )

Indicates Wi-Fi mode using FastLED library.

Displays a sequence of colors on the LED strip to indicate the current Wi-Fi mode. If wifiModeChooser is 1, (AP Mode) displays a sequence of red or blue colors depending on the auxillary variable. If wifiModeChooser is not 1, (Router Mode) displays a sequence of green colors.

Returns
None
Precondition
FastLED library is initialized and ready for use.
Postcondition
LED strip displays a sequence of colors indicating the Wi-Fi mode.
Note
This function is used to provide a visual indication of the Wi-Fi mode.
Uses global variables wifiModeChooser, auxillary, and NUM_LEDS.
Calls other function FastLED.show() and FastLED.delay().
Todo
Consider simplifying the code by reducing repetition.
547{
548 // indicate wifi mode:
549 // //Serial.println("FASTLED NOW");
550 if (wifiModeChooser == 1)
551 {
552 for (int i = 0; i < NUM_LEDS; i++)
553 {
554 // Set the i'th led to whatever
555 if (auxillary)
556 {
557 leds[i] = CRGB::Red;
558 }
559 else
560 {
561 leds[i] = CRGB::Blue;
562 }
563 // Show the leds
564 FastLED.show();
565 // now that we've shown the leds, reset the i'th led to black
566 leds[i] = CRGB::Black;
567 // Wait a little bit before we loop around and do it again
568 FastLED.delay(10);
569 }
570 for (int i = 0; i < NUM_LEDS; i++)
571 {
572 // Set the i'th led to whatever
573 if (auxillary)
574 {
575 leds[i] = CRGB::Red;
576 }
577 else
578 {
579 leds[i] = CRGB::Blue;
580 }
581 // Show the leds
582 FastLED.show();
583 // now that we've shown the leds, reset the i'th led to black
584 leds[i] = CRGB::Black;
585 // Wait a little bit before we loop around and do it again
586 FastLED.delay(10);
587 }
588 for (int i = 0; i < NUM_LEDS; i++)
589 {
590 // Set the i'th led to whatever
591 if (auxillary)
592 {
593 leds[i] = CRGB::Red;
594 }
595 else
596 {
597 leds[i] = CRGB::Blue;
598 }
599 // Show the leds
600 FastLED.show();
601 // now that we've shown the leds, reset the i'th led to black
602 if (auxillary)
603 {
604 leds[i] = CRGB::Red;
605 }
606 else
607 {
608 leds[i] = CRGB::Blue;
609 }
610 // Wait a little bit before we loop around and do it again
611 FastLED.delay(10);
612 }
613
614 FastLED.delay(10);
615 }
616 else
617 {
618 for (int i = 0; i < NUM_LEDS; i++)
619 {
620 // Set the i'th led to whatever
621 leds[i] = CRGB::Green;
622 // Show the leds
623 FastLED.show();
624 // now that we've shown the leds, reset the i'th led to black
625 leds[i] = CRGB::Black;
626 // Wait a little bit before we loop around and do it again
627 FastLED.delay(10);
628 }
629 for (int i = 0; i < NUM_LEDS; i++)
630 {
631 // Set the i'th led to whatever
632 leds[i] = CRGB::Green;
633 // Show the leds
634 FastLED.show();
635 // now that we've shown the leds, reset the i'th led to black
636 leds[i] = CRGB::Black;
637 // Wait a little bit before we loop around and do it again
638 FastLED.delay(10);
639 }
640 for (int i = 0; i < NUM_LEDS; i++)
641 {
642 // Set the i'th led to whatever
643 leds[i] = CRGB::Green;
644 // Show the leds
645 FastLED.show();
646 // now that we've shown the leds, reset the i'th led to black
647 leds[i] = CRGB::Green;
648 // Wait a little bit before we loop around and do it again
649 FastLED.delay(10);
650 }
651
652 FastLED.delay(10);
653 }
654
655 FastLED.showColor(CRGB::Black);
656}
#define NUM_LEDS
Definition main.ino:57
CRGB leds[121]
Definition main.ino:60
boolean auxillary
Definition main.ino:50

References auxillary, leds, NUM_LEDS, and wifiModeChooser.

Referenced by setup().

Here is the caller graph for this function:

◆ fastLEDIndicateFast()

void fastLEDIndicateFast ( )

Indicates Wi-Fi mode using FastLED library with a faster sequence.

Displays a faster sequence of colors on the LED strip to indicate the current Wi-Fi mode. If wifiModeChooser is 1, (AP Mode) displays a sequence of magenta or cyan colors depending on the auxillary variable. If wifiModeChooser is not 1, (Router Mode) displays a sequence of green colors.

Returns
None
Precondition
FastLED library is initialized and ready for use.
Postcondition
LED strip displays a faster sequence of colors indicating the Wi-Fi mode.
Note
This function is used to provide a faster visual indication of the Wi-Fi mode.
Uses global variables wifiModeChooser, auxillary, and NUM_LEDS.
Calls other function FastLED.show() and FastLED.delay().
Todo
Consider simplifying the code by reducing repetition.
676{
677 // indicate wifi mode:
678 // //Serial.println("FASTLED NOW");
679 if (wifiModeChooser == 1)
680 {
681 for (int i = 0; i < NUM_LEDS; i += 2)
682 {
683 // Set the i'th led to whatever
684 if (auxillary)
685 {
686 leds[i] = CRGB::Magenta;
687 }
688 else
689 {
690 leds[i] = CRGB::Cyan;
691 }
692
693 // Show the leds
694 FastLED.show();
695 // now that we've shown the leds, reset the i'th led to black
696 leds[i] = CRGB::Black;
697 // Wait a little bit before we loop around and do it again
698 FastLED.delay(15);
699 }
700 for (int i = 0; i < NUM_LEDS; i += 2)
701 {
702 // Set the i'th led to whatever
703 if (auxillary)
704 {
705 leds[i] = CRGB::Magenta;
706 }
707 else
708 {
709 leds[i] = CRGB::Cyan;
710 }
711 // Show the leds
712 FastLED.show();
713 // now that we've shown the leds, reset the i'th led to black
714 leds[i] = CRGB::Black;
715 // Wait a little bit before we loop around and do it again
716 FastLED.delay(15);
717 }
718 for (int i = 0; i < NUM_LEDS; i++)
719 {
720 // Set the i'th led to whatever
721 leds[i] = CRGB::Black;
722 // now that we've shown the leds, reset the i'th led to black
723 if (auxillary)
724 {
725 leds[0] = CRGB::Magenta;
726 leds[2] = CRGB::Magenta;
727 leds[4] = CRGB::Magenta;
728 leds[NUM_PX / 2] = CRGB::Magenta;
729 leds[NUM_LEDS - 2] = CRGB::Magenta;
730 leds[NUM_LEDS - 4] = CRGB::Magenta;
731 leds[NUM_LEDS - 6] = CRGB::Magenta;
732 }
733 else
734 {
735 leds[0] = CRGB::Cyan;
736 leds[2] = CRGB::Cyan;
737 leds[4] = CRGB::Cyan;
738 leds[NUM_PX / 2] = CRGB::Cyan;
739 leds[NUM_LEDS - 2] = CRGB::Cyan;
740 leds[NUM_LEDS - 4] = CRGB::Cyan;
741 leds[NUM_LEDS - 6] = CRGB::Cyan;
742 }
743 // Show the leds
744 FastLED.show();
745 // Wait a little bit before we loop around and do it again
746 // FastLED.delay(10);
747 }
748
749 // FastLED.delay(10);
750 }
751 else
752 {
753 for (int i = 0; i < NUM_LEDS; i++)
754 {
755 // Set the i'th led to whatever
756 leds[i] = CRGB::Green;
757 // Show the leds
758 FastLED.show();
759 // now that we've shown the leds, reset the i'th led to black
760 leds[i] = CRGB::Black;
761 // Wait a little bit before we loop around and do it again
762 // FastLED.delay(10);
763 }
764 for (int i = 0; i < NUM_LEDS; i++)
765 {
766 // Set the i'th led to whatever
767 leds[i] = CRGB::Green;
768 // Show the leds
769 FastLED.show();
770 // now that we've shown the leds, reset the i'th led to black
771 leds[i] = CRGB::Black;
772 // Wait a little bit before we loop around and do it again
773 // FastLED.delay(10);
774 }
775 for (int i = 0; i < NUM_LEDS; i++)
776 {
777 // Set the i'th led to whatever
778 leds[i] = CRGB::Green;
779 // Show the leds
780 FastLED.show();
781 // now that we've shown the leds, reset the i'th led to black
782 leds[i] = CRGB::Green;
783 // Wait a little bit before we loop around and do it again
784 // FastLED.delay(10);
785 }
786
787 // FastLED.delay(10);
788 }
789
790 FastLED.showColor(CRGB::Black);
791}
#define NUM_PX
Definition main.ino:64

References auxillary, leds, NUM_LEDS, NUM_PX, and wifiModeChooser.

Referenced by setup().

Here is the caller graph for this function:

◆ fastLEDInit()

void fastLEDInit ( )

Initializes FastLED library and sets up LED strip.

Configures FastLED with the specified LED type (WS2812B), data pin (DATA_PIN), and color order (GRB), and sets the initial brightness (newBrightness) and color (black).

Returns
None
Precondition
FastLED library is included and ready for use.
Postcondition
FastLED is initialized and LED strip is set up.
Note
This function is used to initialize FastLED and set up the LED strip.
Uses global variables DATA_PIN, CLOCK_PIN, NUM_LEDS, and newBrightness.
Calls other functions FastLED.addLeds(), FastLED.setBrightness(), and FastLED.showColor().
Sets initial brightness to a low value for startup battery saving.
514{
515
516 ////////////////////////////////////////////////Fast LED Setup: ////////////////////////////////////////////////////////////////////////////////////////////////
517 // FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, BGR>(leds, NUM_LEDS); //DATA_RATE_MHZ(8)
518 // FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
519 LEDS.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
520 FastLED.setBrightness(newBrightness); // should be low figure here, for startup battery saving...
521
522 FastLED.showColor(CRGB::Black);
523
524 // if DNSServer is started with "*" for domain name, it will reply with
525 // provided IP to all DNS request
526 ///////////////////////////////////////////////////////////////////////end FastLED setup///////////////////////////////////////////////////////////////////
527}
#define DATA_PIN
Definition main.ino:40

References DATA_PIN, leds, newBrightness, and NUM_LEDS.

Referenced by setup().

Here is the caller graph for this function:

◆ littleFSLoadSettings()

void littleFSLoadSettings ( )

Loads settings from LittleFS file system.

Reads settings from /settings.txt file and stores them in global variables.

Returns
None
Precondition
LittleFS file system is initialized and ready for use.
Postcondition
Settings are read and stored in global variables.
Note
This function is used to initialize settings from LittleFS.
Uses global variables router_array and pwd_array.
Calls other functions wifiChooser() and webServerSetupLogic().
Warning
Password is stored in plain text, posing a security risk.
Todo
Consider encrypting password for security.
301{
302 settings = LittleFS.open("/settings.txt", "r");
303 // note: password is stored in plain text, security risk?
304 // currently settings.txt avaliable on demand over http!
305
306 // load spiffs into char arrays for router setup:
307 // Define
308 Field = settings.readStringUntil('\n');
309
310 // Length (with one extra character for the null terminator)
311 // int router_len = router.length() + 1;
312 // Prepare the character array (the buffer)
313 // below should be part of Struct
314 char router_array[Field.length() + 1];
315 // Copy it over
316 Field.toCharArray(router_array, Field.length() + 1);
317
318 // and again for password:
319 // Define
320 Field = settings.readStringUntil('\n');
321 // Length (with one extra character for the null terminator)
322 // int pwd_len = pwd.length() + 1;
323 // Prepare the character array (the buffer)
324 char pwd_array[Field.length() + 1];
325 // Copy it over
326 Field.toCharArray(pwd_array, Field.length() + 1);
327
328 settings.close();
329 // delay(100);
330 ///////////////////////////////////////////////////////////////End Read Settings////////////////////////////////////////////////////////////////////////////
331 // more setup below, has to be inside this function...???
332 wifiChooser(router_array, pwd_array);
333 webServerSetupLogic(router_array, pwd_array); // why not do this only on AP mode?
334}
void wifiChooser(char router_array[], char pwd_array[])
Configures Wi-Fi settings based on the selected mode.
Definition initalize.ino:415
String Field
Definition main.ino:170
File settings
Definition main.ino:47
void webServerSetupLogic(String router, String pass)
Sets up the web server with routes for handling file operations, settings, and LED control.
Definition webServerSetupLogic.ino:491

References Field, settings, webServerSetupLogic(), and wifiChooser().

Referenced by setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readAnotherPatternEEProm()

void readAnotherPatternEEProm ( )

Reads and increments the pattern from EEPROM.

Reads the pattern value from EEPROM, increments it, and writes it back to EEPROM.

Returns
None
Precondition
EEPROM is initialized and ready for use.
Postcondition
Pattern is incremented and written back to EEPROM.
Note
This function is used to cycle through patterns on each restart.
Uses global variable pattern.
Calls other function EEPROM.write().
Valid pattern values are 1-5, with 1 being the default.
If pattern is outside the valid range, it is set back to 1 (default).
204{
205 // EEProm Pattern chooser: changes every time you restart poi
206 pattern = int(EEPROM.read(11));
207 pattern++;
208 if (pattern == 2)
209 {
210 EEPROM.write(11, 2);
211 }
212 if (pattern == 3)
213 {
214 EEPROM.write(11, 3);
215 }
216 if (pattern == 4)
217 {
218 EEPROM.write(11, 4);
219 }
220 if (pattern == 5)
221 {
222 EEPROM.write(11, 5);
223 }
224 if (pattern > 5)
225 {
226 EEPROM.write(11, 1); // set back to default
227 pattern = 1;
228 }
229 if (pattern < 1)
230 {
231 EEPROM.write(11, 1); // set back to default
232 pattern = 1;
233 }
234}

References pattern.

Referenced by eepromPatternChooser().

Here is the caller graph for this function:

◆ wifiChooser()

void wifiChooser ( char router_array[],
char pwd_array[] )

Configures Wi-Fi settings based on the selected mode.

Sets up Wi-Fi in either Access Point (AP) mode, Station mode, or connects to a pre-defined router.

Parameters
router_arrayRouter SSID (used in Station mode).
pwd_arrayRouter password (used in Station mode).
Returns
None
Precondition
Wi-Fi library is initialized and ready for use.
Postcondition
Wi-Fi settings are configured according to the selected mode.
Note
This function is used to configure Wi-Fi settings based on the wifiModeChooser variable.
Uses global variables wifiModeChooser, auxillary, apName, apPass, apIP, apChannel, addrNumA, addrNumB, addrNumC, and addrNumD.
Calls other functions WiFi.mode(), WiFi.begin(), WiFi.config(), WiFi.softAP(), dnsServer.start(), and WiFiMulti.addAP().
Supports up to 18 connection attempts in Station mode.
Todo
Consider implementing exponential backoff for connection attempts.
416{
417 if (wifiModeChooser == 1)
418 { // main AP mode, with auxillary connected to main.
419 // this is all that is needed to put main and auxillary poi on one code base:
420 if (auxillary)
421 {
422 // Serial.println("auxillary POI");
423 WiFi.mode(WIFI_STA);
424 WiFi.begin(apName, apPass);
426 while (WiFi.status() != WL_CONNECTED)
427 {
428 if (millis() > 20000)
429 {
430 // don't wait if > 1 minute!
431 break;
432 }
433 // Serial.print(".");
434 FastLED.delay(50); // was set to 500, why? todo: does FastLED.delay() work better?
435 }
436 // LED on test:
437 // digitalWrite(LED_BUILTIN, LOW);
438 }
439 else
440 { // main poi here
441 // Serial.println("main POI");
442 WiFi.mode(WIFI_AP);
443 WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
444 WiFi.softAP(apName, apPass, apChannel); // use pre-set values here
445 dnsServer.start(DNS_PORT, "*", apIP); // AP mode only, surely??
446
447 // wait for station:
448 while (WiFi.softAPgetStationNum() == 0)
449 {
450 if (millis() > 10000)
451 {
452 // don't wait if > 1 minute!
453 break;
454 }
455 FastLED.delay(50);
456 }
457 // LED on test:
458 // digitalWrite(LED_BUILTIN, LOW);
459 }
460 }
461 else
462 { // both main and auxillary the same, connected to pre-defined Router
463 // Serial.println("ROUTER");
464 //////////////////////////////////////////////////////////Connect to Router here://///////////////////////////////////////////////////////////////
465 ////////////////////////////////////////////////////Input Settings from Spiffs: ////////////////////////////////////////////////////////////////////
466 WiFi.mode(WIFI_STA); // disable AP on this one
467 tmpIP = IPAddress(addrNumA, addrNumB, addrNumC, addrNumD);
468 tmpGateway = IPAddress(addrNumA, addrNumB, addrNumC, 1); // make last another variable? YA!
469 WiFiMulti.addAP(router_array, pwd_array);
470 byte wifiConnectAttemptCount = 0;
471 byte maxWifiConnectAttemptCount = 18; // this should be in adjustable settings
472
473 while (WiFiMulti.run() != WL_CONNECTED)
474 {
475 ///////////////////indicate://///////////////////////////////
476 FastLED.showColor(CRGB::Black);
477 for (int i = 0; i < uploadCounter; i++)
478 {
479 leds[i * 2] = CRGB::Green; // For max 18 tries, spacing out indicator
480 }
481 FastLED.show();
483 //////////////////end indicate////////////////////////////////
484
485 delay(500); // delay??? todo: try FastLED.delay() here, also 50ms instead of 500... Must be a better way..?
486 wifiConnectAttemptCount++;
487 if (wifiConnectAttemptCount > maxWifiConnectAttemptCount)
488 {
489 ESP.restart(); // Note: this won't work the first time, needs manual restart!!!!!!!!
490 }
491 }
492
493 uploadCounter = 1;
494 }
495
496}
IPAddress tmpIP(192, 168, 8, 77)
ESP8266WiFiMulti WiFiMulti
Definition main.ino:33
IPAddress ipSubnet(255, 255, 255, 0)
char apName[]
Definition main.ino:90
DNSServer dnsServer
Definition main.ino:84
IPAddress ipGatewayauxillary(192, 168, 1, 1)
IPAddress apIP(192, 168, 1, 1)
int uploadCounter
Definition main.ino:180
char apPass[]
Definition main.ino:91
const byte DNS_PORT
Definition main.ino:81
IPAddress tmpGateway(192, 168, 8, 1)
IPAddress apIPauxillary(192, 168, 1, 78)

References addrNumA, addrNumB, addrNumC, addrNumD, apChannel, apIP(), apIPauxillary(), apName, apPass, auxillary, DNS_PORT, dnsServer, ipGatewayauxillary(), ipSubnet(), leds, tmpGateway(), tmpIP(), uploadCounter, wifiModeChooser, and WiFiMulti.

Referenced by littleFSLoadSettings().

Here is the call graph for this function:
Here is the caller graph for this function: