Created
February 18, 2015 10:31
-
-
Save shenki/12572aec0173e1c9008c to your computer and use it in GitHub Desktop.
uAvaNut Parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2 | |
# Joel Stanley <joel@jms.id.au> | |
# Apache 2.1 | |
import math | |
# Hard coded start location | |
start_lon = -34.92454 | |
start_lat = 138.60033 | |
# From http://stackoverflow.com/a/4913653 | |
def haversine(lon1, lat1, lon2, lat2): | |
""" | |
Calculate the great circle distance between two points | |
on the earth (specified in decimal degrees) | |
""" | |
# convert decimal degrees to radians | |
lon1, lat1, lon2, lat2 = map(math.radians, [lon1, lat1, lon2, lat2]) | |
# haversine formula | |
dlon = lon2 - lon1 | |
dlat = lat2 - lat1 | |
a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2 | |
c = 2 * math.asin(math.sqrt(a)) | |
r = 6371 # Radius of earth in kilometers. Use 3956 for miles | |
return c * r | |
nums = [] | |
dist = [] | |
with open('log.txt') as fh: | |
for line in fh.readlines(): | |
if line.count("Current RSSI: "): | |
nums.append(int(line.split(":")[1])) | |
if line.count("Got Packet: $$LORA1"): | |
lon = float(line.split(",")[3]) | |
lat = float(line.split(",")[4]) | |
dist.append(haversine(start_lon, start_lat, lon, lat) * 1000) | |
import matplotlib.pyplot as plt | |
import numpy as np | |
fig, ax1 = plt.subplots() | |
ax1.plot(nums) | |
ax1.set_ylabel('RSSI (dBm)') | |
step = int(len(nums)/len(dist)) | |
ax2 = ax1.twinx() | |
x = np.arange(0.0, len(nums), step)[:-1] | |
ax2.plot(x, dist, 'r-') | |
ax2.set_ylabel('Distance from base (m)') | |
plt.title("RSSI for Mark's walk to the shop") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment