blob: a2b3657db952203d6ea62a92660c254a927d756e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#!/usr/bin/env python
import sys
import requests
import serial
import random
import datetime
import time
battery_capacity = requests.get("http://wollinuc.local:5000/stats").json()['capa']
def eat(ser):
time.sleep(1)
received = []
while True:
dat = ser.read(1)
if dat:
received.append(dat)
else:
break
return b''.join(received)
now = datetime.datetime.utcnow()
#this script gets called every hour at minutes 13,27,39,53
if battery_capacity < 6000:
print(f"Bat cap not enough: {battery_capacity}")
elif battery_capacity < 10000 and now.minute != 13:
print(f"Bat cap not low: {battery_capacity}")
else:
tx_freq = 10138700 + 400 + random.randint(1410, 1490)
print(f"TX freq {tx_freq}")
serial = serial.Serial("/dev/serial/by-id/usb-HB9EGM_Beep_Machine_1-if00", 115200, timeout=0)
serial.write('f{}\n'.format(tx_freq).encode("ascii"))
print(f"Answer: {eat(serial)}")
while True:
now = datetime.datetime.utcnow()
if now.minute % 2 == 0 and now.second == 00:
break
time.sleep(0.1)
print(f"{now} TX")
serial.write(b'wspr\n')
print(f"Answer: {eat(serial)}")
|