Add bosminer API module

This commit is contained in:
Tanner Collin 2022-04-26 17:03:18 -06:00
parent 127c6ef91c
commit ad34a4b2d2
2 changed files with 43 additions and 0 deletions

2
.gitignore vendored
View File

@ -101,3 +101,5 @@ ENV/
# Editor
*.swp
*.swo
out.txt

41
bosminer.py Normal file
View 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()