[
](LICENSE)

A secure and modular Arduino library for managing Wi-Fi credentials, designed to prevent accidental exposure of sensitive data when sharing code.
🎯 Primary Purpose
The main objective of this library is simple: to prevent accidental exposure of Wi-Fi credentials when sharing code.
This library provides peace of mind when sharing your Arduino projects. Instead of having your Wi-Fi credentials scattered throughout your code where they might be accidentally committed to version control or shared with others, this library keeps them in a separate, easily manageable file.
How It Works
When you share your code with clients or collaborators, they have two simple options:
- Remove the WiFiCreds library code and manually add their own credentials directly in their code
- Install the library and create their own credentials.h file with their hardcoded credentials (just like you did)
This approach ensures that your sensitive network information never gets exposed, while still providing a clean, professional way to manage credentials in your projects.
Features
- 🔒 Secure Credential Management: Keeps Wi-Fi credentials separate from main code
- 🔑 Multiple Credential Sets: Support for named credential sets (home, office, etc.)
- 🎯 Default Behavior: First credential set is always used as default
- 🔄 Automatic Fallback: Invalid names automatically fall back to default
- 📚 Easy Integration: Simple static methods for accessing credentials
- 🛡️ Validation: Built-in credential validation
- 📖 Well Documented: Comprehensive Doxygen documentation
- 🔧 Modular Design: Easy to extend for different storage methods
- 🎯 Production Ready: Follows Arduino library best practices
Platform Compatibility
The WiFiCreds library is compatible with the following platforms:
- ✅ ESP32: Full support with built-in WiFi capabilities
- ✅ ESP8266: Full support with built-in WiFi capabilities
- ✅ Raspberry Pi Pico W: Full support with built-in WiFi capabilities
- ✅ Arduino R4 WiFi: Full support with built-in WiFi capabilities
- ✅ Arduino + ESP8266-01: Support via SoftwareSerial communication
- ✅ Arduino + ESP8266: Support via ESP8266WiFi library
- ✅ Arduino + ESP32: Support via WiFi library
Installation
Arduino Library Manager (Recommended)
- Open Arduino IDE
- Go to Tools → Manage Libraries
- Search for "WiFiCreds"
- Click Install
Manual Installation
- Download or clone this repository
- Copy the WiFiCreds folder to your Arduino libraries directory:
- Windows: Documents\Arduino\libraries\
- macOS: ~/Documents/Arduino/libraries/
- Linux: ~/Arduino/libraries/
- Restart Arduino IDE
Quick Start
1. Configure Your Credentials
Create a credentials.h file in the library's src folder with multiple credential sets:
#ifndef CREDENTIALS_H
#define CREDENTIALS_H
const CredentialSet CREDENTIAL_SETS[] = {
{
.name = "home",
.ssid = "MyHomeWiFi",
.password = "HomePassword123"
},
{
.name = "office",
.ssid = "OfficeNetwork",
.password = "OfficePassword456"
},
{
.name = "guest",
.ssid = "GuestWiFi",
.password = "GuestPassword789"
},
{
.name = nullptr,
.ssid = nullptr,
.password = nullptr
}
};
#endif
Important:
- The credentials.h file must be placed in the WiFiCreds/src/ directory
- The first credential set is always used as the default
- Invalid names automatically fall back to the default set
2. Basic Usage
#include <WiFiCreds.h>
#include <WiFi.h>
void setup() {
Serial.begin(115200);
WiFi.begin(WiFiCreds::getSSID(), WiFiCreds::getPassword());
Serial.print("Connecting to default network: ");
Serial.println(WiFiCreds::getSSID());
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected to Wi-Fi!");
}
void loop() {
}
Using Specific Credential Sets
#include <WiFiCreds.h>
#include <WiFi.h>
void setup() {
Serial.begin(115200);
WiFi.begin(WiFiCreds::getSSID("home"), WiFiCreds::getPassword("home"));
Serial.print("Connecting to home network: ");
Serial.println(WiFiCreds::getSSID("home"));
WiFi.begin(WiFiCreds::getSSID("invalid"), WiFiCreds::getPassword("invalid"));
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected to Wi-Fi!");
}
void loop() {
}
API Reference
Core Methods
getSSID(const char* name = nullptr)
Returns the Wi-Fi SSID for a specific credential set or default if no name provided.
const char* ssid = WiFiCreds::getSSID();
const char* ssid = WiFiCreds::getSSID("home");
getPassword(const char* name = nullptr)
Returns the Wi-Fi password for a specific credential set or default if no name provided.
const char* password = WiFiCreds::getPassword();
const char* password = WiFiCreds::getPassword("home");
isValid(const char* name = nullptr)
Validates that both SSID and password for a specific set are properly configured.
if (WiFiCreds::isValid()) {
}
if (WiFiCreds::isValid("home")) {
}
getSSIDLength(const char* name = nullptr)
Returns the length of the SSID string for a specific credential set.
size_t ssidLength = WiFiCreds::getSSIDLength();
size_t ssidLength = WiFiCreds::getSSIDLength("home");
getPasswordLength(const char* name = nullptr)
Returns the length of the password string for a specific credential set.
size_t passwordLength = WiFiCreds::getPasswordLength();
size_t passwordLength = WiFiCreds::getPasswordLength("home");
Management Methods
getCredentialCount()
Returns the total number of available credential sets.
size_t count = WiFiCreds::getCredentialCount();
getCredentialName(size_t index)
Returns the name of a credential set by index.
const char* name = WiFiCreds::getCredentialName(0);
hasCredential(const char* name)
Checks if a credential set with the given name exists.
if (WiFiCreds::hasCredential("home")) {
}
getDefaultName()
Returns the name of the default credential set (first set).
const char* defaultName = WiFiCreds::getDefaultName();
Examples
The library includes several example sketches for different platforms:
Getting Started Examples
- SimpleExample: Basic demonstration of accessing and displaying stored credentials without connecting to WiFi
- BasicWiFiConnection: Simple Wi-Fi connection example
- WiFiCredsDemo: Comprehensive example with interactive features
Platform-Specific Examples
- RaspberryPiPicoW: Example for Raspberry Pi Pico W with built-in LED indicators
- ESP32: Advanced ESP32 example with WiFi scanning and power management
- ESP8266: ESP8266-specific example with system information and deep sleep
- ArduinoR4: Arduino R4 WiFi example with RGB LED indicators and system information
- ArduinoESP8266-01: Arduino with ESP8266-01 module using SoftwareSerial communication
SimpleExample Walkthrough
The SimpleExample demonstrates the basic usage of the WiFiCreds library:
- Purpose: Tests if your credentials.h file is properly configured
- Functionality: Displays default credentials and shows usage procedure
- Use Case: Perfect for verifying library installation and learning how to use the library
#include <WiFiCreds.h>
void setup() {
Serial.begin(115200);
size_t count = WiFiCreds::getCredentialCount();
if (count > 0) {
Serial.print("Default: ");
Serial.println(WiFiCreds::getSSID());
Serial.println("Usage examples:");
Serial.println("WiFi.begin(WiFiCreds::getSSID(), WiFiCreds::getPassword());");
Serial.println("WiFi.begin(WiFiCreds::getSSID(\"home\"), WiFiCreds::getPassword(\"home\"));");
}
}
This example is ideal for:
- Testing your credential configuration
- Verifying library installation
- Understanding basic API usage
- Debugging credential-related issues
- Learning the usage procedure
- Seeing the credentials.h file format
Security Best Practices
- Never commit credentials: Add credentials.h to your .gitignore
- Use strong passwords: Ensure your Wi-Fi password is secure
- Production deployment: Consider using secure storage methods for production
- Regular updates: Keep your credentials updated and secure
- Share safely: When sharing code, ensure credentials.h is excluded
Future Enhancements
The library is designed to be extensible. Future versions may include:
- EEPROM Storage: Store credentials in EEPROM memory
- SPIFFS Support: Load credentials from SPIFFS file system
- Secure Elements: Integration with hardware security modules
- Encryption: Encrypted credential storage
- Multiple Networks: Support for multiple Wi-Fi networks
- OTA Updates: Over-the-air credential updates
Contributing
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
License
This library is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
Author
Rithik Krisna M (@me-RK)
Version History
- v1.0.3: Simplified version with multiple credential sets, automatic fallback, and clean API design
- v1.0.0: Initial release with basic credential management
Support
If you encounter any issues or have questions:
- Check the examples folder
- Review the documentation
- Open an issue
- Check the Arduino Forum
Note: This library is designed for educational and development purposes. For production applications, consider implementing additional security measures appropriate for your use case.