-
Notifications
You must be signed in to change notification settings - Fork 0
/
_loraFiles.ino
190 lines (173 loc) · 6.58 KB
/
_loraFiles.ino
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// 1-channel LoRa Gateway for ESP8266
// Copyright (c) 2016, 2017 Maarten Westenberg version for ESP8266
// Version 4.0.8
// Date: 2017-08-05
//
// based on work done by Thomas Telkamp for Raspberry PI 1ch gateway
// and many others.
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the MIT License
// which accompanies this distribution, and is available at
// https://opensource.org/licenses/mit-license.php
//
// Author: Maarten Westenberg ([email protected])
//
// This file contains the LoRa filesystem specific code
// ============================================================================
// LORA SPIFFS FILESYSTEM FUNCTIONS
//
// The LoRa supporting functions are in the section below
// ----------------------------------------------------------------------------
// Directory listing. s is a string containing HTML/text code so far.
// The resulting directory listing is appended to s and returned.
// ----------------------------------------------------------------------------
String espDir(String s) {
return s;
}
// ----------------------------------------------------------------------------
// Read the gateway configuration file
// ----------------------------------------------------------------------------
int readConfig(const char *fn, struct espGwayConfig *c) {
Serial.println(F("readConfig:: Starting"));
if (!SPIFFS.exists(fn)) {
Serial.print("ERROR:: readConfig, file does not exist ");
Serial.println(fn);
return(-1);
}
File f = SPIFFS.open(fn, "r");
if (!f) {
Serial.println("ERROR:: readConfig, file open failed");
return(-1);
}
while (f.available()) {
String id =f.readStringUntil('=');
String val=f.readStringUntil('\n');
if (id == "SSID") { // WiFi SSID
Serial.print(F("SSID=")); Serial.println(val);
(*c).ssid = val; // val contains ssid, we do NO check
}
if (id == "PASS") { // WiFi Password
Serial.print(F("PASS=")); Serial.println(val);
(*c).pass = val;
}
if (id == "CH") { // Frequency Channel
Serial.print(F("CH=")); Serial.println(val);
(*c).ch = (uint32_t) val.toInt();
}
if (id == "SF") { // Spreading Factor
Serial.print(F("SF =")); Serial.println(val);
(*c).sf = (uint32_t) val.toInt();
}
if (id == "FCNT") { // Frame Counter
Serial.print(F("FCNT=")); Serial.println(val);
(*c).fcnt = (uint32_t) val.toInt();
}
if (id == "DEBUG") { // Frame Counter
Serial.print(F("DEBUG=")); Serial.println(val);
(*c).debug = (uint8_t) val.toInt();
}
if (id == "CAD") { // CAD setting
Serial.print(F("CAD=")); Serial.println(val);
(*c).cad = (uint8_t) val.toInt();
}
if (id == "HOP") { // HOP setting
Serial.print(F("HOP=")); Serial.println(val);
(*c).hop = (uint8_t) val.toInt();
}
if (id == "BOOTS") { // BOOTS setting
Serial.print(F("BOOTS=")); Serial.println(val);
(*c).boots = (uint8_t) val.toInt();
}
if (id == "RESETS") { // RESET setting
Serial.print(F("RESETS=")); Serial.println(val);
(*c).resets = (uint8_t) val.toInt();
}
if (id == "WIFIS") { // WIFIS setting
Serial.print(F("WIFIS=")); Serial.println(val);
(*c).wifis = (uint8_t) val.toInt();
}
if (id == "VIEWS") { // VIEWS setting
Serial.print(F("VIEWS=")); Serial.println(val);
(*c).views = (uint8_t) val.toInt();
}
if (id == "NODE") { // NODE setting
Serial.print(F("NODE=")); Serial.println(val);
(*c).node = (uint8_t) val.toInt();
}
if (id == "REFR") { // REFR setting
Serial.print(F("REFR=")); Serial.println(val);
(*c).refresh = (uint8_t) val.toInt();
}
if (id == "REENTS") { // REENTS setting
Serial.print(F("REENTS=")); Serial.println(val);
(*c).reents = (uint8_t) val.toInt();
}
if (id == "NTPERR") { // NTPERR setting
Serial.print(F("NTPERR=")); Serial.println(val);
(*c).ntpErr = (uint8_t) val.toInt();
}
if (id == "NTPS") { // NTPS setting
Serial.print(F("NTPS=")); Serial.println(val);
(*c).ntps = (uint8_t) val.toInt();
}
}
f.close();
return(1);
}
// ----------------------------------------------------------------------------
// Write the current gateway configuration to SPIFFS. First copy all the
// separate data items to the gwayConfig structure
//
// ----------------------------------------------------------------------------
int writeGwayCfg(const char *fn) {
gwayConfig.sf = (uint8_t) sf;
gwayConfig.ssid = WiFi.SSID();
//gwayConfig.pass = WiFi.PASS(); // XXX We should find a way to store the password too
gwayConfig.ch = ifreq;
gwayConfig.debug = debug;
gwayConfig.cad = _cad;
gwayConfig.hop = _hop;
#if GATEWAYNODE==1
gwayConfig.fcnt = frameCount;
#endif
return(writeConfig(fn, &gwayConfig));
}
// ----------------------------------------------------------------------------
// Write the configuration ad found in the espGwayConfig structure
// to SPIFFS
// ----------------------------------------------------------------------------
int writeConfig(const char *fn, struct espGwayConfig *c) {
if (!SPIFFS.exists(fn)) {
Serial.print("WARNING:: writeConfig, file does not exist, formatting ");
SPIFFS.format();
// XXX make all initial declarations here if config vars need to have a value
Serial.println(fn);
}
File f = SPIFFS.open(fn, "w");
if (!f) {
Serial.print("ERROR:: writeConfig, file open failed for file=");
Serial.print(fn);
Serial.println();
return(-1);
}
f.print("SSID"); f.print('='); f.print((*c).ssid); f.print('\n');
f.print("PASS"); f.print('='); f.print((*c).pass); f.print('\n');
f.print("CH"); f.print('='); f.print((*c).ch); f.print('\n');
f.print("SF"); f.print('='); f.print((*c).sf); f.print('\n');
f.print("FCNT"); f.print('='); f.print((*c).fcnt); f.print('\n');
f.print("DEBUG"); f.print('='); f.print((*c).debug); f.print('\n');
f.print("CAD"); f.print('='); f.print((*c).cad); f.print('\n');
f.print("HOP"); f.print('='); f.print((*c).hop); f.print('\n');
f.print("NODE"); f.print('='); f.print((*c).node); f.print('\n');
f.print("BOOTS"); f.print('='); f.print((*c).boots); f.print('\n');
f.print("RESETS"); f.print('='); f.print((*c).resets); f.print('\n');
f.print("WIFIS"); f.print('='); f.print((*c).wifis); f.print('\n');
f.print("VIEWS"); f.print('='); f.print((*c).views); f.print('\n');
f.print("REFR"); f.print('='); f.print((*c).refresh); f.print('\n');
f.print("REENTS"); f.print('='); f.print((*c).reents); f.print('\n');
f.print("NTPERR"); f.print('='); f.print((*c).ntpErr); f.print('\n');
f.print("NTPS"); f.print('='); f.print((*c).ntps); f.print('\n');
f.close();
return(1);
}