This project provides a comprehensive module to manage Wi-Fi connections, system state, and network configurations on an ESP32 microcontroller. It supports a variety of Wi-Fi modes and functionalities, such as connecting to existing networks, creating Access Points (AP), enabling Network Address Translation (NAT) for bridge/repeater mode, and managing system configurations persistently.
- Wi-Fi Station Mode: Connect to existing Wi-Fi networks.
- Access Point Mode: Set up a secured Wi-Fi network with WPA2.
- Bridge/Repeater Mode: Create an Access Point while connecting to another Wi-Fi network using NAT.
- System State Management: Persist system states (e.g., online, offline) to configuration files.
- Encrypted Configuration: Secure sensitive data using AES encryption.
- LED Status Indication: Visual feedback for system states (e.g., idle, connected, error).
- Error Handling: Custom exception handling for Wi-Fi connection errors.
- User Input Masking: Securely mask input for sensitive data, such as passwords.
- Clone this repository onto your ESP32 file system.
- Ensure all dependencies are installed (see Dependencies).
- Upload the files to the ESP32 using a compatible IDE (e.g., Thonny, uPyCraft, or rshell).
- Connect to the ESP32 via a serial terminal to interact with the system.
-
Run the script:
import main asyncio.run(main.main_menu())
-
Use the interactive menu to perform actions:
1
: Connect to a pre-configured home network.2
: Scan and connect to available networks.3
: Switch to offline mode.4
: Check Wi-Fi status.5
: Start an Access Point.6
: Stop the Access Point.7
: Start Bridge/Repeater mode.8
: Exit the program.
- Connect to existing Wi-Fi networks using the
connect_to_home
orscan_and_connect
functions. - Persistent configuration files store network details securely using AES encryption.
- Create a secure Wi-Fi network using WPA2.
- Configure the SSID, password, and channel.
- View the Access Point's IP configuration.
- Simultaneously connect to a Wi-Fi network and create an AP for devices to share the connection.
- Enable Network Address Translation (NAT) to bridge devices to the internet.
- Save system states (e.g.,
online
,offline
) to a JSON configuration file. - Automatically restore the last saved state on startup.
- Use AES encryption for sensitive data such as Wi-Fi passwords.
- Securely decrypt configurations on demand using a master passphrase.
- Indicate system states visually with an onboard LED:
Idle
: Blink at 0.25-second intervals.Connected
: Blink at 1-second intervals.Error
: Quick triple blinks.
Stores system states persistently:
{
"state": "offline"
}
Encrypted file storing sensitive AES keys. Ensure this file is protected.
Encrypted Wi-Fi configuration file:
SSID=YourWiFiNetwork
PASSWORD=YourPassword
This module uses the following libraries:
uasyncio
: Asynchronous I/O for multitasking.network
: Wi-Fi network interface.machine
: Hardware control interface for the ESP32.ucryptolib
: AES encryption for sensitive data.ujson
: Lightweight JSON parsing for configurations.
Ensure these dependencies are available in your ESP32 MicroPython firmware. Update your firmware if required.
After running the module, you’ll see the following menu:
Main Menu:
1: Connect to home network
2: Scan and connect to a network
3: Start offline mode
4: Check Wi-Fi status
5: Start Access Point mode
6: Stop Access Point
7: Start Bridge/Repeater mode
8: Exit Program
Choose an option:
- Select option
1
. - Enter the master passphrase to unlock your encrypted configuration.
- The system connects to the stored Wi-Fi SSID and displays its IP configuration.
Contributions are welcome! Please follow these steps:
-
Fork the repository.
-
Create a feature branch:
git checkout -b feature-name
-
Commit your changes:
git commit -m "Add a new feature"
-
Push the branch:
git push origin feature-name
-
Submit a pull request.
This project is licensed under the MIT License. See the LICENSE
file for details.