Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Issue with a connection MQTT over TLS with Ethernet W5500 #98

Open
1 of 2 tasks
MaxiLargo opened this issue Jul 22, 2024 · 4 comments
Open
1 of 2 tasks

Issue with a connection MQTT over TLS with Ethernet W5500 #98

MaxiLargo opened this issue Jul 22, 2024 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@MaxiLargo
Copy link

Description

Steps to Reproduce

boolean reconnect() {
  chipId = ESP.getEfuseMac();
  char chipIdString[18];  
  snprintf(chipIdString, sizeof(chipIdString), "%04X%08X", (uint16_t)(chipId >> 32), (uint32_t)chipId);

  if (client.connect(chipIdString, mqtt_username, mqtt_password)) {
    client.publish("test", message.c_str());
    conectado.store(true);
  }
  return client.connected();
}

void mqttTask(void* param) {
  while (1) {

unsigned long cu = millis();

if (cu - lastReconnectAttempt >= 60000) {
 
    String message = "....";

    if (!client.connected()) {
        reconnect();
      }else {
        client.loop();
    }


  }

  unsigned int highWaterMark = uxTaskGetStackHighWaterMark(NULL);
  Serial.print(highWaterMark);

  lastReconnectAttempt = cu;
}
  vTaskDelay(pdMS_TO_TICKS(60000));
}
}



static const char* root_ca PROGMEM = R"EOF(
...
)EOF";

EthernetClient ethclient;
SSLClient seceth(&ethclient);
PubSubClient client(seceth);


void setup() {
  WiFi.mode(WIFI_STA); 
  Serial.begin(115200);
  disableCore0WDT();
  disableCore1WDT();
  M5.begin();        
  M5.Power.begin();
    
  uint64_t chipId1 = 0;
  chipId1 = ESP.getEfuseMac();

  char chipIdString[18];
  snprintf(chipIdString, sizeof(chipIdString), "%04X%08X", (uint16_t)(chipId1 >> 32), (uint32_t)chipId1);
  Serial.print(chipIdString);
  String ssid = "indulink" + String(chipIdString);
  
  if (!SD.begin()) {
        M5.Lcd.println("Card failed, or not present");
        while (1);
    }
    M5.Lcd.println("TF card initialized.");

    while (!module.begin(&Wire, 21, 22, MODULE_4IN8OUT_ADDR)) {
        Serial.println("4IN8OUT INIT ERROR");
        M5.Lcd.println("4IN8OUT INIT ERROR");
    }
    
    Serial.println("4IN8OUT INIT SUCCESS");


    M5.Lcd.println("Contador de pulsos iniciado.");

  SPI.begin(SCK, MISO, MOSI, -1);
  Ethernet.init(CS);
    while (!Serial) { }

  Ethernet.begin(mac);
  Serial.print("Ethernet iniciado. Dirección IP: ");
  Serial.println(Ethernet.localIP());
  timeClient.begin();
  timeClient.update();
  seceth.setCACert(root_ca);

  client.setServer(mqtt_server, mqtt_port);
  client.setCallback(callback);
  Reinicio.attach(2,reinicio);

  xTaskCreatePinnedToCore(
    mqttTask,    
    "mqttTask",  
    8192,         
    NULL,
    1, 
    NULL,
    0   
  );
  xTaskCreatePinnedToCore(
    countTask,   
    "countTask", 
    8192,       
    NULL,
    1,  
    NULL,
    1   
  );
}

Expected Behavior

Publish a variable in a broker mqtt over tls with ethernet

Actual Behavior

when the mqtt task run, this error appears

[ 62514][E][ssl__client.cpp:42] _handle_error(): [start_ssl_client():367]: (-1) ERROR - Generic error
[ 62515][E][SSLClient.cpp:242] connect(): start_ssl_client failed: 0

Environment

  • Operating System: [Windows 10 Home]
  • Version: [22H2]

IDE

  • Arduino IDE
  • PlatformIO IDE extension

Additional Context

It is a very big program, try to show the functions that are used by the mqtt task

@RobertByrnes
Copy link
Collaborator

RobertByrnes commented Jul 26, 2024

Hi @MaxiLargo Have you got anywhere with this?

  1. Be good to see the output when log level set to debug.
  2. Have you set the flag for the W5500 #define W5500_WORKAROUND . It is recommended.

Ensure you are the latest version of this lib 1.3.1.

@RobertByrnes RobertByrnes added the help wanted Extra attention is needed label Jul 26, 2024
@MaxiLargo
Copy link
Author

Hi @RobertByrnes!
I try to set the debug level (seceth.setDebugStream(&Serial)) but it doesn't work. And yes, I have the flag #define W5500_WORKAROUND and also I tried with #define _W5500_H_ but it is the same result, i have the last version of the lib.

If you can help me I would appreciate it

@RobertByrnes
Copy link
Collaborator

ok @MaxiLargo can you share a longer excerpt from log file that shows the entire connection process leading up o these 2 errors:

[ 62514][E][ssl__client.cpp:42] _handle_error(): [start_ssl_client():367]: (-1) ERROR - Generic error
[ 62515][E][SSLClient.cpp:242] connect(): start_ssl_client failed: 0

@MaxiLargo
Copy link
Author

Here it's the log:

entry 0x400805f0
[ M5Stack initializing...
OK
[ 410][I][esp32-hal-i2c.c:75] i2cInit(): Initialising I2C Master: sda=21 scl=22 freq=100000
Ethernet init.IP: 192.168.0.106
C88CA51FB6084IN8OUT INIT SUCCESS
[ 2112][E][ssl__client.cpp:45] _handle_error(): [start_ssl_client():370]: (-1) ERROR - Generic error
[ 2112][E][SSLClient.cpp:242] connect(): start_ssl_client failed: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants