Add bosminer API module
This commit is contained in:
parent
127c6ef91c
commit
ad34a4b2d2
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -101,3 +101,5 @@ ENV/
|
||||||
# Editor
|
# Editor
|
||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
|
|
||||||
|
out.txt
|
||||||
|
|
41
bosminer.py
Normal file
41
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()
|
Loading…
Reference in New Issue
Block a user