thebigpotatoe / Super-Simple-RGB-WiFi-Lamp

A project based on the ESP8266 and WS2812b

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Super-Simple-RGB-WiFi-Lamp (Clock, Night rider and Bell curve error)

LordVallejo opened this issue · comments

Hello Sir, thanks againg for helping me in this process.
First of all, I am using the Esp8266 NodeMCU 1.0 (ESP-12E Module)
Also I am using a neopixel ring of 24 leds (ws2812b)
The issue I am getting from the esp8266 happens when I try to use these effects:

  1. Clock
  2. Bell Curve
  3. Night rider
    Actually I can connect from my laptop, smart phone and tablet, the browser that I use by default is Google Chrome. When I am online I can pick up the color and rainbow effects, but when I try to change the effect to those I mentioned, the app suddenly stops and the esp8266 doesn’t receive and send information, it remains blocked until I upload the code again.

This is the code I am using:


// Included Libraries
#define FASTLED_ESP8266_RAW_PIN_ORDER
#include <FastLED.h>
#include "FS.h"
#include <ESP8266WiFi.h>
#include "IPAddress.h"
#include <DNSServer.h>
#include <ESP8266mDNS.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPUpdateServer.h>
#include <ESPAsyncTCP.h>
#include <WebSocketsServer.h>
#include <ArduinoJson.h>
#include <TimeLib.h>
#include <ESPAsyncUDP.h>
#include "lwip/inet.h"
#include "lwip/dns.h"

// ############################################################# Sketch Variables #############################################################
// All variables at the top of this sketch need to be defined correctly for your light. Read the comments around each one for moe details on
// what each of them are.

#define DEFAULT_NAME "Super Simple RGB Wifi Lamp"

// Set Your Data pin -This is the pin on your ESP8266 that is connected to the LED's. Be careful as on the NodeMCU the D pin does not map to
// pin number. For this example pin D1 on the NodeMCU is actually pin 5 in software.
#define DATA_PIN 5

// Set the number of LED's - Simply count how many there are on your string and enter the number here
#define NUM_LEDS 24

// Set your UTC offset - This is the time zone you are in. for example +10 for Sydney or -4 for NYC
#define UTC_OFFSET -5

// Set up LED's for each side - These arrays hold which leds are on what sides. For the basic rectangular shape in the example this relates to 4
// sides and 4 arrays. You must subract 1 off the count of the LED when entering it as the array is 0 based. For example the first LED on the
// string is entered as 0.
int topLeds[] = {18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47};
int bottomLeds[] = {14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51};
int leftLeds[] = {48, 49, 50};
int rightLeds[] = {15, 16, 17};

// Eneter your wifi credentials here - If you would like to enter your wifi credentials now you can with these variables. This is a nice easy
// method to get your ESP8266 connected to your network quickly. If you dont you can always set it up later in the wifi portal.
String SSID = "DTVNET_83B0AE";
String Password = "XXXXXXXXXXX";
// ########################################################## End of Sketch Variables ##########################################################

// File System Variables
bool spiffsCorrectSize = false;

// Wifi Variables and Objects
String programmedSSID = SSID;
String programmedPassword = Password;
bool wifiStarting = false;
bool softApStarted = false;
IPAddress accessPointIP = IPAddress(192, 168, 1, 1);
WiFiEventHandler stationConnectedHandler;
WiFiEventHandler stationDisconnectedHandler;

// DNS and mDNS Objects
DNSServer captivePortalDNS;
MDNSResponder::hMDNSService mdnsService;

// Webserver and OTA Objects
ESP8266WebServer restServer(80);
ESP8266HTTPUpdateServer OTAServer;

// Web Sockets Variabels and Objects
WebSocketsServer webSocket(81);
bool processingMessage = false;
bool clientNeedsUpdate = false;

// NTP Variables and Objects
AsyncUDP udpClient;
bool ntpTimeSet = false;
String ntpHostName = "pool.ntp.org";
IPAddress ntpIpAddress = IPAddress(0, 0, 0, 0);
unsigned long utcOffset = UTC_OFFSET * 3600; // in seconds
unsigned long collectionPeriod = 3600;
unsigned long currentEpochTime = 0;
unsigned long lastNTPCollectionTime = 0;

// LED string object and Variables
CRGB ledString[NUM_LEDS];
int topNumLeds = sizeof(topLeds) / sizeof(*topLeds);
int bottomNumLeds = sizeof(bottomLeds) / sizeof(*bottomLeds);
int leftNumLeds = sizeof(leftLeds) / sizeof(*leftLeds);
int rightNumLeds = sizeof(rightLeds) / sizeof(*rightLeds);

// Base Variables of the Light
String Name = DEFAULT_NAME; // The default Name of the Device
String Mode = ""; // The default Mode of the Device
bool State = true; // The Default Mode of the Light
int FadeTime = 200; // Fading time between states in ms
String currentMode = Mode; // Placeholder variable for changing mode
String previousMode = ""; // Placeholder variable for changing mode
bool previousState = false; // Placeholder variable for changing state
float modeChangeFadeAmount = 0; // Place holder for global brightness during mode change

// Colour Mode Variables
int colourRed = 128;
int colourGreen = 128;
int colourBlue = 128;

// Rainbow Mode Variables
int rainbowStartHue = 0;
int rainbowSpeed = 10;
int rainbowBri = 100;
float rainbowAddedHue = 0;

// Clock Mode Variables
int clockHourRed = 128;
int clockHourGreen = 128;
int clockHourBlue = 128;
int clockMinRed = 128;
int clockMinGreen = 128;
int clockMinBlue = 128;
int clockOnPauseBrightness = 255;
unsigned long lastClockExecution = 0;

// Bell Curve Mode Variables
int bellCurveRed = 128;
int bellCurveGreen = 128;
int bellCurveBlue = 128;

// Night Rider Mode Variables
int nightRiderTopLedNumber = 0;
int nightRiderBottomLedNumber = 0;
int nightRiderTopIncrement = 1;
int nightRiderBottomIncrement = 1;

// Setup Method - Runs only once before the main loop. Useful for setting things up
void setup() {
// Add a short delay on start
delay(1000);

// Start Serial
Serial.begin(115200);
Serial.println();

// Check if the flash has been set up correctly
spiffsCorrectSize = checkFlashConfig();
if (spiffsCorrectSize) {
// Init the LED's
ledStringInit();

// Get saved settings
getConfig();

// Start Wifi
wifiInit();

// Setup Webserver
webServerInit();

// Setup websockets
websocketsInit();

}
else Serial.println("[setup] - Flash configuration was not set correctly. Please check your settings under "tools->flash size:"");
}

// The Main Loop Methdo - This runs continuously
void loop() {
// Check if the flash was correctly setup
if (spiffsCorrectSize) {
// Handle the captive portal
captivePortalDNS.processNextRequest();

// Handle mDNS 
MDNS.update();

// // Handle the webserver
restServer.handleClient();

// Handle Websockets
webSocket.loop();

// Get the time when needed
handleNTP();

// Update WS clients when needed
updateClients();

// Handle the wifi connection 
handleWifiConnection();

// Update the LED's
handleMode();

}
else {
delay(10000);
Serial.println("[loop] - Flash configuration was not set correctly. Please check your settings under "tools->flash size:"");
}
}


Also I want to share to you a small video where I record the error that the esp8266 is showing when I pick up the other effects.

the error that the esp8266 shows when I change the effects is:

18:23:21.879 ->
18:23:21.879 -> [handleMode] - LED string was set up correctly
18:23:21.913 -> [webServerInit] - Webserver was set up correctly
18:23:21.913 -> [websocketsInit] - Websocket server is now running on port 81
18:23:21.913 -> [handleMode] - Mode changed to: Bell Curve
18:23:21.913 ->
18:23:21.913 -> Exception (9):
18:23:21.913 -> epc1=0x40226784 epc2=0x00000000 epc3=0x00000000 excvaddr=0x807f7f97 depc=0x00000000
18:23:21.949 ->
18:23:21.949 -> >>>stack>>>
18:23:21.949 ->
18:23:21.949 -> ctx: cont
18:23:21.949 -> sp: 3ffffdd0 end: 3fffffc0 offset: 01a0
18:23:21.949 -> 3fffff70: 40226860 00000000 00001388 4021041a
18:23:21.949 -> 3fffff80: 00000000 00000000 3ffef5f4 4021a6c8
18:23:21.949 -> 3fffff90: 3fffdad0 00000000 3ffefe00 40207101
18:23:21.949 -> 3fffffa0: 3fffdad0 00000000 3ffefe00 4021d8e0
18:23:21.949 -> 3fffffb0: feefeffe feefeffe 3ffe86a4 40100885
18:23:21.949 -> <<<stack<<<
18:23:21.984 ->
18:23:21.984 -> ets Jan 8 2013,rst cause:2, boot mode:(3,7)
18:23:21.984 ->
18:23:21.984 -> load 0x4010f000, len 1384, room 16
18:23:21.984 -> tail 8
18:23:21.984 -> chksum 0x2d
18:23:21.984 -> csum 0x2d
18:23:21.984 -> vac02aff5
18:23:21.984 -> ~ld
18:23:23.063 ->
18:23:23.063 -> [handleMode] - LED string was set up correctly
18:23:23.106 -> [webServerInit] - Webserver was set up correctly
18:23:23.106 -> [websocketsInit] - Websocket server is now running on port 81
18:23:23.106 -> [handleMode] - Mode changed to: Bell Curve
18:23:23.106 ->
18:23:23.106 -> Exception (9):
18:23:23.106 -> epc1=0x40226784 epc2=0x00000000 epc3=0x00000000 excvaddr=0x807f7f97 depc=0x00000000
18:23:23.106 ->
18:23:23.106 -> >>>stack>>>
18:23:23.106 ->
18:23:23.106 -> ctx: cont
18:23:23.106 -> sp: 3ffffdd0 end: 3fffffc0 offset: 01a0
18:23:23.106 -> 3fffff70: 40226860 00000000 00001388 4021041a
18:23:23.106 -> 3fffff80: 00000000 00000000 3ffef5f4 4021a6c8
18:23:23.146 -> 3fffff90: 3fffdad0 00000000 3ffefe00 40207101
18:23:23.146 -> 3fffffa0: 3fffdad0 00000000 3ffefe00 4021d8e0
18:23:23.146 -> 3fffffb0: feefeffe feefeffe 3ffe86a4 40100885
18:23:23.146 -> <<<stack<<<
18:23:23.146 ->
18:23:23.146 -> ets Jan 8 2013,rst cause:2, boot mode:(3,7)
18:23:23.146 ->
18:23:23.146 -> load 0x4010f000, len 1384, room 16
18:23:23.146 -> tail 8
18:23:23.146 -> chksum 0x2d
18:23:23.146 -> csum 0x2d
18:23:23.146 -> vac02aff5
18:23:23.146 -> ~ld
18:23:24.236 ->
18:23:24.236 -> [handleMode] - LED string was set up correctly
18:23:24.283 -> [webServerInit] - Webserver was set up correctly
18:23:24.283 -> [websocketsInit] - Websocket server is now running on port 81
18:23:24.283 -> [handleMode] - Mode changed to: Bell Curve
18:23:24.283 ->
18:23:24.283 -> Exception (9):
18:23:24.283 -> epc1=0x40226784 epc2=0x00000000 epc3=0x00000000 excvaddr=0x807f7f97 depc=0x00000000
18:23:24.283 ->
18:23:24.283 -> >>>stack>>>
18:23:24.283 ->
18:23:24.283 -> ctx: cont
18:23:24.283 -> sp: 3ffffdd0 end: 3fffffc0 offset: 01a0
18:23:24.283 -> 3fffff70: 40226860 00000000 00001388 4021041a
18:23:24.283 -> 3fffff80: 00000000 00000000 3ffef5f4 4021a6c8
18:23:24.330 -> 3fffff90: 3fffdad0 00000000 3ffefe00 40207101
18:23:24.330 -> 3fffffa0: 3fffdad0 00000000 3ffefe00 4021d8e0
18:23:24.330 -> 3fffffb0: feefeffe feefeffe 3ffe86a4 40100885
18:23:24.330 -> <<<stack<<<
18:23:24.330 ->
18:23:24.330 -> ets Jan 8 2013,rst cause:2, boot mode:(3,7)
18:23:24.330 ->
18:23:24.330 -> load 0x4010f000, len 1384, room 16
18:23:24.330 -> tail 8
18:23:24.330 -> chksum 0x2d
18:23:24.330 -> csum 0x2d
18:23:24.330 -> vac02aff5
18:23:24.330 -> ~ld
18:23:25.379 ->
18:23:25.425 -> [handleMode] - LED string was set up correctly
18:23:25.472 -> [webServerInit] - Webserver was set up correctly
18:23:25.472 -> [websocketsInit] - Websocket server is now running on port 81
18:23:25.472 -> [handleMode] - Mode changed to: Bell Curve
18:23:25.472 ->
18:23:25.472 -> Exception (9):
18:23:25.472 -> epc1=0x40226784 epc2=0x00000000 epc3=0x00000000 excvaddr=0x807f7f97 depc=0x00000000
18:23:25.472 ->
18:23:25.472 -> >>>stack>>>
18:23:25.472 ->
18:23:25.472 -> ctx: cont
18:23:25.472 -> sp: 3ffffdd0 end: 3fffffc0 offset: 01a0
18:23:25.472 -> 3fffff70: 40226860 00000000 00001388 4021041a
18:23:25.472 -> 3fffff80: 00000000 00000000 3ffef5f4 4021a6c8
18:23:25.472 -> 3fffff90: 3fffdad0 00000000 3ffefe00 40207101
18:23:25.472 -> 3fffffa0: 3fffdad0 00000000 3ffefe00 4021d8e0
18:23:25.472 -> 3fffffb0: feefeffe feefeffe 3ffe86a4 40100885
18:23:25.519 -> <<<stack<<<
18:23:25.519 ->
18:23:25.519 -> ets Jan 8 2013,rst cause:2, boot mode:(3,7)
18:23:25.519 ->
18:23:25.519 -> load 0x4010f000, len 1384, room 16
18:23:25.519 -> tail 8
18:23:25.519 -> chksum 0x2d
18:23:25.519 -> csum 0x2d
18:23:25.519 -> vac02aff5
18:23:25.519 -> ~ld
18:23:26.584 ->
18:23:26.584 -> [handleMode] - LED string was set up correctly
18:23:26.621 -> [webServerInit] - Webserver was set up correctly
18:23:26.621 -> [websocketsInit] - Websocket server is now running on port 81
18:23:26.621 -> [handleMode] - Mode changed to: Bell Curve
18:23:26.621 ->
18:23:26.621 -> Exception (9):
18:23:26.621 -> epc1=0x40226784 epc2=0x00000000 epc3=0x00000000 excvaddr=0x807f7f97 depc=0x00000000
18:23:26.657 ->
18:23:26.657 -> >>>stack>>>
18:23:26.657 ->
18:23:26.657 -> ctx: cont
18:23:26.657 -> sp: 3ffffdd0 end: 3fffffc0 offset: 01a0
18:23:26.657 -> 3fffff70: 40226860 00000000 00001388 4021041a
18:23:26.657 -> 3fffff80: 00000000 00000000 3ffef5f4 4021a6c8
18:23:26.657 -> 3fffff90: 3fffdad0 00000000 3ffefe00 40207101
18:23:26.657 -> 3fffffa0: 3fffdad0 00000000 3ffefe00 4021d8e0
18:23:26.657 -> 3fffffb0: feefeffe feefeffe 3ffe86a4 40100885
18:23:26.657 -> <<<stack<<<
18:23:26.690 ->
18:23:26.690 -> ets Jan 8 2013,rst cause:2, boot mode:(3,7)
18:23:26.690 ->
18:23:26.690 -> load 0x4010f000, len 1384, room 16
18:23:26.690 -> tail 8
18:23:26.690 -> chksum 0x2d
18:23:26.690 -> csum 0x2d
18:23:26.690 -> vac02aff5
18:23:26.690 -> ~ld
18:23:27.764 ->
18:23:27.764 -> [handleMode] - LED string was set up correctly
18:23:27.800 -> [webServerInit] - Webserver was set up correctly
18:23:27.800 -> [websocketsInit] - Websocket server is now running on port 81
18:23:27.800 -> [handleMode] - Mode changed to: Bell Curve
18:23:27.800 ->
18:23:27.800 -> Exception (9):
18:23:27.800 -> epc1=0x40226784 epc2=0x00000000 epc3=0x00000000 excvaddr=0x807f7f97 depc=0x00000000
18:23:27.834 ->
18:23:27.834 -> >>>stack>>>
18:23:27.834 ->
18:23:27.834 -> ctx: cont
18:23:27.834 -> sp: 3ffffdd0 end: 3fffffc0 offset: 01a0
18:23:27.834 -> 3fffff70: 40226860 00000000 00001388 4021041a
18:23:27.834 -> 3fffff80: 00000000 00000000 3ffef5f4 4021a6c8
18:23:27.834 -> 3fffff90: 3fffdad0 00000000 3ffefe00 40207101
18:23:27.834 -> 3fffffa0: 3fffdad0 00000000 3ffefe00 4021d8e0
18:23:27.834 -> 3fffffb0: feefeffe feefeffe 3ffe86a4 40100885
18:23:27.834 -> <<<stack<<<
18:23:27.868 ->
18:23:27.868 -> ets Jan 8 2013,rst cause:2, boot mode:(3,7)
18:23:27.868 ->
18:23:27.868 -> load 0x4010f000, len 1384, room 16
18:23:27.868 -> tail 8
18:23:27.868 -> chksum 0x2d
18:23:27.868 -> csum 0x2d
18:23:27.868 -> vac02aff5
18:23:27.868 -> ~ld


and it goes in a bucle again and again.

Thank you so much if you can help me.

Hi Mate, thanks for coming over here. Will be much easier to deal with coding issues here than Instructables.

From the get go I think it looks like you have not set up the LED's properly in the sketch. As you state you are not using 66 LED's and have instead a 24 LED neo pixel ring I assume from Adafruit or such. Due to the new geometry and lower number of LED's used you will need to be a bit creative and change some of the code for it to work with all my modes.

As a simple overview, I believe what is happening is the modes are trying to address and LED that does not exist in the locations specified by the topLeds and bottomLeds arrays. This the causes the errors you see repeated as the light boots again and attempts to set the same mode causing it to crash again. If you would like to read a little more on arrays and why this is causing the error have a quick look at this.

If you want to use my code for everything else like the website, rainbow, and colour mode, The results will be the same. But for modes like bell curve and night rider, the specific LED's being addressed will be completely wrong.

So as a fix for your project I hope, try replacing lines 38 to 41 to;

int topLeds[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
int bottomLeds[] = {12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
int leftLeds[] = {};
int rightLeds[] = {};

This should map your LED's correctly and stop the crashing. To be sure there is nothing else wrong with the flash on the chip I recommend also erasing all the memory on the ESP when uploading as i have stated in the Instructable.

Let me know if this works,

Hello Sir.
Thank you so much, the error was solved.
You are a very kind person for taking your time to teach and guide others.

Thanks a lot, it works fantastic

Awesome glad it's fixed. Closing the issue.