Some Arduino IOT boards have eeprom, or you can attach eeprom by serial supporting "EEPROM.h" library. This is ideal to store your Wi-Fi credentials (SSID and Pass), in a cyphered way. Boards with eeprom and Wi-Fi are:
Idea is simple : setup credential structure once in eeprom, then use the read functions in your IOT app. No more credentials in your sketch code, no readable credentials in eeprom.
Credentials Container StructureThere is struct defined in credentials.h, containing a bunch of credential info like SSID/Pass, Login/Pass, Mqtt-Server/login/pass:
// ------------------- EEPROM CREDENTIALS FOR READ WRITE ROUTINES
#define EECredentials_ID 0x13 // EEprom save ID for object to retrieve
#define EE_SEED 55 // Seed for Cyphering
#define EE_MAXCHAR 32 //
struct EECredentials { // structure for EEprom storage: 7 x 32byte + 5 bytes = 229 bytes length + overhead = 232 bytes in total
char ssid[EE_MAXCHAR];
char wifipass[EE_MAXCHAR];
char login1[EE_MAXCHAR];
char pass1[EE_MAXCHAR];
char mqttadr[EE_MAXCHAR];
char mqttlogin[EE_MAXCHAR];
char mqttpass[EE_MAXCHAR];
byte identity;
long counter;
};
Also added I n the container an ID and a counter for the eeprom writes.Total size is a 232 bytes to store. You can reduce it by restricting the text-lengh of the data. Data is stored at the END of the eeprom memory, so you can use eeprom as from adress 0x00 for other data.
All you have to do is set your ID (verifies if you read the right container) and the Seed - this is used for the (de)cyphering.Additional there is an erase function, erasing the ID.
CypheringCypher and Decypher is vey simple, it hustles the text characters by Seed. This is not crypto rocket science, but prevents that in case someone reads the eeprom of your board, it can not read your secrets.
There is a second sketch ReadStoragePass.ino containing only the read functions, this part needs to be integrated in your own code, including the credentials.h definitions.
Debug.hLast but not least, I use a simple Debug() command to execute a Serial.print() for debugging data to the terminal. Advantage is that this can be turned off, after your have tested the code and make your code smaller - see Debug.h include file
Happy Coding!
Comments
Please log in or sign up to comment.