Showing 2 changed files with 96 additions and 38 deletions
+63 -17
csv2geojs.py
... ...
@@ -11,7 +11,7 @@ server = configuration.get_server()
11 11
 # https://unpkg.com/leaflet@1.7.1/dist/leaflet.js
12 12
 # https://unpkg.com/leaflet@1.7.1/dist/leaflet.css
13 13
 
14
-def networkSurveyColor(rssi):
14
+def networkSurveyColorRSSI(rssi):
15 15
     color="#888"
16 16
     if float(rssi) < -105:
17 17
         color="#f00"
... ...
@@ -25,6 +25,32 @@ def networkSurveyColor(rssi):
25 25
         color="#15ab00"
26 26
     return color
27 27
 
28
+def networkSurveyColor(snr):
29
+    color="#888"
30
+    if float(snr) <= -7.5:
31
+        #sf12
32
+        color="#f00"
33
+    elif float(snr) <= -5:
34
+        #sf11
35
+        #color="#ff6600"
36
+        color="#a35c00"
37
+    elif float(snr) < -2.5:
38
+        #sf10
39
+        #color="#ffa500"
40
+        color="#7a8500"
41
+    elif float(snr) < -0:
42
+        #sf9
43
+        #color="#ffab40"
44
+        color="#52ad00"
45
+    elif float(snr) < 2.5:
46
+        #sf8
47
+        #color="#ffab40"
48
+        color="#29d600"
49
+    else:
50
+        #sf7
51
+        color="#15ab00"
52
+    return color
53
+
28 54
 def networkSurveySetLeaflet(useLocal):
29 55
     global useLeafletLocal
30 56
     if True is useLocal:
... ...
@@ -53,9 +79,10 @@ def networkSurveySetMapboxApiToken():
53 79
     return MAPBOXTOKEN
54 80
 
55 81
 
56
-def networkSurvey(filename, subId, devEUI = None, fileOutput= True):
82
+def networkSurvey(filename, subId, devEUI = None, fileOutput= True, latestRecords=0):
57 83
     global server
58 84
     global circleOpacity
85
+    latest=int(latestRecords)
59 86
     start_time = time.time()
60 87
     htmlOutput="<!DOCTYPE html>\n"
61 88
     htmlOutput+="<html>\n"
... ...
@@ -113,18 +140,28 @@ def networkSurvey(filename, subId, devEUI = None, fileOutput= True):
113 140
     count = 0
114 141
     countRaw = 0
115 142
     lastLine=""
143
+    if latest == 0:
144
+        latest = 100000
116 145
     with open(filename, "rt") as fin:
117
-        lines=fin.readlines()
146
+        lines=reversed(fin.readlines())
147
+        #lines=fin.readlines()
148
+        #lastLine=lines[0]
118 149
         for line in lines:
119 150
             part=line.split(',')
120 151
             countRaw += 1
121 152
             if subId == part[0]:
122 153
                 if devEUI is None:
123
-                    lastLine=line
154
+                    #if lastLine is "" and countRaw != 1:
155
+                    #lastLine=line
124 156
                     if part[5] is not "0" and part[6] is not "0":
157
+                        if lastLine is "":
158
+                            lastLine = line
125 159
                         count += 1
160
+                        if count > latest:
161
+                            break
126 162
                         color=networkSurveyColor(part[9])
127
-                        jsLine="  L.circle(["+part[5]+","+part[6]+"],{color: '"+color+"', fillcolor: '"+color+"', fillOpacity: "+str(circleOpacity)+", radius:XXXX}).addTo(mymap);\n"
163
+                        #jsLine="  L.circle(["+part[5]+","+part[6]+"],{color: '"+color+"', fillcolor: '"+color+"', fillOpacity: "+str(circleOpacity)+", radius:XXXX}).addTo(mymap); //"+part[2]+"\n"
164
+                        jsLine="  L.circle(["+part[5]+","+part[6]+"],{color: '"+color+"', fillcolor: '"+color+"', fillOpacity: "+str(circleOpacity)+", radius:"+str(part[7])+"}).addTo(mymap); //"+part[2]+" "+part[9]+" "+part[10]+"\n"
128 165
                         if float(part[5]) > latMax:
129 166
                             latMax=float(part[5])
130 167
                         if float(part[5]) < latMin:
... ...
@@ -135,11 +172,18 @@ def networkSurvey(filename, subId, devEUI = None, fileOutput= True):
135 172
                             lonMin=float(part[6])
136 173
                         pointList+=jsLine
137 174
                 elif part[1] == devEUI:
138
-                    lastLine=line
175
+                    #if lastLine == "":
176
+                    #lastLine=line
139 177
                     if part[5] is not "0" and part[6] is not "0":
178
+                        if lastLine is "":
179
+                            lastLine = line
140 180
                         count += 1
141
-                        color=networkSurveyColor(part[9])
142
-                        jsLine="  L.circle(["+part[5]+","+part[6]+"],{color: '"+color+"', fillcolor: '"+color+"', fillOpacity: "+str(circleOpacity)+", radius:XXXX}).addTo(mymap);\n"
181
+                        if count > latest:
182
+                            break
183
+                        #color=networkSurveyColor(part[9])
184
+                        color=networkSurveyColor(part[10])
185
+                        #jsLine="  L.circle(["+part[5]+","+part[6]+"],{color: '"+color+"', fillcolor: '"+color+"', fillOpacity: "+str(circleOpacity)+", radius:XXXX}).addTo(mymap); //"+part[2]+"\n"
186
+                        jsLine="  L.circle(["+part[5]+","+part[6]+"],{color: '"+color+"', fillcolor: '"+color+"', fillOpacity: "+str(circleOpacity)+", radius:"+str(part[7])+"}).addTo(mymap); //"+part[2]+" "+part[9]+" "+part[10]+"\n"
143 187
                         if float(part[5]) > latMax:
144 188
                             latMax=float(part[5])
145 189
                         if float(part[5]) < latMin:
... ...
@@ -208,17 +252,19 @@ def networkSurvey(filename, subId, devEUI = None, fileOutput= True):
208 252
     deltaTime = float(int(100*(time.time() - start_time)))/100
209 253
     htmlOutput+="<p>Took: "+str(deltaTime)+" seconds</p>\n"
210 254
 
255
+    lastOutput="<p>\n"
211 256
     if countRaw != 0:
212
-        #print(lastLine)
213 257
         part=lastLine.split(',')
214
-        lastOutput="<p>\n"
215
-        lastOutput+="<div id=\"deveui\">"+part[1]+"</div>\n"
216
-        lastOutput+="<div id=\"fcnt\">"+part[4]+"</div>\n"
217
-        lastOutput+="<div id=\"time\">"+part[2]+"</div>\n"
218
-        lastOutput+="<div id=\"position\">"+part[5]+" "+part[6]+" "+part[7]+"</div>\n"
219
-        lastOutput+="<div id=\"reload\"><button class=\"btn-green\" onClick=\"window.location.reload();\">Reload</div>\n"
220
-        lastOutput+="</p>\n"
221
-        htmlOutput+=lastOutput
258
+        try:
259
+            lastOutput+="<div id=\"deveui\">"+part[1]+"</div>\n"
260
+            lastOutput+="<div id=\"fcnt\">"+part[4]+"</div>\n"
261
+            lastOutput+="<div id=\"time\">"+part[2]+"</div>\n"
262
+            lastOutput+="<div id=\"position\">"+part[5]+" "+part[6]+" "+part[7]+"</div>\n"
263
+        except:
264
+            pass
265
+    lastOutput+="<div id=\"reload\"><button class=\"btn-green\" onClick=\"window.location.reload();\">Reload</div>\n"
266
+    lastOutput+="</p>\n"
267
+    htmlOutput+=lastOutput
222 268
 
223 269
     htmlOutput+="</body>\n"
224 270
     htmlOutput+="</html>\n"
+33 -21
mqttGeo.py
... ...
@@ -145,12 +145,12 @@ def on_message(client, userdata, msg):
145 145
                 except:
146 146
                     #warn("GPS Timeout")
147 147
                     warn("UL ID: "+parseTopic[1]+" D: "+parseTopic[3]+" F: "+str(FCnt)+" Type: "+messageType+" GPS Timeout")
148
-                    htmlLatest(parseTopic[3],parseTopic[1],FCnt,parsed['DevEUI_uplink']['Time'],lat,lon,err,parsed['DevEUI_uplink']['LrrRSSI'],"GPS TImeout or Non-GPS position")
148
+                    htmlLatest(parseTopic[3],parseTopic[1],FCnt,parsed['DevEUI_uplink']['Time'],lat,lon,err,parsed['DevEUI_uplink']['LrrSNR'],"GPS TImeout or Non-GPS position")
149 149
                     return
150 150
             else:
151 151
                 isPosition=False
152 152
                 say("UL ID: "+parseTopic[1]+" D: "+parseTopic[3]+" F: "+str(FCnt)+" Type: "+messageType)
153
-                htmlLatest(parseTopic[3],parseTopic[1],FCnt,parsed['DevEUI_uplink']['Time'],lat,lon,err,parsed['DevEUI_uplink']['LrrRSSI'],messageType)
153
+                htmlLatest(parseTopic[3],parseTopic[1],FCnt,parsed['DevEUI_uplink']['Time'],lat,lon,err,parsed['DevEUI_uplink']['LrrSNR'],messageType)
154 154
                 return
155 155
         else:
156 156
             isPosition=False
... ...
@@ -170,11 +170,10 @@ def on_message(client, userdata, msg):
170 170
         #LrrSNR
171 171
         count=0
172 172
         rssi=100
173
+        rssi=parsed['DevEUI_uplink']['LrrSNR']
173 174
         for lrr in parsed['DevEUI_uplink']['Lrrs']['Lrr']:
174 175
             count+=1
175 176
             #print(lrr['Lrrid'])
176
-            if rssi == 100:
177
-                rssi=lrr['LrrRSSI']
178 177
             csvLine+=","+lrr['Lrrid']+","+str(lrr['LrrRSSI'])+","+str(lrr['LrrSNR'])
179 178
         i = 0
180 179
         for i in range(count,MAXLRR):
... ...
@@ -235,7 +234,7 @@ def httpDevEuiList(subId):
235 234
     content += "<li><a href=\"?subId="+subId+"\">All</a></li>\n"
236 235
 
237 236
     for devEui in devEuiList:
238
-        content += "<li><a href=\"?subId="+subId+"&devEUI="+devEui+"\">"+devEui+"</a></li>\n"
237
+        content += "<li><a href=\"?subId="+subId+"&devEUI="+devEui+"\">"+devEui+"</a> Last <a href=\"?subId="+subId+"&devEUI="+devEui+"&latest=10\">10</a> <a href=\"?subId="+subId+"&devEUI="+devEui+"&latest=100\">100</a>  <a href=\"?subId="+subId+"&devEUI="+devEui+"&latest=1000\">1k</a></li>\n"
239 238
 
240 239
 
241 240
     content += "</ul>"
... ...
@@ -297,6 +296,33 @@ class MyServer(BaseHTTPRequestHandler):
297 296
             data_end += fEnd.read().replace( 'CSTAPPNAME', server['name'] ).replace( 'CSTAPPVERSION', server['version'] )
298 297
             fEnd.close()
299 298
 
299
+        # Parse URI params
300
+        if "?" in self.path:
301
+            uriObject = urlparse(self.path)
302
+            queries = uriObject.query.split('&')
303
+            uriParams = {} 
304
+
305
+            data_page = "" 
306
+            for query in queries:
307
+                element=query.split("=")
308
+                uriParams[element[0]]=element[1]
309
+
310
+        latestNum = 0
311
+        try:
312
+            subId=uriParams['subId']
313
+        except:
314
+            subId=None
315
+
316
+        try:
317
+            devEUI=uriParams['devEUI']
318
+        except:
319
+            devEUI=None
320
+
321
+        try:
322
+            latestNum=uriParams['latest']
323
+        except:
324
+            latestNum=0
325
+
300 326
         if "/favicon.png" in self.path or "/style.css" in self.path:
301 327
             splitPath=self.path.split('/')
302 328
             localFilename=splitPath[len(splitPath)-1]
... ...
@@ -385,29 +411,15 @@ class MyServer(BaseHTTPRequestHandler):
385 411
             self.wfile.write(content.encode('utf-8'))
386 412
             
387 413
         elif "/?" in self.path:
388
-            uriObject = urlparse(self.path)
389
-            queries = uriObject.query.split('&')
390
-            uriParams = {} 
391
-
392
-            data_page = "" 
393
-            for query in queries:
394
-                element=query.split("=")
395
-                uriParams[element[0]]=element[1]
396
-
397
-            subId=uriParams['subId']
398
-            try:
399
-                devEUI=uriParams['devEUI']
400
-            except:
401
-                devEUI=None
402 414
 
403 415
             data_page += "<p><div id=\"home\"><button class=\"btn-green-menu\" onClick=\"window.location.href='.';\">Home</div>\n"
404 416
             data_page += "<div id=\"latest\"><button class=\"btn-green-menu\" onClick=\"window.location.href='./last';\">Latest</div>\n"
405 417
             data_page += "<div id=\"log\"><button class=\"btn-green-menu\" onClick=\"window.location.href='./log';\">Log</div>\n"
406 418
 
407 419
             if subId is not None and devEUI is None:
408
-                data_page += csv2geojs.networkSurvey(server['rawCsv'], subId, fileOutput=False)
420
+                data_page += csv2geojs.networkSurvey(server['rawCsv'], subId, fileOutput=False, latestRecords=latestNum)
409 421
             elif subId is not None and devEUI is not None:
410
-                data_page += csv2geojs.networkSurvey(server['rawCsv'], subId, devEUI, fileOutput=False)
422
+                data_page += csv2geojs.networkSurvey(server['rawCsv'], subId, devEUI, fileOutput=False, latestRecords=latestNum)
411 423
             data_page += httpDevEuiList(subId)
412 424
 
413 425
             page.append(data_begin)