Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issues and added ehancement #2

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions python/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
root@loraserver01:/home/lora/raktester# cat Dockerfile
FROM python:3.10-alpine3.17

##uncomment to add proxy
#ENV HTTPS_PROXY http://username:password@proxy:port
#ENV HTTP_PROXY http://username:password@proxy:port

WORKDIR /app
ADD server.py requirements.txt ./
RUN pip install -r requirements.txt
RUN pip install "cython<3.0.0" && pip install --no-build-isolation pyyaml==6.0

CMD ["python", "server.py"]
2 changes: 1 addition & 1 deletion python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

init:
test -d .env || virtualenv .env
. .env/bin/activate ; pip install -Ur requirements.txt
. .env/bin/activate ; pip install -Ur requirements.txt; pip install "cython<3.0.0" && pip install --no-build-isolation pyyaml==6.0

run:
set -e ; . .env/bin/activate ; python3 server.py
Expand Down
3 changes: 2 additions & 1 deletion python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ future==0.18.2
iso8601==1.1.0
paho-mqtt==1.6.1
pyparsing==3.0.9
PyYAML==6.0
setuptools
#PyYAML==6.0
52 changes: 32 additions & 20 deletions python/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,17 @@ def process(data, port, sequence_id, gateways):
encLon = ((data[3] & 0x7f)<<16) + (data[4]<<8) + data[5]
hdop = data[8]/10
sats = data[9]
min_distance = 0
max_distance = 0

# Send only acceptable quality of position to mappers
if (hdop > 2) or (sats < 5):
return False
# # Send only acceptable quality of position to mappers
# if (hdop > 2) or (sats < 5):
# return False

# Gather data
output = {
## if no sats then only publish SQ
if (hdop > 2) or (sats < 5):
output = {
'latitude': latSign * (encLat * 108 + 53) / 10000000,
'longitude': lonSign * (encLon * 215 + 107) / 10000000,
'altitude': ((data[6]<<8) + data[7]) - 1000,
Expand All @@ -129,21 +133,28 @@ def process(data, port, sequence_id, gateways):
'min_rssi': MAX_RSSI,
'max_rssi': MIN_RSSI
}
else:
output = {
'num_gateways': len(gateways),
'min_rssi': MAX_RSSI,
'max_rssi': MIN_RSSI
}

for gateway in gateways:

output['min_rssi'] = min(output['min_rssi'], gateway.get('rssi', MAX_RSSI));
output['max_rssi'] = max(output['max_rssi'], gateway.get('rssi', MIN_RSSI));
if (hdop > 2) or (sats < 5):
for gateway in gateways:
output['min_rssi'] = min(output['min_rssi'], gateway.get('rssi', MAX_RSSI));
output['max_rssi'] = max(output['max_rssi'], gateway.get('rssi', MIN_RSSI));
if 'location' in gateway:
distance = int(circleDistance(output, gateway['location']))
output['min_distance'] = min(output['min_distance'], distance)
output['max_distance'] = max(output['max_distance'], distance)

if 'location' in gateway:
distance = int(circleDistance(output, gateway['location']))
output['min_distance'] = min(output['min_distance'], distance)
output['max_distance'] = max(output['max_distance'], distance)

# Build response buffer
if 1 == port:
min_distance = constrain(int(round(output['min_distance'] / 250.0)), 1, 128)
max_distance = constrain(int(round(output['max_distance'] / 250.0)), 1, 128)
if (hdop > 2) or (sats < 5):
min_distance = constrain(int(round(output['min_distance'] / 250.0)), 1, 128)
max_distance = constrain(int(round(output['max_distance'] / 250.0)), 1, 128)
output['buffer'] = [
sequence_id % 256,
int(output['min_rssi'] + 200) % 256,
Expand All @@ -153,9 +164,10 @@ def process(data, port, sequence_id, gateways):
output['num_gateways'] % 256
]
elif 11 == port:
min_distance = constrain(int(round(output['min_distance'] / 10.0)), 1, 65535)
max_distance = constrain(int(round(output['max_distance'] / 10.0)), 1, 65535)
logging.debug("[TTS3] max_distance: %d" % max_distance)
if (hdop > 2) or (sats < 5):
min_distance = constrain(int(round(output['min_distance'] / 10.0)), 1, 65535)
max_distance = constrain(int(round(output['max_distance'] / 10.0)), 1, 65535)
logging.debug("[TTS3] max_distance: %d" % max_distance)
output['buffer'] = [
sequence_id % 256,
int(output['min_rssi'] + 200) % 256,
Expand Down Expand Up @@ -238,8 +250,8 @@ def parser_cs34(config, topic, payload):

# Process the data
data = process(data, port, sequence_id, gateways)
if not data:
return [False, False]
#if not data:
# return [False, False]
logging.debug("[CS34] Processed: %s" % data)

# Get topic
Expand Down Expand Up @@ -304,4 +316,4 @@ def mqtt_on_message(client, userdata, msg):
time.sleep(0.01)

if (__name__ == '__main__'):
main()
main()