Browse Source

added WiFiManger

g40st 7 years ago
parent
commit
660ed3ee8e
2 changed files with 20 additions and 12 deletions
  1. 1
    0
      README.md
  2. 19
    12
      sysAdmin/sysAdmin.ino

+ 1
- 0
README.md View File

@@ -8,6 +8,7 @@ Projekt zur Systemadministration-Vorlesung im Wintersemester 2016/17 an der Hoch
8 8
 * [Arduino core for ESP8266 WiFi chip](https://github.com/esp8266/Arduino)
9 9
 * [temperature and humidity sensor SHT21](https://github.com/markbeee/SHT21)
10 10
 * [Websocket Server](https://github.com/morrissinger/ESP8266-Websocket)
11
+* [WiFiManager](https://github.com/tzapu/WiFiManager)
11 12
 
12 13
 ### JavaScript
13 14
 * [Bootstrap](http://getbootstrap.com/)

+ 19
- 12
sysAdmin/sysAdmin.ino View File

@@ -7,6 +7,8 @@
7 7
 #include <WebSocketServer.h>
8 8
 #include <WiFiServer.h>
9 9
 #include <EEPROM.h>
10
+#include <DNSServer.h>
11
+#include <WiFiManager.h>
10 12
 
11 13
 #define NTP_PORT 2392
12 14
 #define MAX_WAIT_TIME 550
@@ -29,8 +31,9 @@ ESP8266WebServer server(80);
29 31
 WiFiServer serverSocket(2391);
30 32
 WebSocketServer webSocketServer;
31 33
 
32
-const char* ssid = "SysadminWLAN";
33
-const char* password = "sysadmin";
34
+#define DEFAULT_SSID "ESP-Weather"
35
+#define DEFAULT_PASS "testtest"
36
+
34 37
 IPAddress broadcastIP;
35 38
 
36 39
 struct __attribute__((__packed__)) Measurement {
@@ -85,7 +88,7 @@ PersistentStorage readMemory() {
85 88
     Serial.println((b << 8) | a);
86 89
     s.header.count = 0;
87 90
   } else {
88
-    Serial.println("Checksum ok");  
91
+    Serial.println("Checksum ok");
89 92
   }
90 93
   return s;
91 94
 }
@@ -148,29 +151,31 @@ void handleNotFound(){
148 151
 }
149 152
 
150 153
 void setup(void) {
151
-  SHT21.begin();
152
-  
153 154
   EEPROM.begin(512);
154
-    
155
+   
155 156
   // Debugging
156 157
   Serial.begin(115200);
157
-  WiFi.begin(ssid, password);
158 158
   Serial.println("");
159 159
 
160
+  SHT21.begin();
161
+  
162
+  WiFiManager wifiManager;
163
+  // use one or the other, never both!
164
+  wifiManager.autoConnect(DEFAULT_SSID, DEFAULT_PASS);
165
+  //wifiManager.startConfigPortal(DEFAULT_SSID, DEFAULT_PASS);
166
+
167
+  storage = readMemory();
168
+
160 169
   // Wait for connection
161 170
   while (WiFi.status() != WL_CONNECTED) {
162 171
     delay(500);
163 172
     Serial.print(".");
164 173
   }
165 174
   Serial.println("");
166
-  Serial.print("Connected to ");
167
-  Serial.println(ssid);
168 175
   Serial.print("IP address: ");
169 176
   Serial.println(WiFi.localIP());
170
-    
171
-  broadcastIP = ~WiFi.subnetMask() | WiFi.gatewayIP();
172 177
   
173
-  storage = readMemory();
178
+  broadcastIP = ~WiFi.subnetMask() | WiFi.gatewayIP();
174 179
   
175 180
   server.on("/", handleRoot);
176 181
   server.onNotFound(handleNotFound);
@@ -186,10 +191,12 @@ void setup(void) {
186 191
   
187 192
   Udp.begin(localPort);
188 193
   Serial.println("HTTP server and UDP started");
194
+  
189 195
 }
190 196
 
191 197
 void loop(void){
192 198
   server.handleClient();
199
+  Serial.println(SHT21.getTemperature());
193 200
 
194 201
   // Websocket fuer Browser
195 202
   WiFiClient client = serverSocket.available();

Loading…
Cancel
Save