Smart Poi 3.0.0
WiFi Connected LED POV Poi
Loading...
Searching...
No Matches
main.ino File Reference
#include "user_interface.h"
#include "LittleFS.h"
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <EEPROM.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiUdp.h>
#include <FastLED.h>
Include dependency graph for main.ino:

Macros

#define DATA_PIN   D2
 
#define CLOCK_PIN   D1
 
#define NUM_LEDS   121
 
#define NUM_PX   120
 
#define UPDATES_PER_SECOND   30000
 

Functions

IPAddress apIP (192, 168, 1, 1)
 
IPAddress apIPauxillary (192, 168, 1, 78)
 
ESP8266WebServer server (80)
 
IPAddress ipSubnet (255, 255, 255, 0)
 
IPAddress ipGateway (192, 168, 8, 1)
 
IPAddress ipGatewayauxillary (192, 168, 1, 1)
 
IPAddress ip (192, 168, 8, 77)
 
IPAddress tmpGateway (192, 168, 8, 1)
 
IPAddress tmpIP (192, 168, 8, 77)
 
void setup ()
 Setup function, called once at program start.
 
void loop ()
 Main loop function, called repeatedly after setup.
 

Variables

File fsUploadFile
 
ESP8266WiFiMulti WiFiMulti
 
int newBrightness = 20
 
File f
 
File a
 
File settings
 
boolean auxillary = false
 
CRGB leds [121]
 
const int maxPX = 24000
 
uint8_t message1Data [maxPX]
 
int pxDown = 120
 
int pxAcross = pxDown
 
const byte DNS_PORT = 53
 
DNSServer dnsServer
 
int status = WL_IDLE_STATUS
 
char apName [] = "Smart_Poi6"
 
char apPass [] = "SmartOne"
 
int apChannel = 1
 
int keyIndex = 0
 
uint8_t addrNumA = 192
 
uint8_t addrNumB = 168
 
uint8_t addrNumC = 8
 
uint8_t addrNumD = 78
 
const unsigned int localPort = 2390
 
byte packetBuffer [120]
 
WiFiUDP Udp
 
String responseHTML
 
String content
 
int statusCode
 
unsigned long previousMillis = 0
 
unsigned long previousMillis2 = 0
 
unsigned long previousMillis3 = 0
 
long interval = 5000
 
boolean checkit = false
 
boolean channelChange = false
 
boolean savingToSpiffs = false
 
unsigned long previousFlashy = 0
 
const long intervalBetweenFlashy = 5
 
boolean black = true
 
int state = 0
 
boolean upDown = true
 
boolean lines = true
 
CRGBPalette16 currentPalette
 
TBlendType currentBlending = NOBLEND
 
int paletteVar = 1
 
int motionSpeed = 1
 
int maxStartIndex = 70
 
int minStartIndex = 0
 
volatile int setting = 2
 
int patternChooser = 2
 
int pattern = 2
 
int wifiModeChooser = 1
 
int imageChooser = 1
 
boolean preloaded = false
 
int byteCounter = 0
 
boolean tempSwitch = true
 
String Field
 
int imageToUse = 0
 
int maxImages = 52
 
int minImages = 0
 
String images = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
 
String bin = "a.bin"
 
int uploadCounter = 1
 
boolean wifiEventDetect = false
 
boolean start = true
 
boolean routerOption = false
 
volatile byte X
 
volatile byte Y
 
volatile byte R1
 
volatile byte G1
 
volatile byte M1
 
volatile unsigned long currentMillis = millis()
 
volatile unsigned long currentMillis2 = millis()
 
volatile int packetSize
 
volatile int len
 

Macro Definition Documentation

◆ CLOCK_PIN

#define CLOCK_PIN   D1

Referenced by setup().

◆ DATA_PIN

#define DATA_PIN   D2

Referenced by fastLEDInit(), and setup().

◆ NUM_LEDS

◆ NUM_PX

#define NUM_PX   120

Referenced by fastLEDIndicateFast(), and handleUDP().

◆ UPDATES_PER_SECOND

#define UPDATES_PER_SECOND   30000

Function Documentation

◆ apIP()

IPAddress apIP ( 192 ,
168 ,
1 ,
1  )

Referenced by wifiChooser().

Here is the caller graph for this function:

◆ apIPauxillary()

IPAddress apIPauxillary ( 192 ,
168 ,
1 ,
78  )

Referenced by wifiChooser().

Here is the caller graph for this function:

◆ ip()

IPAddress ip ( 192 ,
168 ,
8 ,
77  )

◆ ipGateway()

IPAddress ipGateway ( 192 ,
168 ,
8 ,
1  )

◆ ipGatewayauxillary()

IPAddress ipGatewayauxillary ( 192 ,
168 ,
1 ,
1  )

Referenced by wifiChooser().

Here is the caller graph for this function:

◆ ipSubnet()

IPAddress ipSubnet ( 255 ,
255 ,
255 ,
0  )

Referenced by wifiChooser().

Here is the caller graph for this function:

◆ loop()

void loop ( )

Main loop function, called repeatedly after setup.

Handles various tasks such as:

  • Waiting for a signal or connection
  • Processing DNS server requests
  • Handling UDP packets (optional)
  • Changing patterns periodically
  • Displaying patterns using FastLED
Parameters
None
Returns
None
Precondition
setup() function has been called
Postcondition
Continuously runs, handling various tasks and events
Note
This function is called repeatedly after setup.
Uses global variables such as start, routerOption, interval, and pattern.
Calls other functions such as dnsServer.processNextRequest(), server.handleClient(), ChangePatternPeriodically(), and handleUdp().
272{
273 // this only works once:
274 if (start == false)
275 {
276 if (routerOption)
277 {
278 if (millis() > interval * 4)
279 { // perhaps wait a little longer...?
280 start = true;
281 }
282 }
283 else
284 {
285 if (millis() > interval * 2)
286 { // wait for less time...
287 start = true;
288 }
289 }
290 }
291 dnsServer.processNextRequest();
292 server.handleClient();
293
294 //////////////////////////////////////////////////////////// check if there is no signal ////////////////////////////////////////////////
295 currentMillis = millis();
296 currentMillis2 = millis();
298
299 if (start)
300 {
301 //
303 { // should not ever be true if udp is sending at correct speed!
304 // Serial.println(millis());
305 // save the last time you checked the time
307 state = 1; // udp no signal state
308 }
309 }
310
311 ///////////////////////////// OPTIONAL: UDP Packet handling (STREAMING from app option): /////////////////////////////////////////////////
312 // if there's data available, read a packet
313 // packetSize = Udp.parsePacket();
314 // if (packetSize) // if udp packet is received:
315 // {
316 // handleUdp();
317 // }
318 // else if (!packetSize && state == 1)
319 // { // this is backup, if udp not received ie: connection dropped for > interval millisecs
320 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
321
322 switch (pattern)
323 {
324 case 1:
325 {
326 funColourJam();
327 // sendTestMessage(); //test send message for now...
328 break;
329 }
330 // more options for patterns and spiffs loading here
331 case 2:
332 {
333 minImages = 0; // start of block
334 maxImages = 4; // end of block
335 bin.setCharAt(0, images.charAt(imageToUse));
337 break;
338 }
339 case 3:
340 {
341 minImages = 5; // start of block
342 maxImages = 10; // end of block
343 bin.setCharAt(0, images.charAt(imageToUse));
345 break;
346 }
347 case 4:
348 {
349 minImages = 11; // start of block
350 maxImages = 20; // end of block
351 bin.setCharAt(0, images.charAt(imageToUse));
353 break;
354 }
355 case 5:
356 {
357 minImages = 0; // start of block
358 maxImages = 52; // end of block
359 bin.setCharAt(0, images.charAt(imageToUse));
361 break;
362 }
363 // todo: add some more patterns, pattern 0...
364 }
365
366 ///////////////////////////////////// Optional: UDP Parse packet (streaming) code: ///////////////////////////////////////////////////
367 // yield(); // this is to give WiFi process control for tasks
368 // }
369 // else {
370 // // //Serial.println("/");
371 // //nothing for <interval> seconds wait for signal
372 // }
373 ///////////////////////////////////// End optional UDP code //////////////////////////////////////////////////////////////////////////
374
375 yield(); // give WiFi and other processor processes time to work
376}
void funColourJam()
Implements the "Colour Jam" pattern.
Definition colourPalette_code.ino:426
String bin
Definition main.ino:178
int maxImages
Definition main.ino:174
int minImages
Definition main.ino:175
volatile unsigned long currentMillis2
Definition main.ino:247
String images
Definition main.ino:177
DNSServer dnsServer
Definition main.ino:84
ESP8266WebServer server(80)
long interval
Definition main.ino:127
unsigned long previousMillis
Definition main.ino:124
int state
Definition main.ino:139
volatile unsigned long currentMillis
Definition main.ino:246
boolean routerOption
Definition main.ino:185
int pattern
Definition main.ino:157
int imageToUse
Definition main.ino:172
boolean start
Definition main.ino:183
void showLittleFSImage()
Definition showLittleFSImage.ino:22
void ChangePatternPeriodically()
Changes the pattern periodically based on the set interval.
Definition timeFunc.ino:15

References bin, ChangePatternPeriodically(), currentMillis, currentMillis2, dnsServer, funColourJam(), images, imageToUse, interval, maxImages, minImages, pattern, previousMillis, routerOption, server(), showLittleFSImage(), start, and state.

Here is the call graph for this function:

◆ server()

ESP8266WebServer server ( 80 )

◆ setup()

void setup ( )

Setup function, called once at program start.

Initializes digital pins, FastLED, serial communication, and EEPROM settings. Also mounts the LittleFS file system, loads router settings, and checks files.

Parameters
None
Returns
None
Precondition
None
Postcondition
Digital pins, FastLED, serial, EEPROM, and LittleFS are initialized. Router settings are loaded, and files are checked for corruption or size issues.
Note
This function is called automatically at program start.
EEPROM settings are loaded from storage.
LittleFS file system is mounted and files are checked.
205{
206 digitalWrite(CLOCK_PIN, LOW);
207 digitalWrite(DATA_PIN, LOW);
208 fastLEDInit();
210 // Initialize serial and wait for port to open: - for tests only
211 Serial.begin(115200);
212 Serial.println(""); // new line for readability
213 Serial.println("Started");
214 //////////////////////////////////////////////read eeprom settings://////////////////////////////////////////////////////////////////
215 EEPROM.begin(512);
216
217 // EEPROM storage:
218 // Brightness 15, wifiMode 5, PatternChooser 10, pattern 11, apChannel 13, addrNumD 14, addrNumA 16, addrNumB 17, addrNumC 18
219
220 eepromBrightnessChooser(15); // up to 220 max
221 eepromRouterOptionChooser(100); // do we try to connect to router or not? default is no.
222 eepromWifiModeChooser(5); // AP or STA mode
223 eepromPatternChooser(10); // 5 settings
224 eepromReadChannelAndAddress(13, 14, 16, 17, 18);
225 EEPROM.commit(); // save any changes made above
226
227 ///////////////////////////////////////////////////////LittleFS: /////////////////////////////////////////////////////////
228 // always use this to "mount" the filesystem
229 bool result = LittleFS.begin();
230 String router;
231
232 // The following is related to router settings (using AP mode currently)
235 fastLEDIndicate(); // indicates AP (Auxillary: Red, Main: Blue) or STA mode (Green)
236 Udp.begin(localPort);
237 // Check files for corruption or size issues
238}
void eepromRouterOptionChooser(int addr)
Retrieves and sets the router option from EEPROM.
Definition initalize.ino:59
void eepromReadChannelAndAddress(int addr1, int addr2, int addr3, int addr4, int addr5)
Reads channel and address information from EEPROM.
Definition initalize.ino:259
void checkFilesInSetup()
Checks files in the LittleFS file system during setup.
Definition initalize.ino:352
void eepromPatternChooser(int addr)
Retrieves and sets the pattern from EEPROM.
Definition initalize.ino:142
void littleFSLoadSettings()
Loads settings from LittleFS file system.
Definition initalize.ino:300
void eepromWifiModeChooser(int addr)
Retrieves and sets the Wi-Fi mode from EEPROM.
Definition initalize.ino:95
void fastLEDInit()
Initializes FastLED library and sets up LED strip.
Definition initalize.ino:513
void eepromBrightnessChooser(int addr)
Retrieves and sets the brightness from EEPROM.
Definition initalize.ino:17
void fastLEDIndicate()
Indicates Wi-Fi mode using FastLED library.
Definition initalize.ino:546
void fastLEDIndicateFast()
Indicates Wi-Fi mode using FastLED library with a faster sequence.
Definition initalize.ino:675
#define CLOCK_PIN
Definition main.ino:41
const unsigned int localPort
Definition main.ino:109
#define DATA_PIN
Definition main.ino:40
WiFiUDP Udp
Definition main.ino:114

References checkFilesInSetup(), CLOCK_PIN, DATA_PIN, eepromBrightnessChooser(), eepromPatternChooser(), eepromReadChannelAndAddress(), eepromRouterOptionChooser(), eepromWifiModeChooser(), fastLEDIndicate(), fastLEDIndicateFast(), fastLEDInit(), littleFSLoadSettings(), localPort, and Udp.

Here is the call graph for this function:

◆ tmpGateway()

IPAddress tmpGateway ( 192 ,
168 ,
8 ,
1  )

Referenced by wifiChooser().

Here is the caller graph for this function:

◆ tmpIP()

IPAddress tmpIP ( 192 ,
168 ,
8 ,
77  )

Referenced by wifiChooser().

Here is the caller graph for this function:

Variable Documentation

◆ a

◆ addrNumA

uint8_t addrNumA = 192

◆ addrNumB

uint8_t addrNumB = 168

◆ addrNumC

uint8_t addrNumC = 8

◆ addrNumD

uint8_t addrNumD = 78

◆ apChannel

int apChannel = 1

◆ apName

char apName[] = "Smart_Poi6"

Referenced by wifiChooser().

◆ apPass

char apPass[] = "SmartOne"

Referenced by wifiChooser().

◆ auxillary

boolean auxillary = false

◆ bin

String bin = "a.bin"

Referenced by loop(), and showLittleFSImage().

◆ black

boolean black = true

◆ byteCounter

int byteCounter = 0

◆ channelChange

boolean channelChange = false

Referenced by handleUDP().

◆ checkit

boolean checkit = false

Referenced by handleUDP().

◆ content

String content

Referenced by webServerSetupLogic().

◆ currentBlending

◆ currentMillis

volatile unsigned long currentMillis = millis()

Referenced by handleUDP(), and loop().

◆ currentMillis2

volatile unsigned long currentMillis2 = millis()

Referenced by handleUDP(), and loop().

◆ currentPalette

◆ DNS_PORT

const byte DNS_PORT = 53

Referenced by wifiChooser().

◆ dnsServer

DNSServer dnsServer

Referenced by loop(), and wifiChooser().

◆ f

◆ Field

String Field

Referenced by littleFSLoadSettings().

◆ fsUploadFile

File fsUploadFile

Referenced by handleFileUpload().

◆ G1

volatile byte G1

Referenced by handleUDP(), and showLittleFSImage().

◆ imageChooser

int imageChooser = 1

◆ images

String images = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

Referenced by handleFileUpload(), and loop().

◆ imageToUse

int imageToUse = 0

◆ interval

long interval = 5000

◆ intervalBetweenFlashy

const long intervalBetweenFlashy = 5

◆ keyIndex

int keyIndex = 0

◆ leds

◆ len

volatile int len

Referenced by handleUDP().

◆ lines

boolean lines = true

◆ localPort

const unsigned int localPort = 2390

Referenced by setup().

◆ M1

volatile byte M1

Referenced by handleUDP(), and showLittleFSImage().

◆ maxImages

int maxImages = 52

Referenced by ChangePatternPeriodically(), and loop().

◆ maxPX

const int maxPX = 24000

◆ maxStartIndex

int maxStartIndex = 70

Referenced by funColourJam().

◆ message1Data

uint8_t message1Data[maxPX]

Referenced by showLittleFSImage().

◆ minImages

int minImages = 0

Referenced by ChangePatternPeriodically(), and loop().

◆ minStartIndex

int minStartIndex = 0

Referenced by funColourJam().

◆ motionSpeed

int motionSpeed = 1

Referenced by funColourJam().

◆ newBrightness

int newBrightness = 20

◆ packetBuffer

byte packetBuffer[120]

Referenced by handleUDP().

◆ packetSize

volatile int packetSize

◆ paletteVar

int paletteVar = 1

Referenced by ChangePaletteEveryTime().

◆ pattern

◆ patternChooser

int patternChooser = 2

◆ preloaded

boolean preloaded = false

◆ previousFlashy

unsigned long previousFlashy = 0

◆ previousMillis

unsigned long previousMillis = 0

Referenced by handleUDP(), and loop().

◆ previousMillis2

unsigned long previousMillis2 = 0

Referenced by handleUDP().

◆ previousMillis3

unsigned long previousMillis3 = 0

◆ pxAcross

int pxAcross = pxDown

Referenced by showLittleFSImage().

◆ pxDown

int pxDown = 120

Referenced by showLittleFSImage().

◆ R1

volatile byte R1

Referenced by handleUDP(), and showLittleFSImage().

◆ responseHTML

String responseHTML

Referenced by webServerSetupLogic().

◆ routerOption

boolean routerOption = false

◆ savingToSpiffs

boolean savingToSpiffs = false

◆ setting

volatile int setting = 2

◆ settings

File settings

◆ start

boolean start = true

Referenced by loop().

◆ state

int state = 0

Referenced by handleUDP(), and loop().

◆ status

int status = WL_IDLE_STATUS

◆ statusCode

int statusCode

Referenced by webServerSetupLogic().

◆ tempSwitch

boolean tempSwitch = true

◆ Udp

WiFiUDP Udp

Referenced by handleUDP(), and setup().

◆ upDown

boolean upDown = true

Referenced by funColourJam().

◆ uploadCounter

int uploadCounter = 1

Referenced by handleFileUpload(), and wifiChooser().

◆ wifiEventDetect

boolean wifiEventDetect = false

◆ wifiModeChooser

int wifiModeChooser = 1

◆ WiFiMulti

ESP8266WiFiMulti WiFiMulti

Referenced by wifiChooser().

◆ X

volatile byte X

Referenced by handleUDP(), and showLittleFSImage().

◆ Y

volatile byte Y

Referenced by handleUDP().