Skip to content

Lightweight, modular and non-blocking WiFi Station manager for ESP32-C6 using Arduino IDE. Focused on STA-only functionality, event-driven reconnect/backoff, flash-stored (PROGMEM) translations and multi-level logging — easy to embed in sketches without packaging as a library.

License

Notifications You must be signed in to change notification settings

DenizOner/WiFi_STA-Module-for-ESP32

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

wifi_sta — Non-blocking WiFi STA module (ESP32-C6, Arduino IDE)

Purpose:
A small, modular, non-blocking WiFi Station (STA) manager for ESP32 devices (tested on ESP32-C6 with Arduino IDE 2.3.6).
Focus: single responsibility — WiFi STA only. No AP / OTA / MQTT included. All user-visible strings live in PROGMEM for RAM saving and easy localization.


Repository layout (how you should place files)

/YourSketchFolder/
  main.ino
  /wifi_sta/
    secrets.h
    wifi_config.h
    strings.h
    logger.h
    logger.cpp
    wifi_module.h
    wifi_module.cpp
    wifi_sta_sources.h

Important: secrets.h must remain private (do not commit). See .gitignore example below.


Quick start (copy & paste)

  1. Copy the wifi_sta directory into the same folder where your main.ino sits.
  2. Edit wifi_sta/secrets.h and fill in SECRETS_WIFI_SSID and SECRETS_WIFI_PASSWORD.
  3. Add /wifi_sta/secrets.h to .gitignore.
  4. In main.ino, include headers in this order (header then wrapper):
#include <Arduino.h>
#include "wifi_sta/wifi_module.h"
// Force compilation of .cpp sources inside wifi_sta subfolder
#include "wifi_sta/wifi_sta_sources.h"

void setup() {
  Serial.begin(115200);
  delay(50); // give Serial time to spin up

  // Optional runtime overrides
  WifiModule::setLogLevel(LOG_LEVEL_DEBUG);
  WifiModule::setLanguage(LANG_EN);

  // Initialize module (register events). This does NOT enable the radio.
  WifiModule::begin();

  // Enable radio and start non-blocking connection attempts
  WifiModule::enable();
}

void loop() {
  WifiModule::loop();
  // your non-blocking code...
  delay(10);
}

Order matters: include wifi_module.h before wifi_sta_sources.h. The wrapper forces Arduino IDE to compile .cpp files located in the subfolder.


API overview

  • WifiModule::begin() — Initialize module (register event handlers). Radio remains OFF.
  • WifiModule::enable() — Turn radio ON and start non-blocking connect attempts.
  • WifiModule::disable() — Power radio OFF and forget network (non-blocking).
  • WifiModule::loop() — Must be called frequently from your loop(); runs timers and reconnect logic.
  • WifiModule::isEnabled() / WifiModule::isConnected() — status queries.
  • WifiModule::getIP() / WifiModule::getRSSI() — diagnostics.
  • WifiModule::requestReconnectNow() / WifiModule::forceDisconnect() — manual controls.
  • WifiModule::setLanguage(Language lang) — set LANG_EN / LANG_TR.
  • WifiModule::setLogLevel(LogLevel level) — set log verbosity (TRACE .. FATAL).

Strings & localization

  • All user-facing messages live in strings.h and are stored in PROGMEM.
  • Logger reads templates from PROGMEM, copies to RAM, runs vsnprintf() and then writes to Serial.
  • English and Turkish translations are included. Add more languages by following the strings.h pattern.

Logging

  • Levels: TRACE, DEBUG, INFO, WARN, ERROR, FATAL (most verbose → least).
  • Example: WifiModule::setLogLevel(LOG_LEVEL_DEBUG);
  • Output format: [LEVEL] message

Secrets / Security

wifi_sta/secrets.h (example — DO NOT commit):

#ifndef WIFI_SECRETS_H
#define WIFI_SECRETS_H
#define SECRETS_WIFI_SSID       "your-ssid"
#define SECRETS_WIFI_PASSWORD   "your-password"
#endif // WIFI_SECRETS_H

Add to .gitignore:

/wifi_sta/secrets.h

Arduino IDE notes & compatibility

  • Tested with Arduino IDE 2.3.6 and ESP32-C6 support.
  • Event registration uses WiFi.onEvent([](auto ev, auto info){...}); for cross-core compatibility.
  • Arduino IDE sometimes ignores .cpp files in subfolders — wifi_sta_sources.h includes the module .cpp files to ensure they get compiled without making an Arduino library. This keeps your layout simple and avoids library packaging if you prefer that.

Troubleshooting: common build/link errors

  • undefined reference to 'WifiModule::...'

    • Ensure #include "wifi_sta/wifi_sta_sources.h" is present after wifi_module.h in main.ino.
    • Ensure all .cpp files are present inside wifi_sta folder and spelled correctly.
  • PROGMEM weirdness / garbled strings

    • Confirm strings.h uses pgmspace.h and that fetchMessageTemplate() is used by the logger to copy templates into RAM before formatting.

Where to publish — Repo vs Gist?

  • Use a GitHub repository. This project contains multiple files, a README, and usage examples — repo gives versioning, issues, PRs, releases, and easier future conversion to a real Arduino Library.
  • Gist is fine only for single-file snippets or tiny examples.

License suggestion

  • MIT is recommended for permissive reuse. Add LICENSE to the repo if you choose MIT.

Next steps

  • Convert to a proper Arduino library (library.properties) if you want to install via the IDE.
  • Add additional languages and unit tests for strings.h / PROGMEM fetch.
  • Optional non-blocking health check (async HTTP/TCP) as a separate module that uses this WiFi STA module.

About

Lightweight, modular and non-blocking WiFi Station manager for ESP32-C6 using Arduino IDE. Focused on STA-only functionality, event-driven reconnect/backoff, flash-stored (PROGMEM) translations and multi-level logging — easy to embed in sketches without packaging as a library.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published