Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Webserver and WiFiClientSecure (SMTP SSL) fatal error 29 #2837

Closed
Marius58 opened this issue Jan 6, 2017 · 5 comments
Closed

Webserver and WiFiClientSecure (SMTP SSL) fatal error 29 #2837

Marius58 opened this issue Jan 6, 2017 · 5 comments

Comments

@Marius58
Copy link

Marius58 commented Jan 6, 2017

Please fill the info fields, it helps to get you faster support ;)

if you have a stack dump decode it:
https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/stack_dump.md

SORRY THE DECODER DOES NOT WORK

Exception (29):
epc1=0x4023eb0b epc2=0x00000000 epc3=0x00000000 excvaddr=0x0000000c depc=0x00000000

ctx: cont
sp: 3fff23f0 end: 3fff2c20 offset: 01a0

stack>>>
3fff2590: 3fffb4c0 00000044 3fff29a4 4023eb08
3fff25a0: 00000100 00000100 3fffb6a4 4023f043
3fff25b0: 3fffb4c0 00000100 3fffb18c 40240943
3fff25c0: 3fffb6a4 3fff4444 00000003 402445df
3fff25d0: 3fff1ba8 00000200 00000200 00000000
3fff25e0: 00000100 3fff984e 3fff29a4 40244aec
3fff25f0: 3fff4444 3fffb6a4 3fff29a4 4024497c
3fff2600: 3fffb494 00000026 3fff29a4 4024481c
3fff2610: 00000000 0000003c 3fff984e 00000004
3fff2620: 00000000 3fffb494 3fff984e 4023d78c
3fff2630: 00000288 00000000 65b62cea d20baa30
3fff2640: a9a9f21a f25aff4c aaab75b3 90598882
3fff2650: 42a9754c 8d118b03 556c751f 93f12f84
3fff2660: 47cc899b a8bc35e4 00000080 00000000
3fff2670: 00000000 00000000 00000000 00000000
3fff2680: 00000000 00000000 00000000 00000000
3fff2690: 00000000 80260000 feefeffe feefeffe
3fff26a0: feefeffe feefeffe feefeffe feefeffe
3fff26b0: feefeffe feefeffe feefeffe feefeffe
3fff26c0: feefeffe feefeffe feefeffe feefeffe
3fff26d0: feefeffe feefeffe feefeffe feefeffe
3fff26e0: feefeffe feefeffe feefeffe feefeffe
3fff26f0: feefeffe feefeffe feefeffe feefeffe
3fff2700: feefeffe feefeffe feefeffe feefeffe
3fff2710: feefeffe feefeffe feefeffe feefeffe
3fff2720: feefeffe feefeffe feefeffe feefeffe
3fff2730: feefeffe feefeffe feefeffe feefeffe
3fff2740: feefeffe feefeffe feefeffe feefeffe
3fff2750: feefeffe feefeffe feefeffe feefeffe
3fff2760: feefeffe feefeffe feefeffe feefeffe
3fff2770: feefeffe feefeffe feefeffe feefeffe
3fff2780: feefeffe feefeffe feefeffe feefeffe
3fff2790: feefeffe feefeffe feefeffe 40310000
3fff27a0: 00000001 0000001c 3ffe82f4 401004f4
3fff27b0: feefeffe 00000002 3ffe82f4 402017e4
3fff27c0: 00000046 40348000 00000000 4021698e
3fff27d0: 00000008 00000000 00000020 40100ece
3fff27e0: 3ffeb518 40100b79 00000002 00000100
3fff27f0: 00000005 00000008 40100a2e 00000002
3fff2800: 00000002 4010082f 00000002 3ffef660
3fff2810: 00000001 00000000 00000020 40100ece
3fff2820: 00000005 00000000 00000020 40100ece
3fff2830: 3ffeb515 401041ab 3ffeefa0 00000000
3fff2840: 40101be1 3ffeefa0 00000000 00000002
3fff2850: 00007fff 044dd1d1 3ffef9c8 40101d70
3fff2860: 3ffebd9c 00000000 00000000 00000002
3fff2870: 00000000 044dd1d1 401021ae 00000100
3fff2880: 7fffffff 3ffebd9c 3ffebd9c 00000001
3fff2890: 00000005 00000000 00000020 40100ece
3fff28a0: 3ffeb515 401041ab 3ffeef50 4000050c
3fff28b0: 00000000 00000000 0000001f 40104cad
3fff28c0: 4000050c 044dd8a0 3ffef9c8 40101d70
3fff28d0: 40242cc9 00000030 00000019 ffffffff
3fff28e0: 40243a9c 0cf2f005 dd9e0761 a89e7050
3fff28f0: d50cd43a b0c536e5 e0761dd9 93cb4680
3fff2900: cfbcac30 f737ad03 b6af3b12 9a70c509
3fff2910: a5e74ae4 00000000 00000000 00000000
3fff2920: 00000000 00000000 00000000 00000000
3fff2930: 00000000 00000000 00000000 00000000
3fff2940: 00000000 00000000 00000000 00000000
3fff2950: 00000000 00000000 00000000 00000000
3fff2960: ea2cb665 30aa0bd2 1af2a9a9 4cff5af2
3fff2970: b375abaa 82885990 4c75a942 038b118d
3fff2980: 3ffeb2c1 00000000 00000001 00000030
3fff2990: b88e96d8 e0e0fa05 ceead7ba bd1874c2
3fff29a0: 0000053c 000002c1 00000428 ea0e3082
3fff29b0: 3fff4d30 00000288 00000001 00000000
3fff29c0: 00000000 a97416b5 8e65017c 3fff9259
3fff29d0: 0000100b 0000000c 00000003 3fff9259
3fff29e0: 3fff4d30 00000001 000005f5 4023baf1
3fff29f0: 00001004 0000100b 3fff4d2c 3fff4504
3fff2a00: 3fff7e34 00000007 00860011 3fff7e88
3fff2a10: 0000053c 99d9b942 35950480 b2f11879
3fff2a20: 47d67a5b 3fff7254 f32e1730 3fff9259
3fff2a30: 0000100b 0000100b 3fff7e34 4023ce99
3fff2a40: 7876dcc6 ec8729df 79b8777c 0923c6ba
3fff2a50: db15d5d9 5d5e9354 3fff1c00 00000000
3fff2a60: 0000003e 3fffa24c 3fffa24c 3fff7254
3fff2a70: 00000000 00000f98 00000064 402109b4
3fff2a80: 0000004a 00000000 0000000d 3fff9259
3fff2a90: 3fff9259 0000100b 3fff7e34 3fff9259
3fff2aa0: 0000100b 0000100b 3fff7e34 4023c972
3fff2ab0: 00000043 00000016 3fff7e34 40201795
3fff2ac0: 5992ef2f 3fff69bc 00000000 00000000
3fff2ad0: 3fff2b20 0000000b 00000010 4023ccbb
3fff2ae0: 3fff69bc 3fff4344 3fff7e34 01000000
3fff2af0: 3fff2b20 3fff2b8c 3fff7e34 4023cad8
3fff2b00: 4020b1a4 00000000 3fff5e4c 00001387
3fff2b10: 000119ec 3fff2b8c 3fff5e4c 4020b6f0
3fff2b20: 000001d1 3fff5064 3fff2b8c 4020aa1a
3fff2b30: 4016fcc1 00000378 00000378 3fff0e28
3fff2b40: 000001d1 3fff2b8c 3fff4344 4020b8b1
3fff2b50: 3ffea428 4016fcc1 3ffea428 4016fcc1
3fff2b60: 3ffeae1c 3fff0e10 3ffe8568 402094e5
3fff2b70: 00000020 3fff2bd0 3fff2bd0 402100d7
3fff2b80: 00000018 00000001 3fff2bd0 3ffe9c18
3fff2b90: 00000000 000003e8 00000443 3fff0f3c
3fff2ba0: 3fff6914 3fff5e4c 3fff2bd0 4010068c
3fff2bb0: 3ffeae1c 3fff0e10 3fff0d98 3fff0e28
3fff2bc0: 3ffeae1c 3fff0e10 3ffe8568 402097eb
3fff2bd0: 00000000 00000000 00000000 4020f73c
3fff2be0: 3fffdad0 00000003 3fff186c 3fff1bf4
3fff2bf0: 3fffdad0 00000003 3fff187a 40209f20
3fff2c00: 3fffdad0 00000000 3fff1bed 40210988
3fff2c10: feefeffe feefeffe 3fff1c00 40100718
<<<stack<<<

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v00000000
~ld

for better debug messages:
https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/debugging.md

----------------------------- Remove above -----------------------------

Basic Infos

Hardware

Hardware: Wemos D1 R2 Mini
Core Version: ?2.1.0-rc2?

Description

Problem description

Hello everybody,
For some months I am working on an home automation project.
The application is a classical web server with a main page and configuration pages.
All pages are send in chunk mode.
Until now things are going well
I decided to improve the application by adding email notifications based on some events.
I have developed and tested two email functions outside of my application.
One function is normal email and the other is secure SSL function. Both are working perfectly in the test application.
I have integrated the email functions in my main application. Depending on the
configuration I chose for example smtp port 25 not secure or smtp port 465 SSL (to use Gmail) I can select standard or the secured email function.
I call the email function in the Arduino loop() function.
With the standard function (WiFiClient client) everything works correctly.
I have a problem with Secure SSL (WiFiClientSecure client).
Every time I make a request on the Web server the following email sending causes a fatal error.

  • When an email is sent in setup () function it works good.
  • Several emails can be sent at intervals of one minute for example if nobody makes a request to the web server.
  • This suggests that a web server request breaks the WiFiClientSecure function or makes a memory confict.

Any idea ?

Settings in IDE

Arduino IDE 1.6.9
ESP8266 core for Arduino Date: 2016, Nov 14
ESP8266 board Wemos D1 Mini

Module: Wemos D1 R2 Mini

Flash Size: 4MB/3MB
CPU Frequency: 80Mhz
Flash Mode: ?qio?
Flash Frequency: ?40Mhz?
Upload Using: SERIAL
Reset Method: ?ck / nodemcu?

Sketch (SIMPLIFIED and REDUCED )

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <TimeLib.h>
#include <EEPROM.h>
#include <rBase64.h>
#include <OneWire.h>

MDNSResponder mdns;

// Declarations ...
// Variables ...

ESP8266WebServer server(80);

// SendMail  **********************************************************
// Receiver are defined before ...
// Message depending from msgcod
// NORMAL / SSL and PORT defined before ...

void SendMail(byte msgcod)
{
  if (msgcod==0x80) msg_txt=(F("Message .....\r\n"));
  if (msgcod==0x40) msg_txt=(F("System boot\r\n"));
  if (msgcod==0x10) msg_txt=(F("Température alarm\r\n"));
  if (msgcod==0x08) msg_txt=(F("Message .....\r\n"));
  
  if ((Val_Port & 0x0F) == 0) Val_SMTP = 25;
  if ((Val_Port & 0x0F) == 1) Val_SMTP = 587;
  if ((Val_Port & 0x0F) == 2) Val_SMTP = 465;

  from_email = F("MAIL FROM:<");
  from_email += Mes_Expe+">";
  to_email0 = F("RCPT TO:<");
  to_email0 += Mes_Dst1+">";
  to_email1 = F("RCPT TO:<");
  to_email1 += Mes_Dst2+">";
  to_email2 = F("RCPT TO:<email@prov.fr>");
  
  msg_subj = F("Subject: ");
  msg_subj += Mes_Tit0+"\r\n";
  
  msg_to  = F("To: <");
  msg_to += Mes_Dst1;
  msg_to += F(">");
  if (Mes_Dst2!="") msg_to += F(", <");
  if (Mes_Dst2!="") msg_to += Mes_Dst2;
  if (Mes_Dst2!="") msg_to += F(">");
  msg_to += F("\r\n");

  msg_from = "From: <"+Mes_Expe+">\r\n";

  Mail_f = 0;

  if (Val_Port == 32 || Val_Port == 33 || Val_Port == 81) Mail_f=sendEmailNor();		// NORMAL case

  if (Val_Port == 34 || Val_Port == 66) Mail_f=sendEmailSec();	// SECURED SSL case
}


// SendMail NOR **********************************************************
byte sendEmailNor() //sending email function
{
  WiFiClient client;
  if (client.connect(Mes_SMTP.c_str(), Val_SMTP) == 1) {
    Serial.println(F("connected"));
  } else {
    Serial.println(F("connection failed"));
    return 0;
  }
  if (!eRcv(client)) return 0;
  Serial.println(F("-- Sending EHLO")); client.println("EHLO 1.2.3.4"); if (!eRcv(client)) return 0;

  if ((Val_Port & 0x0F) != 0) Serial.println(F("-- Send login")); client.println("AUTH LOGIN"); if (!eRcv(client)) return 0;
  if ((Val_Port & 0x0F) != 0) Serial.println(F("-- Send IDb64")); client.println(rbase64.encode(Mes_STID)); if (!eRcv(client)) return 0;
  if ((Val_Port & 0x0F) != 0) Serial.println(F("-- Send PWb64")); client.println(rbase64.encode(Mes_STPW)); if (!eRcv(client)) return 0;

  Serial.println(F("-- Send From")); client.println(from_email); if (!eRcv(client)) return 0;
  Serial.println(F("-- Send To_1")); client.println(to_email0); if (!eRcv(client)) return 0;
  Serial.println(F("-- Send To_2")); client.println(to_email1); if (!eRcv(client)) return 0;
  Serial.println(F("-- Send To_3")); client.println(to_email2); if (!eRcv(client)) return 0;
  Serial.println(F("-- Send DATA")); client.println(F("DATA")); if (!eRcv(client)) return 0;

  client.print(F("Content-Type: text/plain; charset=\"UTF-8\"\r\n"));
  client.print(F("MIME-Version: 1.0\r\n"));
  client.print(F("Content-Transfer-Encoding: 8bit\r\n"));

  client.print(msg_subj);
  client.print(msg_to);
  client.println(msg_from);
  client.print(msg_txt);
  client.println(F(".")); if (!eRcv(client)) return 0;

  Serial.println(F("-- Sending QUIT")); client.println(F("QUIT")); if (!eRcv(client)) return 0;
  client.stop();
  Serial.println(F("disconnected"));
  return 1;
}
// eRcv NOR **********************************************************
byte eRcv(WiFiClient client)
{
  byte respCode;
  byte thisByte;
  int loopCount = 0;
  while (!client.available()) {
    delay(1);
    loopCount++;
    if (loopCount > 10000) {        // if nothing received for 10 seconds, timeout
      client.stop();
      Serial.println(F("\r\nTimeout"));
      return 0;
    }
  }
  respCode = client.peek();
  while (client.available())
  {
    thisByte = client.read();
    Serial.write(thisByte);
  }
  if (respCode >= '4')
  {
  //efail();
  return 0; //  NG
  }
  return 1; //  OK
}
// End NOR mail  *********************************************************

// SendMail SEC **********************************************************
byte sendEmailSec() {  //sending email function

WiFiClientSecure client;
if (client.connect(Mes_SMTP.c_str(), Val_SMTP) == 1) {
    Serial.println(F("connected"));
  } else {
    Serial.println(F("connection failed"));
  client.stop();
    return 0;    // ERROR
  }
  
  Serial.println(F("-- Sending QUIT")); client.println(F("QUIT")); client.stop(); if (!eRcvSec(client)) return 0;
  Serial.println(F("disconnected"));
  return 1;
}
// eRcv SEC **********************************************************
byte eRcvSec(WiFiClientSecure client)
{
  byte respCode;
  byte thisByte;
  int loopCount = 0;
  while (!client.available()) {
    delay(1);
    loopCount++;
    if (loopCount > 10000) {    // if nothing received for 10 seconds, timeout
      client.stop();
      Serial.println(F("\r\nTimeout"));
      return 0;    //  efail();
    }
  }
  respCode = client.peek();
  while (client.available())
  {
    thisByte = client.read();
    Serial.write(thisByte);
  }
  if (respCode >= '4')
  {
  return 0;    //  NG();
  }
  return 1;    //  OK();
}
// End NOR mail  *********************************************************


// ***********************************************************************************
// *ùù                                Create Page SYSTEM html                               *
// ***********************************************************************************
void PageSys() {
	webPage1  = F("<.... HTML PAGE ... 1");
	webPage2  = F("<.... HTML PAGE ... 2");
	webPage3  = F("<.... HTML PAGE ... 3");
	webPage4  = F("<.... HTML PAGE ... 4");
}
  
// ***********************************************************************************
// *ùù                                Create Page MESURE html                               *
// ***********************************************************************************
void PageMesure() {
	webPage1  = F("<.... HTML PAGE ... 1");
	webPage2  = F("<.... HTML PAGE ... 2");
	webPage3  = F("<.... HTML PAGE ... 3");
}

// ***********************************************************************************
// *ùù                                 Create Page CONF html                                *
// ***********************************************************************************
void PageConf() {
	webPage1  = F("<.... HTML PAGE ... 1");
	webPage2  = F("<.... HTML PAGE ... 2");
	webPage3  = F("<.... HTML PAGE ... 3");
	webPage4  = F("<.... HTML PAGE ... 4");
}

// ***********************************************************************************
// *ùù                                 Create Page PROG html                                *
// ***********************************************************************************
void PageProg() {
	webPage1  = F("<.... HTML PAGE ... 1");
	webPage2  = F("<.... HTML PAGE ... 2");
	webPage3  = F("<.... HTML PAGE ... 3");
}

// ***********************************************************************************
// *ùù                                 Create Page MAIN html                                *
// ***********************************************************************************
void PageMain() {
	webPage1  = F("<.... HTML PAGE ... 1");
	webPage2  = F("<.... HTML PAGE ... 2");
	webPage3  = F("<.... HTML PAGE ... 3");
	webPage4  = F("<.... HTML PAGE ... 4");
}

// #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
// #ùù                             void    SETUP                                     #
// #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
void setup(void){
  
// Preparing GPIOs ...
// Definitions ...
// Variables settings from eeprom ...

  Serial.begin(115200);
  delay(1000);

  WiFi.begin(WF_ssid.c_str(), WF_pass.c_str());

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  gateway = WiFi.gatewayIP();   // Cfg Static IP
  subnet = WiFi.subnetMask();
  WiFi.config(ip, gateway, subnet);  

  
  if (mdns.begin("esp8266", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  }

// ***********************************************************************************
// *                                   Page MAIN   App                               *
// ***********************************************************************************
	server.on("/", [](){

// Post datas analysing ...  
	PageMain(); // Create MAIN html page
// Init chunk mode    
	server.sendContent(webPage1);
	server.sendContent(webPage2);
	server.sendContent(webPage3);
	server.sendContent(webPage4);
});
// ***********************************************************************************
// *                                   Page PROG   App                               *
// ***********************************************************************************
	server.on("/prog", [](){

// Post datas analysing ...  
	PageProg(); // Create PROG html page
// Init chunk mode    
	server.sendContent(webPage1);
	server.sendContent(webPage2);
	server.sendContent(webPage3);
});
// ***********************************************************************************
// *                                   Page CONFIG   App                             *
// ***********************************************************************************
	server.on("/config", [](){

// Post datas analysing ...  
	PageConfig(); // Create CONFIG html page
// Init chunk mode    
	server.sendContent(webPage1);
	server.sendContent(webPage2);
	server.sendContent(webPage3);
	server.sendContent(webPage4);
});
// ***********************************************************************************
// *                                 Page MESURE   App                               *
// ***********************************************************************************
	server.on("/mesure", [](){

// Post datas analysing ...  
	PageMesure(); // Create MESURE html page
// Init chunk mode    
	server.sendContent(webPage1);
	server.sendContent(webPage2);
	server.sendContent(webPage3);
});

// ***********************************************************************************
// *                                 Page SYSTEM   App                               *
// ***********************************************************************************
  server.on("/system", [](){

// Post datas analysing ...  
	PageMesure(); // Create MESURE html page
// Init chunk mode    
	server.sendContent(webPage1);
	server.sendContent(webPage2);
	server.sendContent(webPage3);
	server.sendContent(webPage4);
});

// Page SYSTEME end ------------------------------------------------------------------

  server.begin();
  Serial.println("HTTP server started");

  SendMail(0x40); // Système Boot email

}	// End of HTML pages


// #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
// #                                 void    LOOP                                    #
// #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
void loop(void){
  server.handleClient();

// About one seconde delay--------------------------------------------
  if (second()!=SecLast)
    {
		SecLast=second();
		if (Mail_id != 0)
      {
      SendMail(Mail_id); // send email if required
      Mail_id=0;
      }
    }
}
    

Debug Messages

messages here
Thank you for your help.

@Palatis
Copy link
Contributor

Palatis commented Jan 7, 2017

probably out of memory.

axTLS needs 16k ram to run, plus 1.6k buffer for MTU.
and sometimes when changing keys it needs twice as much.

@Marius58
Copy link
Author

Marius58 commented Jan 7, 2017

Hello,
Thank you for your comment.
I suspected a memory problem. But the web server and SSL email each individually working.
Only in the case that the webserser responds to a request the SSL email does not work after this event.

@Palatis
Copy link
Contributor

Palatis commented Jan 7, 2017

yes, because when they work one at the time there isn't as much memory pressure.

@Marius58
Copy link
Author

Marius58 commented Jan 8, 2017

OK,
In this case I have to use only the standard SMTP without SSL which works well.
Thanks.

@devyte
Copy link
Collaborator

devyte commented May 29, 2018

BearSSL is merged in #4273 , with alternate BearSSL::WiFi* classes. Although axtls-based classes are still available and even the default, they are planned for deprecation and then retirement, hence won't be fixed. Any issues with BearSSL-based classes should be reported in new issues.
Closing.

@devyte devyte closed this as completed May 29, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants