Skip to content

ESP32C3 keeps disconnecting #428

Closed
Closed
@mathiskir

Description

@mathiskir

In the log (on sinric.pro) it shows that my esp32 c3 keeps disconnecting and then reconnecting. However the downtimes overweigh the uptimes, is this a known issue? Im using the following code on my esp:

#ifdef ENABLE_DEBUG
   #define DEBUG_ESP_PORT Serial
   #define NODEBUG_WEBSOCKETS
   #define NDEBUG
#endif 

#include <WiFi.h>
#include "SinricPro.h"
#include "SinricProSwitch.h"
#include <RCSwitch.h>

#define WIFI_SSID         ""
#define WIFI_PASS         ""
#define APP_KEY           ""
#define APP_SECRET        ""

#define MHZSIGNAL_ON      21
#define MHZSIGNAL_OFF     20

#define SWITCH_ID_1       ""

#define BAUD_RATE         115200

RCSwitch mhzSwitch = RCSwitch();

bool onPowerState1(const String &deviceId, bool &state) {
 Serial.printf("\n[Device]: Device 1 turned %s", state?"on":"off");
 if(state){
  Serial.println("\n[433 Mhz]: Sende Code " + String(MHZSIGNAL_ON));
  mhzSwitch.send(MHZSIGNAL_ON, 24);
 } else if(!state){
  Serial.println("\n[433 Mhz]: Sende Code " + String(MHZSIGNAL_ON));
  mhzSwitch.send(MHZSIGNAL_OFF, 24);
 }
 return true;
}

void setupWiFi() {
  Serial.printf("\r\n[Wifi]: Connecting");

  #if defined(ESP8266)
    WiFi.setSleepMode(WIFI_NONE_SLEEP); 
    WiFi.setAutoReconnect(true);
  #elif defined(ESP32)
    WiFi.setSleep(false); 
    WiFi.setAutoReconnect(true);
  #endif

  WiFi.begin(WIFI_SSID, WIFI_PASS);

  while (WiFi.status() != WL_CONNECTED) {
    Serial.printf(".");
    delay(250);
  }

  Serial.printf("\n[WiFi]: Connected.\r\n[WiFi]: IP-Address is %s", WiFi.localIP().toString().c_str());
}

void setupSinricPro() {
  SinricProSwitch& virtualSwitch = SinricPro[SWITCH_ID_1];
  virtualSwitch.onPowerState(onPowerState1);
  
  
  SinricPro.onConnected([](){ Serial.printf("\n[Sinric]: Connected to SinricPro"); }); 
  SinricPro.onDisconnected([](){ Serial.printf("\n[Sinric]: Disconnected from SinricPro"); });
  SinricPro.restoreDeviceStates(true);
   
  SinricPro.begin(APP_KEY, APP_SECRET);
}

void setup() {
  Serial.begin(BAUD_RATE); Serial.printf("\r\n");
  setupWiFi();
  setupSinricPro();
  mhzSwitch.enableTransmit(5);
  mhzSwitch.setProtocol(1);
  mhzSwitch.setPulseLength(318);
  mhzSwitch.setRepeatTransmit(10);
}

void loop() {
  SinricPro.handle();
}

let me know if i should enable any debug mode or smth to further assist you with solving this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions