Browse Source

Now serving scripts using RawGit.com service

Thomas Buck 7 years ago
parent
commit
d7272835c8
2 changed files with 24 additions and 21 deletions
  1. 23
    20
      ESP-Weather.ino
  2. 1
    1
      README.md

+ 23
- 20
ESP-Weather.ino View File

@@ -13,7 +13,8 @@
13 13
 #define WEB_PORT 80
14 14
 #define BROADCAST_PORT 2390
15 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 19
 #define DEFAULT_SSID "ESP-Weather"
19 20
 #define DEFAULT_PASS "testtest"
@@ -49,18 +50,20 @@ std::vector<IPAddress> vecClients;
49 50
 char packetBuffer[UDP_PACKET_BUFFER_SIZE];
50 51
 const char pingBuffer[] = "pingESP8266v0.1";
51 52
 const char echoBuffer[] = "echoESP8266v0.1";
52
-WiFiUDP Udp;
53
+WiFiUDP udp;
53 54
 
54 55
 unsigned long lastTime;
55 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 60
 const char* htmlBegin = "<html><head>\
58 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 67
 </head><body>\
65 68
 <script type=\"text/javascript\">";
66 69
 const char* htmlEnd = "</script></body></html>";
@@ -69,9 +72,9 @@ void handleRoot() {
69 72
     Serial.println("Sending UDP Broadcast...");
70 73
 
71 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 79
     // Start reply wait timer
77 80
     lastTime = millis();
@@ -136,12 +139,12 @@ void setup(void) {
136 139
     serverSocket.begin();
137 140
 
138 141
     // NTP-Client
139
-    ntp.begin(NTP_PORT);
142
+    ntp.begin(NTP_PORT_FROM);
140 143
     WiFi.hostByName(ntpServerName, timeServerIP); 
141 144
     lastNTP = millis();
142 145
     sendNTPpacket(timeServerIP); 
143 146
 
144
-    Udp.begin(BROADCAST_PORT);
147
+    udp.begin(BROADCAST_PORT);
145 148
     Serial.println("ESP-Weather ready!");
146 149
 }
147 150
 
@@ -221,11 +224,11 @@ void loop(void){
221 224
     }
222 225
 
223 226
     // UDP
224
-    int packetSize = Udp.parsePacket();
227
+    int packetSize = udp.parsePacket();
225 228
     if (packetSize) {
226
-        IPAddress remoteIp = Udp.remoteIP();
229
+        IPAddress remoteIp = udp.remoteIP();
227 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 232
         if (len > 0) {
230 233
             packetBuffer[len] = 0;
231 234
         }
@@ -235,11 +238,11 @@ void loop(void){
235 238
 
236 239
         if (strcmp(packetBuffer, pingBuffer) == 0) {
237 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 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,7 +282,7 @@ void sendNTPpacket(IPAddress& address) {
279 282
     ntpPacketBuffer[14]  = 49;
280 283
     ntpPacketBuffer[15]  = 52;
281 284
 
282
-    ntp.beginPacket(address, 123);
285
+    ntp.beginPacket(address, NTP_PORT_TO);
283 286
     ntp.write(ntpPacketBuffer, NTP_PACKET_SIZE);
284 287
     ntp.endPacket();
285 288
 }

+ 1
- 1
README.md View File

@@ -1,6 +1,6 @@
1 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 5
 ## Dependencies
6 6
 

Loading…
Cancel
Save