Compare commits
4 Commits
6c0054e72d
...
4a8d130c72
Author | SHA1 | Date | |
---|---|---|---|
4a8d130c72 | |||
ad34a4b2d2 | |||
127c6ef91c | |||
84a643e69c |
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -101,3 +101,5 @@ ENV/
|
|||
# Editor
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
out.txt
|
||||
|
|
41
rpiserver/bosminer.py
Normal file
41
rpiserver/bosminer.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
import asyncio
|
||||
import json
|
||||
|
||||
async def bosminer_cmd(host, command, param=None):
|
||||
reader, writer = await asyncio.open_connection(host, 4028)
|
||||
|
||||
payload = dict(command=command)
|
||||
if param:
|
||||
payload['parameter'] = param
|
||||
|
||||
message = json.dumps(payload)
|
||||
writer.write(message.encode())
|
||||
await writer.drain()
|
||||
data = await reader.readuntil(separator=b'\00')
|
||||
writer.close()
|
||||
await writer.wait_closed()
|
||||
|
||||
return data[:-1].decode()
|
||||
|
||||
async def test():
|
||||
import sys
|
||||
|
||||
if len(sys.argv) == 3:
|
||||
cmd = sys.argv[1]
|
||||
param = sys.argv[2]
|
||||
if len(sys.argv) == 2:
|
||||
cmd = sys.argv[1]
|
||||
param = None
|
||||
else:
|
||||
cmd = 'temps'
|
||||
param = None
|
||||
|
||||
res = await bosminer_cmd('192.168.69.4', cmd, param)
|
||||
j = json.loads(res)
|
||||
print(json.dumps(j, indent=4))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(test())
|
||||
loop.close()
|
37
rpiserver/requirements.txt
Normal file
37
rpiserver/requirements.txt
Normal file
|
@ -0,0 +1,37 @@
|
|||
aiofiles==0.8.0
|
||||
aiohttp==3.8.1
|
||||
aiosignal==1.2.0
|
||||
appdirs==1.4.4
|
||||
async-timeout==4.0.2
|
||||
attrs==21.4.0
|
||||
certifi==2020.6.20
|
||||
chardet==4.0.0
|
||||
charset-normalizer==2.0.12
|
||||
click==8.1.2
|
||||
colorzero==1.1
|
||||
dbus-python==1.2.16
|
||||
distlib==0.3.1
|
||||
distro==1.5.0
|
||||
distro-info==1.0
|
||||
filelock==3.0.12
|
||||
frozenlist==1.3.0
|
||||
gpiozero==1.6.2
|
||||
idna==2.10
|
||||
importlib-metadata==1.6.0
|
||||
more-itertools==4.2.0
|
||||
multidict==6.0.2
|
||||
PyGObject==3.38.0
|
||||
python-apt==2.2.1
|
||||
requests==2.25.1
|
||||
RPi.GPIO==0.7.0
|
||||
six==1.16.0
|
||||
spidev==3.5
|
||||
ssh-import-id==5.10
|
||||
supervisor==4.2.2
|
||||
ufw==0.36
|
||||
unattended-upgrades==0.1
|
||||
urllib3==1.26.5
|
||||
virtualenv==20.4.0+ds
|
||||
w1thermsensor==2.0.0
|
||||
yarl==1.7.2
|
||||
zipp==1.0.0
|
22
rpiserver/w1therm.py
Normal file
22
rpiserver/w1therm.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
import asyncio
|
||||
from w1thermsensor import AsyncW1ThermSensor, Unit
|
||||
|
||||
async def get_temperatures():
|
||||
temps = {}
|
||||
|
||||
for sensor in AsyncW1ThermSensor.get_available_sensors():
|
||||
temps[sensor.id] = await sensor.get_temperature()
|
||||
|
||||
return temps
|
||||
|
||||
async def test():
|
||||
temps = await get_temperatures()
|
||||
|
||||
for id_, temp in temps.items():
|
||||
print('sensor', id_, ':' , temp, 'C')
|
||||
|
||||
if __name__ == '__main__':
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(test())
|
||||
loop.close()
|
||||
|
Loading…
Reference in New Issue
Block a user