hello. trying to understand why this sketch below does not want to be online. or frequent disconnections sometimes after five minutes or several hours.
the sketch controls a ring neopixelixel 16b led rgb with departure to daytime wanted. thanks for a help.translate with google
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "FastLED.h"
#define LED_PIN 2 // GPIO pin for RGB LEDs.
#define NUM_LEDS 16 // Number of LEDs connected.
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define FRAMES_PER_SECOND 40
//#include <TimeLib.h>
#include <WidgetRTC.h>
CRGB leds[NUM_LEDS];
//BlynkTimer timer;
WidgetRTC rtc;
WidgetLED led1(V11);
SimpleTimer timer;
char currentTime[9];
char auth[] = "";
char ssid[] = "moreno12344";
char pass[] = "lucky123";
char server[] = "blynk-cloud.com";
bool isFirstConnect = true;
int r = 255;
int g = 255;
int b = 255;
int Brightness ;
int masterSwitch ;
int autoMode = 1;
uint8_t gHue = 0;
void setup() {
Serial.begin(9600);
Serial.println();
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalSMD5050);
FastLED.setBrightness(Brightness);
Blynk.begin(auth, ssid, pass,server);
timer.setInterval(1500L, ringled);
timer.setInterval(30000L, activetoday);
}
BLYNK_CONNECTED() {
rtc.begin();
Blynk.syncAll();
}
void activetoday(){
if(Blynk.connected())
if(year() != 1970){
Blynk.syncVirtual(V8); // sync scheduler #1
}
}
BLYNK_WRITE(V8) { // Scheduler #1 Time Input widget
TimeInputParam t(param);
int Avvio1;
unsigned int nowseconds = ((hour() * 3600) + (minute() * 60) + second());
unsigned int startseconds = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
unsigned int stopseconds = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
int dayadjustment = -1;
if(weekday() == 1){
dayadjustment = 6; // needed for Sunday Time library is day 1 and Blynk is day 7
}
if(t.isWeekdaySelected((weekday() + dayadjustment))){ //Time library starts week on Sunday, Blynk on Monday
//Schedule is ACTIVE today
if(nowseconds >= startseconds - 31 && nowseconds <= startseconds + 31 ){ // 62s on 60s timer ensures 1 trigger command is sent
led1.on(); // turn on virtual LED
Avvio1 = masterSwitch = 1;
Blynk.virtualWrite(10, 1);
//Serial.println("Schedule 1 started");
}
if(nowseconds >= stopseconds - 31 && nowseconds <= stopseconds + 31 ){ // 62s on 60s timer ensures 1 trigger command is sent
led1.off(); // turn OFF virtual LED
Avvio1 = masterSwitch= 0;
Blynk.virtualWrite(10, 0);
//Serial.println("Schedule 1 finished");
}
}
}
BLYNK_WRITE(V10) {
masterSwitch = param.asInt();
}
void ringled(){
FastLED.setBrightness(Brightness);
if(masterSwitch == 0) {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Black;
FastLED.show();
}
}
if(autoMode == 0 && masterSwitch == 1) {
for (int i = 0; i < NUM_LEDS; i++){
leds[i] = CRGB(r, g, b);\
FastLED.show();
}
}
if(autoMode == 1 && masterSwitch == 1) {
fill_rainbow( leds, NUM_LEDS, gHue, 2);
// send the 'leds' array out to the actual LED strip
FastLED.show();
// insert a delay to keep the framerate modest
FastLED.delay(40/FRAMES_PER_SECOND);
EVERY_N_MILLISECONDS(80) {
gHue++; // slowly cycle the "base color" through the rainbow
}
}
}
BLYNK_WRITE(V6) {
Brightness = param.asInt();
}
//---Master On/Off---
BLYNK_WRITE(V0) {
masterSwitch = param.asInt();
}
//--- Red slider value---
BLYNK_WRITE(V1) {
r = param.asInt();
}
//--- Green slider value---
BLYNK_WRITE(V2) {
g = param.asInt();
}
//--- Blue slider value---
BLYNK_WRITE(V3) {
b = param.asInt();
}
//--- Toggle Auto/Manual Mode ---
BLYNK_WRITE(V4) {
autoMode = param.asInt();
}
void loop()
{
if(Blynk.connected()){
Blynk.run();
}
timer.run();
}