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

ESP32-C3 Mini Development Board not able to connect to WiFi #780

Open
fbernaly opened this issue Feb 21, 2024 · 1 comment
Open

ESP32-C3 Mini Development Board not able to connect to WiFi #780

fbernaly opened this issue Feb 21, 2024 · 1 comment

Comments

@fbernaly
Copy link

fbernaly commented Feb 21, 2024

First, thank you very much for this plugin. Now I can create my own Homekit compatible devices without the the of Homebridge. It is very nice how this plugin lets me to use ESP32 and connect directly to Homekit without the of a 3rd party bridge.

I am working on this home project to control my son's beside led strip light with ESP32.

I prototyped it using ESP32-WROOM-32, but I do not need that many GPIO and want to use a smaller ESP32 and I went with the ESP32-C3 Mini Development Board (aka ESP32-C3-Zero) by waveshare. It is a very tiny dev board that suit my needs.

However, I found that there is an issue with the ESP32-C3-Zero, it does not connect to WiFi, this is what I get in the logs:

11:35:18.383 -> Accessory configuration has changed.  Updating configuration number to 2
11:35:18.383 -> 
11:35:18.383 -> esp32-lighting is READY!
11:35:18.383 -> 
11:35:18.383 -> Trying to connect to SSID.  Waiting 1 sec...
11:35:19.415 -> Trying to connect to SSID.  Waiting 2 sec...
11:35:19.415 -> E (4395) wifi:sta is connecting, return error
11:35:21.447 -> Trying to connect to SSID.  Waiting 4 sec...
11:35:25.434 -> Trying to connect to SSID.  Waiting 8 sec...
11:35:33.419 -> Trying to connect to NETGEAR54.  Waiting 16 sec...
11:35:49.426 -> 
11:35:49.426 -> *** Can't connect to SSID.  You may type 'W <return>' to re-configure WiFi, or 'X <return>' to erase WiFi credentials.  Will try connecting again in 60 seconds.
11:35:49.426 -> 

It connects only if I add this line after WiFi.begin():

WiFi.begin(ssid, password);
WiFi.setTxPower(WIFI_POWER_8_5dBm); // <- need to add this line

I found that workaround in this thread.

Since HomeSpan sets the WiFi credentials using CLI. I have found no way to set WiFi.setTxPower other than with this workaround: call both WiFi.begin and WiFi.setTxPower in my setup() like this:

#define LED_PIN 1
#define PUSH_BUTTON_PIN 2

const char* ssid = "<YOUR_SSID>";
const char* password = "<YOUR_PASSWORD>";

void connectToWifi() {
  WiFi.begin(ssid, password);
  WiFi.setTxPower(WIFI_POWER_8_5dBm); // <-- This is the important line
  Serial.print("Connecting to WiFi");
  int i = 0;
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    digitalWrite(LED_PIN, (i++) % 2);
    delay(50);
  }
  digitalWrite(LED_PIN, LOW);
  Serial.print("\nConnected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());
}

void setup() {
  Serial.begin(115200);

  connectToWifi();

  ... // the rest of my stuff
}

void loop() {
  homeSpan.poll();  // run HomeSpan!
}

When I do this it connects to the WiFi. But I need to set WiFi credential in both CLI and inside the setup() method. Is there a more elegant way to tackle this? How can I edit the CLI command to set WiFi.setTxPower(WIFI_POWER_8_5dBm) as well?

@frankonski
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants