In function 'void loop()': 'xxxx' was not declared in this scope

Hi,

I’ve built a testcode using smtp and it works well.
After moving the code into the main module, I get the ‘sendSMTP’ was not declared in this scope
I can’t figure out what is wrong, can anybody point me in the correct direction / find the issue?

Snippet of the code from void loop () :

void loop() {

/************************************************************************************************************
 ***                                  ACCESS STORED VALUES FROM WEBSERVER                                 ***
 ***********************************************************************************************************/

  String your_ap_ssid = readFile(SPIFFS, "/ap_ssid.txt");
  String your_ap_pwd = readFile(SPIFFS, "/ap_pwd.txt");
  String your_email = readFile(SPIFFS, "/email.txt");
  int your_amount = readFile(SPIFFS, "/amount.txt").toInt();

  
  delay(5000);


/************************************************************************************************************
 ***                              CHECK WEIGHT IF BELOW THRESHOLD AND REPORT                              ***
 ***********************************************************************************************************/
  float weight0 = scale.get_units();
  if (weight0 > THRESHOLD) {
    sendSMTP();

  }

  weight0 = 0;
  scale.power_down();             // put the ADC in sleep mode
  delay(1000);
  scale.power_up();
}


void sendSMTP() {
  smtpData.setLogin(smtpServer, smtpServerPort, emailSenderAccount, emailSenderPassword);                                   
  smtpData.setSTARTTLS(true);
  smtpData.setSender("ESP32", emailSenderAccount);                                                                          
  smtpData.setPriority("High");                                                                                     
  smtpData.setSubject(emailSubject);   
  String espID = String(ESP_getChipId(), HEX);
  espID.toUpperCase();
  Serial.println("ESP ID på denne enheten:");
  Serial.println(espID); 
  float weight1 = scale.get_units();
  char body[2048];
  sprintf***MASKED***);
  smtpData.setMessage(body, true);
  smtpData.addRecipient(emailRecipient);                                                                               
  smtpData.setSendCallback(sendCallback);
  if (!MailClient.sendMail(smtpData))         
    Serial.println("Error sending Email, " + MailClient.smtpErrorReason());
  
}



void sendCallback(SendStatus msg) {                                                                                    
  Serial.println(msg.info());           
  if (msg.success()) {         
    Serial.println("----------------");
  }
}

Are you aware that in 'normal' C/C++ you have to declare functions before first use but in order to simplify things for beginners the Arduino IDE does that for you?

The problem is it doesn't always work properly. Try putting

void sendSMTP();

Right at the top before setup()

For future reference please post all your code not a snippet, often the problem is not in the bit you think it is.

PerryBebbington:
The problem is it doesn't always work properly. Try putting

void sendSMTP();

Right at the top before setup()

For future reference please post all your code not a snippet, often the problem is not in the bit you think it is.

Thank you Perry, you were perfectly right, and no, I didn't know Arduino could fail on this.
And noted regarding the full code :slight_smile:

Perhaps the file isn't a .ino suffix file? The auto-prototype generation is limited to .ino files
if I remember right.