-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetups.cpp
More file actions
54 lines (46 loc) · 2 KB
/
setups.cpp
File metadata and controls
54 lines (46 loc) · 2 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
#include <Arduino.h>
#include <SD.h>
#include "setups.h"
#include <Wire.h>
#include "AT24C256.h"
AT24C256 e2prom = AT24C256();
#define maximum 128
char secret[maximum];
/*
* Reads the file /sys/secret.c2n
* Requires:
* SSID,PASSWORD <- No spaces or anything else at the end !
*
* Writes the e²prom and deletes the file
*
* No file: attempt to read the e²prom creditials
*/
String setups::get_creditials(String creditsfile) {
String filepath = String(folder)+creditsfile;
int i=0; int j=0;
if (SD.exists(filepath)) {
File creditfile = SD.open(filepath,"r"); // get the creditials
while (creditfile.available())
{
char inputchar = creditfile.read();
secret[i] = inputchar;
i++;
}
e2prom.write(i, 0); // write amount of chars
j=0; // write creditials to e²prom
do {
e2prom.write(secret[j],j+1);
j++;
} while (j <= i);
SD.remove(filepath); // delete the creditials-file secret.c2n
}
else { // no file, read e²prom for creditials
i = e2prom.read(0); // get amount of chars
j = 0;
do {
secret[j] = e2prom.read(j+1);
j++;
} while(j <= i+1);
}
return secret;
}