g40st преди 7 години
родител
ревизия
660ed3ee8e
променени са 2 файла, в които са добавени 20 реда и са изтрити 12 реда
  1. 1
    0
      README.md
  2. 19
    12
      sysAdmin/sysAdmin.ino

+ 1
- 0
README.md Целия файл

8
 * [Arduino core for ESP8266 WiFi chip](https://github.com/esp8266/Arduino)
8
 * [Arduino core for ESP8266 WiFi chip](https://github.com/esp8266/Arduino)
9
 * [temperature and humidity sensor SHT21](https://github.com/markbeee/SHT21)
9
 * [temperature and humidity sensor SHT21](https://github.com/markbeee/SHT21)
10
 * [Websocket Server](https://github.com/morrissinger/ESP8266-Websocket)
10
 * [Websocket Server](https://github.com/morrissinger/ESP8266-Websocket)
11
+* [WiFiManager](https://github.com/tzapu/WiFiManager)
11
 
12
 
12
 ### JavaScript
13
 ### JavaScript
13
 * [Bootstrap](http://getbootstrap.com/)
14
 * [Bootstrap](http://getbootstrap.com/)

+ 19
- 12
sysAdmin/sysAdmin.ino Целия файл

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

Loading…
Отказ
Запис