-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcredentialsmemory.cpp
More file actions
83 lines (60 loc) · 1.63 KB
/
credentialsmemory.cpp
File metadata and controls
83 lines (60 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <EEPROM.h>
#include "credentialsmemory.h"
WifiCredentials CredentialsMemory::read()
{
Serial.println("Initializing EEPROM");
EEPROM.begin(512);
Serial.println("Reading EEPROM ssid");
String essid = "";
WifiCredentials result;
for (int i = 0; i < 32; ++i)
{
essid += char(EEPROM.read(i));
}
result.ssid = essid;
Serial.println();
Serial.print("ssid: ");
Serial.println(result.ssid);
Serial.println("Reading EEPROM password");
String epass = "";
for (int i = 32; i < 96; ++i)
{
epass += char(EEPROM.read(i));
}
result.pwd = epass;
Serial.print("PASS: ");
Serial.println(result.pwd);
return result;
}
bool CredentialsMemory::write(const String& ssid, const String& password)
{
if (ssid.length() > 0 && password.length() > 0)
{
Serial.println("clearing eeprom");
for (int i = 0; i < 96; ++i)
{
EEPROM.write(i, 0);
}
Serial.println(ssid);
Serial.println("");
Serial.println(password);
Serial.println("");
Serial.println("writing eeprom ssid:");
for (int i = 0; i < ssid.length(); ++i)
{
EEPROM.write(i, ssid[i]);
Serial.print("Wrote: ");
Serial.println(ssid[i]);
}
Serial.println("writing eeprom pass:");
for (int i = 0; i < password.length(); ++i)
{
EEPROM.write(32 + i, password[i]);
Serial.print("Wrote: ");
Serial.println(password[i]);
}
EEPROM.commit();
return false;
}
return true;
}