-
-
Save PatrickHallek/3f800d0d39e740a3f955733a549011c3 to your computer and use it in GitHub Desktop.
import serial | |
import time | |
import datetime | |
import json | |
import redis | |
r = redis.Redis(host='localhost', port=6379, db=0) | |
DWM = serial.Serial(port="/dev/ttyACM0", baudrate=115200) | |
print("Connected to " + DWM.name) | |
DWM.write("\r\r".encode()) | |
print("Encode") | |
time.sleep(1) | |
DWM.write("lec\r".encode()) | |
print("Encode") | |
time.sleep(1) | |
try: | |
while True: | |
data = DWM.readline() | |
if(data): | |
print(data) | |
if ("DIST" in data and "AN0" in data and "AN1" in data and "AN2" in data): | |
data = data.replace("\r\n", "") | |
data = data.decode().split(",") | |
if("DIST" in data): | |
anchor_Nummber = int(data[data.index("DIST")+1]) | |
for i in range(anchor_Nummber): | |
pos_AN = {"id": data[data.index("AN"+str(i))+1], "x": data[data.index("AN"+str(i))+2], "y": data[data.index( | |
"AN"+str(i))+3], "dist": data[data.index("AN"+str(i))+5]} | |
pos_AN = json.dumps(pos_AN) | |
print(pos_AN) | |
r.set('AN'+str(i), pos_AN) | |
if("POS" in data): | |
pos = {"x": data[data.index("POS")+1], | |
"y": data[data.index("POS")+2]} | |
pos = json.dumps(pos) | |
print(pos) | |
r.set("pos", pos) | |
DWM.write("\r".encode()) | |
DWM.close() | |
except KeyboardInterrupt: | |
print("Stop") |
Thanks for your response. Actually, I want to implement the UWB network in which
we have the following scenario:
1.Configure Anchor Initiator including position coordinates
2.Configure additional anchors
3.Configure 1 tag
All devices should be in the same PAN(uwb network)
4.Configure one DWM1001-DEV Node as a Bridge node.
5.Configure the PAN ID of the Bridge node at /etc/dwm1001/dwm1001.config
6.connect an MQTT client to the Pi and subscribe to $SYS/# and dwm/# to know about tag location.
Can you suggest me how to proceed in a programming way??
Hey Patrick, this is all looking good but when it comes to running the code I get the following error:
Traceback (most recent call last):
File "/home/raspberry/Documents/projects/dwmTest.py", line 21, in
if ("DIST" in data and "AN0" in data and "AN1" in data and "AN2" in data):
TypeError: a bytes-like object is required, not 'str'
Any thoughts on solutions?
You need to install a redis database and run it on port 6379. After connecting the tag via USB to port /dev/ttyACM0 (on my pi), you can execute the code after installing python with
python dwm1001-localization.py
which will store/update the x and y positions into the redis database as json string to the key "pos".