Pārlūkot izejas kodu

Now serving scripts using RawGit.com service

Thomas Buck 7 gadus atpakaļ
vecāks
revīzija
d7272835c8
2 mainītis faili ar 24 papildinājumiem un 21 dzēšanām
  1. 23
    20
      ESP-Weather.ino
  2. 1
    1
      README.md

+ 23
- 20
ESP-Weather.ino Parādīt failu

13
 #define WEB_PORT 80
13
 #define WEB_PORT 80
14
 #define BROADCAST_PORT 2390
14
 #define BROADCAST_PORT 2390
15
 #define WEBSOCKET_PORT 2391
15
 #define WEBSOCKET_PORT 2391
16
-#define NTP_PORT 2392
16
+#define NTP_PORT_FROM 2392
17
+#define NTP_PORT_TO 123
17
 
18
 
18
 #define DEFAULT_SSID "ESP-Weather"
19
 #define DEFAULT_SSID "ESP-Weather"
19
 #define DEFAULT_PASS "testtest"
20
 #define DEFAULT_PASS "testtest"
49
 char packetBuffer[UDP_PACKET_BUFFER_SIZE];
50
 char packetBuffer[UDP_PACKET_BUFFER_SIZE];
50
 const char pingBuffer[] = "pingESP8266v0.1";
51
 const char pingBuffer[] = "pingESP8266v0.1";
51
 const char echoBuffer[] = "echoESP8266v0.1";
52
 const char echoBuffer[] = "echoESP8266v0.1";
52
-WiFiUDP Udp;
53
+WiFiUDP udp;
53
 
54
 
54
 unsigned long lastTime;
55
 unsigned long lastTime;
55
 bool waitingForReplies = false;
56
 bool waitingForReplies = false;
56
 
57
 
58
+// Using the RawGit.com service to serve the scripts directly from GitHub.
59
+// Consider using cdn.rawgit.com to reduce their server load.
57
 const char* htmlBegin = "<html><head>\
60
 const char* htmlBegin = "<html><head>\
58
 <title>Sysadmin</title>\
61
 <title>Sysadmin</title>\
59
-<script src=\"http://hoegerle-home.de/sysAdmin/js/jquery-3.1.1.min.js\"></script>\
60
-<script src=\"http://hoegerle-home.de/sysAdmin/js/bootstrap.min.js\"></script>\
61
-<script src=\"http://hoegerle-home.de/sysAdmin/js/Chart.bundle.min.js\"></script>\
62
-<script src=\"http://hoegerle-home.de/sysAdmin/js/script.js\"></script>\
63
-<link rel=\"stylesheet\" href=\"http://hoegerle-home.de/sysAdmin/css/bootstrap.min.css\" />\
62
+<script src=\"https://rawgit.com/xythobuz/ESP-Weather/master/static/jquery-3.1.1.min.js\"></script>\
63
+<script src=\"https://rawgit.com/xythobuz/ESP-Weather/master/static/bootstrap.min.js\"></script>\
64
+<script src=\"https://rawgit.com/xythobuz/ESP-Weather/master/static/Chart.bundle.min.js\"></script>\
65
+<script src=\"https://rawgit.com/xythobuz/ESP-Weather/master/static/script.js\"></script>\
66
+<link rel=\"stylesheet\" href=\"https://rawgit.com/xythobuz/ESP-Weather/master/static/bootstrap.min.css\" />\
64
 </head><body>\
67
 </head><body>\
65
 <script type=\"text/javascript\">";
68
 <script type=\"text/javascript\">";
66
 const char* htmlEnd = "</script></body></html>";
69
 const char* htmlEnd = "</script></body></html>";
69
     Serial.println("Sending UDP Broadcast...");
72
     Serial.println("Sending UDP Broadcast...");
70
 
73
 
71
     // Send UDP broadcast to other modules
74
     // Send UDP broadcast to other modules
72
-    Udp.beginPacket(broadcastIP, BROADCAST_PORT);
73
-    Udp.write(pingBuffer);
74
-    Udp.endPacket();
75
+    udp.beginPacket(broadcastIP, BROADCAST_PORT);
76
+    udp.write(pingBuffer);
77
+    udp.endPacket();
75
 
78
 
76
     // Start reply wait timer
79
     // Start reply wait timer
77
     lastTime = millis();
80
     lastTime = millis();
136
     serverSocket.begin();
139
     serverSocket.begin();
137
 
140
 
138
     // NTP-Client
141
     // NTP-Client
139
-    ntp.begin(NTP_PORT);
142
+    ntp.begin(NTP_PORT_FROM);
140
     WiFi.hostByName(ntpServerName, timeServerIP); 
143
     WiFi.hostByName(ntpServerName, timeServerIP); 
141
     lastNTP = millis();
144
     lastNTP = millis();
142
     sendNTPpacket(timeServerIP); 
145
     sendNTPpacket(timeServerIP); 
143
 
146
 
144
-    Udp.begin(BROADCAST_PORT);
147
+    udp.begin(BROADCAST_PORT);
145
     Serial.println("ESP-Weather ready!");
148
     Serial.println("ESP-Weather ready!");
146
 }
149
 }
147
 
150
 
221
     }
224
     }
222
 
225
 
223
     // UDP
226
     // UDP
224
-    int packetSize = Udp.parsePacket();
227
+    int packetSize = udp.parsePacket();
225
     if (packetSize) {
228
     if (packetSize) {
226
-        IPAddress remoteIp = Udp.remoteIP();
229
+        IPAddress remoteIp = udp.remoteIP();
227
         // read the packet into packetBufffer
230
         // read the packet into packetBufffer
228
-        int len = Udp.read(packetBuffer, UDP_PACKET_BUFFER_SIZE);
231
+        int len = udp.read(packetBuffer, UDP_PACKET_BUFFER_SIZE);
229
         if (len > 0) {
232
         if (len > 0) {
230
             packetBuffer[len] = 0;
233
             packetBuffer[len] = 0;
231
         }
234
         }
235
 
238
 
236
         if (strcmp(packetBuffer, pingBuffer) == 0) {
239
         if (strcmp(packetBuffer, pingBuffer) == 0) {
237
             Serial.println("Broadcast");
240
             Serial.println("Broadcast");
238
-            Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
239
-            Udp.print(echoBuffer);
240
-            Udp.endPacket();
241
+            udp.beginPacket(udp.remoteIP(), udp.remotePort());
242
+            udp.print(echoBuffer);
243
+            udp.endPacket();
241
         } else if((strcmp(packetBuffer, echoBuffer) == 0) && (waitingForReplies == true)) {
244
         } else if((strcmp(packetBuffer, echoBuffer) == 0) && (waitingForReplies == true)) {
242
-            vecClients.push_back(Udp.remoteIP());
245
+            vecClients.push_back(udp.remoteIP());
243
         }
246
         }
244
     }
247
     }
245
 
248
 
279
     ntpPacketBuffer[14]  = 49;
282
     ntpPacketBuffer[14]  = 49;
280
     ntpPacketBuffer[15]  = 52;
283
     ntpPacketBuffer[15]  = 52;
281
 
284
 
282
-    ntp.beginPacket(address, 123);
285
+    ntp.beginPacket(address, NTP_PORT_TO);
283
     ntp.write(ntpPacketBuffer, NTP_PACKET_SIZE);
286
     ntp.write(ntpPacketBuffer, NTP_PACKET_SIZE);
284
     ntp.endPacket();
287
     ntp.endPacket();
285
 }
288
 }

+ 1
- 1
README.md Parādīt failu

1
 # ESP-Weather
1
 # ESP-Weather
2
 
2
 
3
-This started out as a project for the "Systemadministration" course in the Hochschule Ravensburg-Weingarten in the winter of 2016 / 2017.
3
+This [started out as a project](https://github.com/g40st/Systemadministration) for the "Systemadministration" course in the Hochschule Ravensburg-Weingarten in the winter of 2016 / 2017.
4
 
4
 
5
 ## Dependencies
5
 ## Dependencies
6
 
6
 

Notiek ielāde…
Atcelt
Saglabāt