Log Uniden close call hits with Python
Uniden remote command PWR returns frequency value 00000000 and background noise RSSI value when there is no CC hit. When Close Call found PWR returns frequency and RSSI values.
import serial
import pandas as pd
import matplotlib.pyplot as plt
import csv
from datetime import datetime
ser = serial.Serial('COM14', '115200', timeout = 0.5)
print(ser.name)
serialCmd = b'PWR\r'
readSize = 19
loop = True
freq = ""
rssi = 0
data = []
log_data = []
cc_data = []
cols = ['Frequency', 'RSSI', 'Timestamp']
plt.xlabel("Frequency")
plt.ylabel("RSSI")
try:
while (loop == True):
ser.write(serialCmd)
res = ser.read(readSize).decode()
if (len(res) > 15):
r = res.replace('\r', '').split(",")
freq = r[2]
rssi = int(r[1])
if freq == '00000000':
log_data.append([freq, rssi, datetime.now().strftime("%Y%m%d%H%M%S")])
else:
cc_data.append([freq, rssi, datetime.now().strftime("%Y%m%d%H%M%S")])
i = -1
b = False
for x in data:
i = i + 1
if (x[0] == freq):
data[i][1] = rssi
b = True
break
if (b == False):
data.append([freq, rssi])
df = pd.DataFrame(data, columns = ['Frequency', 'RSSI'])
df = df.sort_values("Frequency")
plt.clf()
plt.xticks(rotation = 90)
plt.bar('Frequency', 'RSSI', data = df)
plt.pause(0.03)
except KeyboardInterrupt:
loop = False
plt.close()
ser.close()
with open("c:\\temp\\background_noise_level.csv", 'w', newline = '') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(cols)
csvwriter.writerows(log_data)
with open("c:\\temp\\cc_hits.csv", 'w', newline = '') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(cols)
csvwriter.writerows(cc_data)
background_noise_level.csv
Frequency,RSSI,Timestamp
00000000,217,20250525195112
00000000,94,20250525195113
00000000,65,20250525195114
00000000,63,20250525195114
00000000,78,20250525195115
00000000,232,20250525195116
00000000,230,20250525195116
00000000,113,20250525195117
00000000,204,20250525195117
00000000,72,20250525195118
00000000,211,20250525195120
00000000,203,20250525195121
00000000,203,20250525195122
00000000,229,20250525195122
00000000,129,20250525195123
00000000,208,20250525195124
00000000,89,20250525195124
00000000,225,20250525195125
00000000,117,20250525195127
cc_hits.csv
Frequency,RSSI,Timestamp
04071500,242,20250525195145
04460062,593,20250525195155
04460062,590,20250525195156
04460062,230,20250525195156
04460062,232,20250525195157
04460187,588,20250525195209
04460187,587,20250525195209
04460187,587,20250525195210
04460187,222,20250525195211
04460187,226,20250525195211
04460187,229,20250525195212
Comments
Post a Comment