(RESOLVED) "_____" previously defined here; tried removing all backup .ino files

Solved problem, but new problem arose! Title edited accordingly, and new version of code added as attachment. As posted in Reply 5 in this thread:

I’m having a different problem now, same code - now Line 7, which is simply

const char *ssid     = "YOUR_SSID";
const char *password = "YOUR_PASS";

Is giving me the following error:

'const char* ssid' previously defined here

That’s the short version, but the code repeats for basically everything defined prior to “void.setup”; the cactus.io, constant char *password, etc.

I’ve read online this can be caused by creating backup copies of your .ino file (which I did), so I tried removing those from the Arduino folder but still experiencing the issue. Any recommendations?

Looks like just this and another few small errors to fix and it’ll be ready to go; thanks again for your help and for everyone who has posted in other topics, really been a huge help.

I am (if the code works beyond Arduino’s recognized errors) approaching the end of the first version of my project. I am encountering an error I’m having a hard time understanding: “else without previous if” despite an equal count of both if/else statements.
This is my first attempt at coding anything beyond changing some colors or images on a web page, so expect ugly code and noob errors. Most of the code came from kind assistance from this board or Reddit combined with online tutorials so it’s very possible I made errors in combining the sections of code, or other errors. But to my untrained mind, that doesn’t seem to be the problem here.
Essentially what I’m trying to do is tell my NodeMCU, “Run this code for this part of the day, and if it’s not that part of the day, run this code”. Then I could just adjust one set of time parameters instead of both. I could probably just do two separate “if” statements and define separate time periods, but that’s a minor inconvenience and I don’t understand why this isn’t working anyway.
Arduino’s auto formatting indents the first “if” statement more than the error-inducing “else” statement which makes me think it’s some problem with how I set up the code somewhere along the way, but all my brackets are balanced from what I can tell, as if I add any more closing brackets than I have, it closes the void.loop function prematurely. And I’ve already had to fix previous errors with too many or too few brackets so perhaps a different issue in formatting, but again, no experience. A Google search revealed issues related mostly to misplaced semicolons/etc in the code, which I don’t seem to have at least within the “if/else” related lines.
I’m sure the problem will be obvious to someone on this board, just demonstrating I am trying to solve it prior to posting lol
Attached both my full code (Project Jun23…txt) and a “map” of the if/else statements in my code; bold is “if”, italic is “else”. There are 9 of each and the structure makes sense to me logically but there’s clearly an error in the code somewhere. If it’s just some basic error with having too many or too few brackets I apologize in advance, but I’ve encountered those errors before and this doesn’t seem to be one of them. “If/else” structure starts on line 77 and ends on 176, error occurs on 127 (the else which acts as the “bridge” between the day and night conditions).

Project Jun23 - previously defined error.txt (4.62 KB)

Read the "how to use this forum-please read" stickies (in bold at the top of each topic) to see how to post code. A lot more members will see your code if posted properly.

If you use autoformat (ctrl-t or in the IDE, File, Auto Format) to indent your code, the error may be visible.

Every time I post here I’m told I need to post the full code to be of any use, but in case the partial code would be helpful or get more replies:

  {
    int hour = timeClient.getHours();
    if (hour > 6 && hour < 11)  // TIME PARAMETERS (In sync with "day"/lights on or "night"/lights off)
    {
      //code here for period (6 to 24)
      //DAY CONDITIONS / LIGHTS ON
      // read the temp value of the sensor:
      int (sht31.getTemperature_C()); Serial.print(" *C\t");

      // if the temp  value is high enough, turn on the air conditioner:
      if (sht31.getTemperature_C() > 23.8)
      {
        digitalWrite(4, HIGH);
      } else
      {
        digitalWrite(4, LOW);
      }
      // if the temp  value is low enough, turn on the heater:
      if (sht31.getTemperature_C() < 22.2)
      {
        digitalWrite(5, HIGH);
      } else
      {
        digitalWrite(5, LOW);
      }
    }

    {
      // read the % humidity value of the sensor:
      int (sht31.getHumidity()); Serial.print(" %\t\t");

      // if the temp  value is high enough, turn on the dehumidifier:
      // value based on 23 C median temp minus 2.8 C for inner leaf temp for evaporative cooling:
      if (sht31.getHumidity() > 58)
      {
        digitalWrite(13, HIGH);
      } else
      {
        digitalWrite(13, LOW);
      }
      // if the temp  value is low enough, turn on the humidifier:
      // value based on 23 C median temp minus 2.8 C for inner leaf temp for evaporative cooling:
      if (sht31.getHumidity() < 56)
      {
        digitalWrite(15, HIGH);
      } else
      {
        digitalWrite(15, LOW);
      }
    }

    else
    {
      //code here for the rest of the day
      //NIGHT CONDITIONS / LIGHTS OFF
      // read the temp value of the sensor:
      int (sht31.getTemperature_C()); Serial.print(" *C\t");

      // if the temp  value is high enough, turn on the air conditioner:
      if (sht31.getTemperature_C() > 23.8)
      {
        digitalWrite(4, HIGH);
      } else
      {
        digitalWrite(4, LOW);
      }
      // if the temp  value is low enough, turn on the heater:
      if (sht31.getTemperature_C() < 22.2)
      {
        digitalWrite(5, HIGH);
      } else
      {
        digitalWrite(5, LOW);
      }
    }


    // read the % humidity value of the sensor:
    int (sht31.getHumidity()); Serial.print(" %\t\t");

    // if the temp  value is high enough, turn on the dehumidifier:
    // value based on 23 C median temp minus 2.8 C for inner leaf temp for evaporative cooling:
    if (sht31.getHumidity() > 58)
    {
      digitalWrite(13, HIGH);
    } else
    {
      digitalWrite(13, LOW);
    }
    // if the temp  value is low enough, turn on the humidifier:
    // value based on 23 C median temp minus 2.8 C for inner leaf temp for evaporative cooling:
    if (sht31.getHumidity() < 56)
    {
      digitalWrite(15, HIGH);
    } else
    {
      digitalWrite(15, LOW);
    }
  }

7101334:
"If/else" structure starts on line 77 and ends on 176, error occurs on 127 (the else which acts as the "bridge" between the day and night conditions).

My line numbers seem slightly off from yours. The offending else is on line 129 for me, and the if starts at 78.

The if structure on line 77 (in the numbers I see) is contained within a block started on line 76. This block is closed on like 127. An if statement entirely within a block cannot lead to an else statement outside that block.

There's no reason to put that extra block there at all. Delete the pair of curly braces at lines 76 and 127.

Also, code is easier to read if you do

if(condition){
  dostuff();
} else {
  doOtherStuff(); 
}

vs.

if(condition)
{
  dostuff();
} else 
{
  doOtherStuff(); 
}

Less lines to scroll through, and with those short conditions in a row, the similar looking } and {. all lined up at the same level of indentation is visually hard to follow (at least it is for me), and it confounds my "an open brace alone on a line is wrong" instinct. I suspect if you adhered to this convention you'd have noticed the issue and fixed it: "what's this lonely open brace with no associated control structure doing here?"

Nothing changed - just cleaned up
The choice of one-line or next-line curlies is personal - as long as they’re balanced

		// { // unnecessary
    int hour = timeClient.getHours();
		// ----------------------------------
    if (hour > 6 && hour < 11) { 	// FIXED <<-- OOPS - the opening curly was inside the comment 
																	// TIME PARAMETERS (In sync with "day"/lights on or "night"/lights off) {
      //code here for period (6 to 24)
      //DAY CONDITIONS / LIGHTS ON
      // read the temp value of the sensor:
      int (sht31.getTemperature_C()); Serial.print(" *C\t");

			// ----------------------------------
      // if the temp  value is high enough, turn on the air conditioner:
      if (sht31.getTemperature_C() > 23.8) {
        digitalWrite(4, HIGH);
      } else {
        digitalWrite(4, LOW);
      }
			// ----------------------------------
      // if the temp  value is low enough, turn on the heater:
      if (sht31.getTemperature_C() < 22.2) {
        digitalWrite(5, HIGH);
      } else {
        digitalWrite(5, LOW);
      }
    }
		// ----------------------------------
			// *** AWK! - as follows --
    { // <<-- where's the IF for this block ?
      // read the % humidity value of the sensor:
      int (sht31.getHumidity()); Serial.print(" %\t\t");

			// ----------------------------------
      // if the temp  value is high enough, turn on the dehumidifier:
      // value based on 23 C median temp minus 2.8 C for inner leaf temp for evaporative cooling:
      if (sht31.getHumidity() > 58) {
        digitalWrite(13, HIGH);
      } else {
        digitalWrite(13, LOW);
      }
			// ----------------------------------
      // if the temp  value is low enough, turn on the humidifier:
      // value based on 23 C median temp minus 2.8 C for inner leaf temp for evaporative cooling:
      if (sht31.getHumidity() < 56) {
        digitalWrite(15, HIGH);
      } else {
        digitalWrite(15, LOW);
      }
		// ----------------------------------
    } else {
      //code here for the rest of the day
      //NIGHT CONDITIONS / LIGHTS OFF
      // read the temp value of the sensor:
      int (sht31.getTemperature_C()); Serial.print(" *C\t");

			// ----------------------------------
      // if the temp  value is high enough, turn on the air conditioner:
      if (sht31.getTemperature_C() > 23.8) {
        digitalWrite(4, HIGH);
      } else {
        digitalWrite(4, LOW);
      }
			// ----------------------------------
      // if the temp  value is low enough, turn on the heater:
      if (sht31.getTemperature_C() < 22.2) {
        digitalWrite(5, HIGH);
      } else {
        digitalWrite(5, LOW);
      }
    }

		// ----------------------------------
    // read the % humidity value of the sensor:
    int (sht31.getHumidity()); Serial.print(" %\t\t");

		// ----------------------------------
    // if the temp  value is high enough, turn on the dehumidifier:
    // value based on 23 C median temp minus 2.8 C for inner leaf temp for evaporative cooling:
    if (sht31.getHumidity() > 58) {
      digitalWrite(13, HIGH);
    } else {
      digitalWrite(13, LOW);
    }
		// ----------------------------------
    // if the temp  value is low enough, turn on the humidifier:
    // value based on 23 C median temp minus 2.8 C for inner leaf temp for evaporative cooling:
    if (sht31.getHumidity() < 56) {
      digitalWrite(15, HIGH);
    } else {
      digitalWrite(15, LOW);
    }
		// } // unnecessary

Enjoy & grow!

@DrAzzy Perfect, I had to do some bracket rearranging but indeed that fixed it, and totally makes sense as to why it didn't work (which is what allowed me to arrange a few extra brackets than what you mentioned). Thank you!

I'll try formatting differently in the future, funnily enough I was doing that because someone indicated that's the "proper" way of doing it, but it didn't serve me well here so will certainly give your way a shot.

@lastchancename And thank you for that very detailed markup!

I'm having a different problem now, same code - now Line 7, which is simply

const char *ssid     = "YOUR_SSID";
const char *password = "YOUR_PASS";

Is giving me the following error:

'const char* ssid' previously defined here

That's the short version, but the code repeats for basically everything defined prior to "void.setup"; the cactus.io, constant char *password, etc.

I've read online this can be caused by creating backup copies of your .ino file (which I did), so I tried removing those from the Arduino folder but still experiencing the issue. Any recommendations?

Looks like just this and another few small errors to fix and it'll be ready to go; thanks again for your help and for everyone who has posted in other topics, really been a huge help.

To ignore most of this thread...
When I want to ‘backup’ an INO file within the same sketch folder structure, I simply rename the copy as .INOx so the compiler doesn’t try to scan it during compilation.
Arduino sketch folders are scanned by the IDE - and scoops up all INI and C files without being asked to.
Just make sure there aren’t any that you’re not using in the folder tree with your primary sketch file.

7101334:
Is giving me the following error:

'const char* ssid' previously defined here

You omitted a bunch of useful information from the error message. Please post the full error output.