Hi Guys,
We've built a Lighthouse that does some light shows for a customer, but out sourced the code for the esp8266. Whilst ut in the rain a board got damaged and we've had to repace it. however when i try download the code to the esp i keep getting an error
can anyone help?
the error says 'D3' was not declared in the scope
Date :- 2021-March-24
Version :- 4.0
**************************************************************************/
//#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP_Mail_Client.h>
#include <EEPROM.h>
int addr = 0;
const String WIFI_SSID = "xxxxxxxxxxxxxxx";
const String WIFI_PASSWORD = "xxxxxxxxxxxxxxxxxxx";
#define WIFI_TIMEOUT 300000
unsigned long last_wifi_check_time = 0;
String PrevSMSCountChr;
int PrevSMSCount;
int CurrentSMSCount;
String CurrentSMSCountChr;
#define DOOR_RELAY D3
#define WINDOW_RELAY D2
#define WINDOW_HALFWAYUP_RELAY D1
#define T1000SRELAY D5
long mailEffectStart;
long mailEffectwait = 30000;
long ToplightStart;
long Toplightwait = 15000; // 15 seconds
long MiddlelightStart;
long Middlelightwait = 5000; //5 seconds
long BottomlightStart;
long Bottomlightwait = 7000; //7 seconds
//long RainBowStartTime, LedOffStarttime;
//byte color[10][3] = { {190,0,109},{230,255,0},{255,140,109},{255,0,0},{0,255,17},{25,255,255},{0,0,255},{179,0,255},{0,205,255},{255,77,0}};
//
//uint32_t ColorCode;
//int saturation,lightness;
//CRGB leds[LED_COUNT];
//#define LED_TYPE WS2812B
//#define COLOR_ORDER RGB
//long Starttime;
//long BlinkDelay = 200;
/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */
#define IMAP_HOST "imap.gmail.com"
/** The imap port e.g.
* 143 or esp_mail_imap_port_143
* 993 or esp_mail_imap_port_993
*/
#define IMAP_PORT 993
/* The log in credentials */
#define AUTHOR_EMAIL "xxxxxxxxxxxxx"
#define AUTHOR_PASSWORD "xxxxxxxxxx"
/* Print the selected folder info */
void printSelectedMailboxInfo(IMAPSession &imap);
/* The IMAP Session object used for Email reading */
IMAPSession imap;
unsigned long readMillis = 0;
int nextMsgUID = 0;
int msgUID = 0;
int sign = -1;
/* Declare the session config data */
ESP_Mail_Session session;
/* Setup the configuration for searching or fetching operation and its result */
IMAP_Config config;
void setup()
{
pinMode(DOOR_RELAY,OUTPUT);
pinMode(WINDOW_RELAY,OUTPUT);
pinMode(WINDOW_HALFWAYUP_RELAY,OUTPUT);
pinMode(T1000SRELAY,OUTPUT);
digitalWrite(DOOR_RELAY,HIGH);
digitalWrite(WINDOW_RELAY,HIGH);
digitalWrite(WINDOW_HALFWAYUP_RELAY,HIGH);
digitalWrite(T1000SRELAY,HIGH);
Serial.begin(115200);
EEPROM.begin(512); //Initialize EEPROM
ReadMemory();
Serial.println();
Serial.print("Connecting to AP");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(200);
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();
/** Enable the debug via Serial port
* none debug or 0
* basic debug or 1
*/
imap.debug(1);
/* Set the callback function to get the reading results */
//imap.callback(imapCallback);
/* Set the session config */
session.server.host_name = IMAP_HOST;
session.server.port = IMAP_PORT;
session.login.email = AUTHOR_EMAIL;
session.login.password = AUTHOR_PASSWORD;
/* Message UID to fetch or read */
config.fetch.uid = "";
/* Search criteria */
config.search.criteria = "";
/* Also search the unseen message */
config.search.unseen_msg = true;
/* Set the storage to save the downloaded files and attachments */
config.storage.saved_path = "/email_data";
/** The file storage type e.g.
* esp_mail_file_storage_type_none,
* esp_mail_file_storage_type_flash, and
* esp_mail_file_storage_type_sd
*/
config.storage.type = esp_mail_file_storage_type_flash;
/** Set to download heades, text and html messaeges,
* attachments and inline images respectively.
*/
config.download.header = false;
config.download.text = false;
config.download.html = false;
config.download.attachment = false;
config.download.inlineImg = false;
/** Set to enable the results i.e. html and text messaeges
* which the content stored in the IMAPSession object is limited
* by the option config.limit.msg_size.
* The whole message can be download through config.download.text
* or config.download.html which not depends on these enable options.
*/
config.enable.html = true;
config.enable.text = true;
/* Set to enable the sort the result by message UID in the ascending order */
config.enable.recent_sort = true;
/* Set to report the download progress via the default serial port */
config.enable.download_status = true;
/* Set the limit of number of messages in the search results */
config.limit.search = 5;
/** Set the maximum size of message stored in
* IMAPSession object in byte
*/
config.limit.msg_size = 512;
/** Set the maximum attachments and inline images files size
* that can be downloaded in byte.
* The file which its size is largger than this limit may be saved
* as truncated file.
*/
config.limit.attachment_size = 1024 * 1024 * 5;
/* Connect to server with the session and config */
if (!imap.connect(&session, &config))
{
Serial.println("IMAP connection failed!");
return;
}
else
{
Serial.println("IMAP connection OK");
}
/* Open or select the mailbox folder to read or search the message */
if (!imap.selectFolder("LightHouse"))
{
Serial.println("Folder selection failed!");
return;
}
else
{
Serial.println("Folder selection OK");
}
/* {Optional] */
printSelectedMailboxInfo(imap);
}
void loop()
{
// Check WiFi connectivity
unsigned long now = millis();
if(now - last_wifi_check_time > WIFI_TIMEOUT) {
Serial.print("Checking WiFi... ");
if(WiFi.status() != WL_CONNECTED) {
Serial.println("WiFi connection lost. Reconnecting...");
wifi_setup();
} else {
Serial.println("WiFi OK");
}
last_wifi_check_time = now;
}
//// End of Checking WiFi
digitalWrite(T1000SRELAY,HIGH);
// Check new Mail every 5 seconds
if (millis() - readMillis > 5000 || readMillis == 0)
{
/* Open or select the mailbox folder to read or search the message */
if (!imap.selectFolder("LightHouse"))
return;
printSelectedMailboxInfo(imap);
readMillis = millis();
if (CurrentSMSCount != PrevSMSCount)
{
mailEffectStart = millis();
LighthouseShow();
WritetoMemory();
PrevSMSCount = CurrentSMSCount;
//StartStarEffect();
}
}
}
void wifi_setup() {
Serial.println();
Serial.print("Connecting to ");
Serial.println(WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
WiFi.mode(WIFI_STA);
#ifdef STATIC_IP
WiFi.config(ip, gateway, subnet);
#endif
unsigned long connect_start = millis();
while(WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
if(millis() - connect_start > WIFI_TIMEOUT) {
Serial.println();
Serial.print("Tried ");
Serial.print(WIFI_TIMEOUT);
Serial.print("ms. Resetting ESP now.");
ESP.reset();
}
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();
}
void printSelectedMailboxInfo(IMAPSession &imap)
{
/* Declare the selected folder info class to get the info of selected mailbox folder */
SelectedFolderInfo sFolder = imap.selectedFolder();
/* Show the mailbox info */
Serial.printf("\nTotal Messages: %d\n", sFolder.msgCount());
CurrentSMSCount = sFolder.msgCount();
}
void LighthouseShow()
{
Serial.println("Start");
digitalWrite(DOOR_RELAY,LOW);
digitalWrite(WINDOW_RELAY,LOW);
digitalWrite(WINDOW_HALFWAYUP_RELAY,LOW);
digitalWrite(T1000SRELAY,LOW);
while((mailEffectStart + mailEffectwait) > millis())
{
yield();
}
digitalWrite(DOOR_RELAY,HIGH);
digitalWrite(WINDOW_RELAY,HIGH);
digitalWrite(WINDOW_HALFWAYUP_RELAY,HIGH);
digitalWrite(T1000SRELAY,HIGH);
Serial.println("End");
// ToplightStart = millis();
// //Serial.println("End");
// digitalWrite(DOOR_RELAY,LOW);
// while((ToplightStart + Toplightwait) > millis())
// {
// yield();
// }
// digitalWrite(DOOR_RELAY,HIGH);
// MiddlelightStart = millis();
// digitalWrite(WINDOW_HALFWAYUP_RELAY,LOW);
// while((MiddlelightStart + Middlelightwait) > millis())
// {
// yield();
// }
// digitalWrite(WINDOW_HALFWAYUP_RELAY,HIGH);
// BottomlightStart = millis();
// digitalWrite(WINDOW_RELAY,LOW);
// while((BottomlightStart + Bottomlightwait) > millis())
// {
// yield();
// }
// digitalWrite(WINDOW_RELAY,HIGH);
delay(3000);
//Serial.println("finish");
}
void WritetoMemory()
{
CurrentSMSCountChr = String(CurrentSMSCount);
for(int i=0;i<20;i++) //loop upto string lenght www.length() returns length of string
{
EEPROM.write(0x0F+i,0); //Write one by one with starting address of 0x0F
}
EEPROM.commit(); //Store data to EEPROM
for(int i=0;i<CurrentSMSCountChr.length();i++) //loop upto string lenght www.length() returns length of string
{
EEPROM.write(0x0F+i,CurrentSMSCountChr[i]); //Write one by one with starting address of 0x0F
}
EEPROM.commit(); //Store data to EEPROM
ReadMemory();
}
void ReadMemory()
{
CurrentSMSCountChr = "";
for(int i=0;i<20;i++)
{
CurrentSMSCountChr = CurrentSMSCountChr + char(EEPROM.read(0x0F+i)); //Read one by one with starting address of 0x0F
}
PrevSMSCount = CurrentSMSCountChr.toInt();
Serial.print("Current SMS Count- "+ CurrentSMSCountChr); //Print the text on serial monitor
}
//void getRGB(int hue, int sat, int val, int colors[3]) {
// /* convert hue, saturation and brightness ( HSB/HSV ) to RGB
// The dim_curve is used only on brightness/value and on saturation (inverted).
// This looks the most natural.
// */
//
// val = dim_curve[val];
// sat = 255-dim_curve[255-sat];
//
// int r;
// int g;
// int b;
// int base;
//
// if (sat == 0) { // Acromatic color (gray). Hue doesn't mind.
// colors[0]=val;
// colors[1]=val;
// colors[2]=val;
// } else {
//
// base = ((255 - sat) * val)>>8;
//
// switch(hue/60) {
// case 0:
// r = val;
// g = (((val-base)*hue)/60)+base;
// b = base;
// break;
//
// case 1:
// r = (((val-base)*(60-(hue%60)))/60)+base;
// g = val;
// b = base;
// break;
//
// case 2:
// r = base;
// g = val;
// b = (((val-base)*(hue%60))/60)+base;
// break;
//
// case 3:
// r = base;
// g = (((val-base)*(60-(hue%60)))/60)+base;
// b = val;
// break;
//
// case 4:
// r = (((val-base)*(hue%60))/60)+base;
// g = base;
// b = val;
// break;
//
// case 5:
// r = val;
// g = base;
// b = (((val-base)*(60-(hue%60)))/60)+base;
// break;
// }
//
// colors[0]=r;
// colors[1]=g;
// colors[2]=b;
// }
//}
//
//
//
//
//void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
// int Pixel = random(300);
// uint32_t currentColor = strip.getPixelColor(Pixel);
//
// strip.setPixelColor(Pixel,strip.Color(rgb_colorsSpark[0],rgb_colorsSpark[1],rgb_colorsSpark[2]));
// strip.show();
//
// delay(SpeedDelay);
// strip.setPixelColor(Pixel,currentColor);
// strip.show();
// delay(10);
//}
//
//
//// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
//void rainbow(int wait) {
// int LedX;
// for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
// for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
// int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
// strip.setPixelColor((strip.numPixels()-i), strip.gamma32(strip.ColorHSV(pixelHue)));
// }
//
// if (((millis() - RainBowStartTime) > 2000) && (LedOffStarttime == 0))
// {
// LedOffStarttime = millis();
// }
// if (LedOffStarttime > 0)
// {
// for(LedX = 0; LedX < (millis()-LedOffStarttime)/10;LedX++)
// {
// strip.setPixelColor(LedX, 0, 0, 0);
// }
// }
//
// if (LedX >= strip.numPixels())
// {
// break;
// }
//
//
// strip.show(); // Update strip with new contents
// delay(wait); // Pause for a moment
// }
//}
//
//// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
//void theaterChaseRainbow(int wait) {
// int firstPixelHue = 0; // First pixel starts at red (hue 0)
// for(int a=0; a<45; a++) { // Repeat 45 times...
// for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
// strip.clear(); // Set all pixels in RAM to 0 (off)
// for(int c=b; c<strip.numPixels(); c += 3) {
// int hue = firstPixelHue + c * 65536L / strip.numPixels();
// uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
// strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
// }
// strip.show(); // Update strip with new contents
// delay(wait); // Pause for a moment
// firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
// }
// }
//}
//
//
//
//void TwinkleRandom(int Count, int SpeedDelay, boolean OnlyOne) {
// setAll(0,0,0);
//
// for (int i=0; i<Count; i++) {
// strip.setPixelColor(random(strip.numPixels()),random(0,255),random(0,255),random(0,255));
// }
// strip.show();
// delay(SpeedDelay);
//}
//
//
//void setAll(byte red, byte green, byte blue) {
// for(int i = 0; i < strip.numPixels(); i++ ) {
// strip.setPixelColor(i, red, green, blue);
// }
// strip.show();
//}
//
//
//
//
//void MultiColorStrips()
//{
// for(int k=0;k<30;k++)
// {
// strip.fill(strip.Color(color[k%10][0],color[k%10][1],color[k%10][2]),random(0,((LED_COUNT/10)*1)),(LED_COUNT/20));
// strip.fill(strip.Color(color[(k+1)%10][0],color[(k+1)%10][1],color[(k+1)%10][2]),random(((LED_COUNT/10)*1),((LED_COUNT/10)*2)),(LED_COUNT/20));
// strip.fill(strip.Color(color[(k+2)%10][0],color[(k+2)%10][1],color[(k+2)%10][2]),random(((LED_COUNT/10)*2),((LED_COUNT/10)*3)),(LED_COUNT/20));
// strip.fill(strip.Color(color[(k+3)%10][0],color[(k+3)%10][1],color[(k+3)%10][2]),random(((LED_COUNT/10)*3),((LED_COUNT/10)*4)),(LED_COUNT/20));
// strip.fill(strip.Color(color[(k+4)%10][0],color[(k+4)%10][1],color[(k+4)%10][2]),random(((LED_COUNT/10)*4),((LED_COUNT/10)*5)),(LED_COUNT/20));
// strip.fill(strip.Color(color[(k+5)%10][0],color[(k+5)%10][1],color[(k+5)%10][2]),random(((LED_COUNT/10)*5),((LED_COUNT/10)*6)),(LED_COUNT/20));
// strip.fill(strip.Color(color[(k+6)%10][0],color[(k+6)%10][1],color[(k+6)%10][2]),random(((LED_COUNT/10)*6),((LED_COUNT/10)*7)),(LED_COUNT/20));
// strip.fill(strip.Color(color[(k+7)%10][0],color[(k+7)%10][1],color[(k+7)%10][2]),random(((LED_COUNT/10)*7),((LED_COUNT/10)*8)),(LED_COUNT/20));
// strip.fill(strip.Color(color[(k+8)%10][0],color[(k+8)%10][1],color[(k+8)%10][2]),random(((LED_COUNT/10)*8),((LED_COUNT/10)*9)),(LED_COUNT/20));
// strip.fill(strip.Color(color[(k+9)%10][0],color[(k+9)%10][1],color[(k+9)%10][2]),random(((LED_COUNT/10)*9),((LED_COUNT/10)*10)),(LED_COUNT/20));
// strip.show();
// delay(20);
// setAll(0,0,0);
// }
//}
//
//
//void MultiDotPixels()
//{
// int LEDid;
// for (LEDid = 0; LEDid < strip.numPixels(); LEDid++)
// {
// if (LEDid%10 == 0)
// {
// strip.setPixelColor(LEDid,190,0,109); //Red,Green,Blue
// }
// if (LEDid%10 == 1)
// {
// strip.setPixelColor(LEDid,230,255,0); //Red,Green,Blue yellow
// }
// if (LEDid%10 == 2)
// {
// strip.setPixelColor(LEDid,255,140,109); //Red,Green,Blue orange
// }
// if (LEDid%10 == 3)
// {
// strip.setPixelColor(LEDid,255,0,0); //Red,Green,Blue red
// }
// if (LEDid%10 == 4)
// {
// strip.setPixelColor(LEDid,0,255,17); //Red,Green,Blue green bright
// }
// if (LEDid%10 == 5)
// {
// strip.setPixelColor(LEDid,25,255,255); //Red,Green,Blue white
// }
// if (LEDid%10 == 6)
// {
// strip.setPixelColor(LEDid,0,0,255); //Red,Green,Blue blue
// }
// if (LEDid%10 == 7)
// {
// strip.setPixelColor(LEDid,179,0,255); //Red,Green,Blue purple
// }
// if (LEDid%10 == 8)
// {
// strip.setPixelColor(LEDid,0,205,255); ///Red,Green,Blue light blue
// }
// if (LEDid%10 == 9)
// {
// strip.setPixelColor(LEDid,255,77,0); //Red,Green,Blue dark orange
// }
//
// if (LEDid%30 == 0)
// {
// strip.show();
// delay(1);
// }
// }
//
// delay(500);
// for (LEDid = strip.numPixels(); LEDid > 0; LEDid--)
// {
// strip.setPixelColor(LEDid,0,0,0); //Red,Green,Blue
// if (LEDid%30 == 0)
// {
// strip.show();
// delay(1);
// }
// }
//
//}
//
//
//
/////boouncing ball
//void BouncingBalls(byte red, byte green, byte blue, int BallCount) {
// float Gravity = -9.81;
// int StartHeight = 1;
//
// float Height[BallCount];
// float ImpactVelocityStart = sqrt( -2 * Gravity * StartHeight );
// float ImpactVelocity[BallCount];
// float TimeSinceLastBounce[BallCount];
// int Position[BallCount];
// long ClockTimeSinceLastBounce[BallCount];
// float Dampening[BallCount];
//
// for (int i = 0 ; i < BallCount ; i++) {
// ClockTimeSinceLastBounce[i] = millis();
// Height[i] = StartHeight;
// Position[i] = 0;
// ImpactVelocity[i] = ImpactVelocityStart;
// TimeSinceLastBounce[i] = 0;
// Dampening[i] = 0.90 - float(i)/pow(BallCount,2);
// }
//
// //while (true) {
// for (int z = 0 ; z < 400 ; z++) {
// for (int i = 0 ; i < BallCount ; i++) {
// TimeSinceLastBounce[i] = millis() - ClockTimeSinceLastBounce[i];
// Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;
//
// if ( Height[i] < 0 ) {
// Height[i] = 0;
// ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
// ClockTimeSinceLastBounce[i] = millis();
//
// if ( ImpactVelocity[i] < 0.01 ) {
// ImpactVelocity[i] = ImpactVelocityStart;
// }
// }
// Position[i] = round( Height[i] * (strip.numPixels() - 1) / StartHeight);
// }
//
// for (int i = 0 ; i < BallCount ; i++) {
// strip.setPixelColor(Position[i],red,green,blue);
// }
//
// showStrip();
// setAll(0,0,0);
// yield();
// }
//}
//
//
//
//void showStrip() {
// #ifdef ADAFRUIT_NEOPIXEL_H
// // NeoPixel
// strip.show();
// #endif
// #ifndef ADAFRUIT_NEOPIXEL_H
// // FastLED
// FastLED.show();
// #endif
//}
//
//void setPixel(int Pixel, byte red, byte green, byte blue) {
// #ifdef ADAFRUIT_NEOPIXEL_H
// // NeoPixel
// strip.setPixelColor(Pixel, strip.Color(red, green, blue));
// #endif
// #ifndef ADAFRUIT_NEOPIXEL_H
// // FastLED
// leds[Pixel].r = red;
// leds[Pixel].g = green;
// leds[Pixel].b = blue;
// #endif
//}
//void YellowStarEffect()
//{
// Serial.println("Yellow star");
// fadeToBlackBy( leds, LED_COUNT, 10);
// if ((Starttime + BlinkDelay) < millis())
// {
// ///fadeToBlackBy( leds, LED_COUNT, 10);
// for(int k=0;k<25;k++)
// {
// int pos = random16(LED_COUNT);
// leds[pos] = CRGB::Yellow; //CHSV( 65, 255, 255);
// //FastLED.show();
// yield();
// }
// Starttime = millis();
// //FastLED.show();
// }
// FastLED.show();
//}
//void LighthouseShowold()
//{
// Serial.println("Start");
// digitalWrite(DOOR_RELAY,HIGH);
// digitalWrite(WINDOW_RELAY,HIGH);
// digitalWrite(WINDOW_HALFWAYUP_RELAY,HIGH);
// theaterChaseRainbow(5); // Rainbow-enhanced theaterChase variant
//
// strip.clear();
// for (int j =0; j<70;j++)
// {
// TwinkleRandom(200, 1, false);
// }
//
// MultiDotPixels();
// MultiColorStrips();
// Serial.println("Mid");
// RainBowStartTime = millis();
// LedOffStarttime = 0;
// rainbow(1); // Flowing rainbow cycle along the whole strip
// strip.clear();
// strip.show();
// Serial.println("End");
// digitalWrite(DOOR_RELAY,LOW);
// delay(3000);
// digitalWrite(DOOR_RELAY,HIGH);
// digitalWrite(WINDOW_RELAY,LOW);
// delay(1500);
// digitalWrite(WINDOW_RELAY,HIGH);
// digitalWrite(WINDOW_HALFWAYUP_RELAY,LOW);
// delay(1500);
// digitalWrite(WINDOW_HALFWAYUP_RELAY,HIGH);
// delay(3000);
//
//}