Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command line #9

Open
zon2004 opened this issue May 11, 2020 · 2 comments
Open

command line #9

zon2004 opened this issue May 11, 2020 · 2 comments

Comments

@zon2004
Copy link

zon2004 commented May 11, 2020

Скажите пожалуйста, Возможна ли отправка и получение кодов с командной строки.
Использовал скрипт для отправки кода

#!/usr/bin/python3
import sys
import ipaddress
from typing import Any
from miio import ChuangmiIr,DeviceException
import time
ip = '192.168.x.x'
token = '6xxxxxxxxxxxxxxxxxxxxxxxxxxc'
f=open('codes.txt')
codeline=f.readlines()
id_aux = codeline[int(sys.argv[1])-1].split(" ")
id=id_aux[0]
ir = ChuangmiIr(ip,token)
ir.play_raw(id,frequency='')

Но пульты от сони он так не берет
Возможно что виноват скрипт получения кодов

#!/usr/bin/python3
import sys
import ipaddress
from typing import Any
from miio import ChuangmiIr,DeviceException
import time
import json
import os
import os.path
fichero ='./codes.txt'
ip= '192.168.x.x'
token = '6xxxxxxxxxxxxxxxxxxxxxxxxxxc'
try:
os.stat("codes.txt")
except:
file = open("codes.txt", "w")

num_lines = sum(1 for line in open('codes.txt'))
print ('Stored Ir Keys ->'+ str(num_lines) )
id = num_lines + 1
ir = ChuangmiIr(ip,token)

ir.learn(key=1)
time.sleep(10)
print (ir.read(key=1).get("code"))

with open('codes.txt', 'a') as file:
try:
file.write(ir.read(key=1).get("code")+ '\n')
except:
print('error')

Спасибо за любую помощь

@Whilser
Copy link
Owner

Whilser commented May 11, 2020

Дело не в скрипте. Есть подозрение, что посылка слишком длинная. Некоторые пользователи с этим сталкиваются. Но обычно родное приложение работает без особых проблем.

@zon2004
Copy link
Author

zon2004 commented May 11, 2020

Может Вы знаете как переделать пронто HEX код для передачи. возможно отослать получиться.
Видел такой скрипт, но не могу понять его работу

mport base64
import heatshrink2
import miio

def pronto_convert(pronto):
old_raw, freq = miio.ChuangmiIr.pronto_to_raw(pronto)
signal = miio.chuangmi_ir.ChuangmiIrSignal.parse(base64.b64decode(old_raw))
times = []
for pair in signal.edge_pairs:
times.append(signal.times_index[pair.pulse])
times.append(signal.times_index[pair.gap])
times = '{}\x00'.format(','.join(map(str, times)))
return f"raw:{base64.b64encode(heatshrink2.encode(times.encode())).decode()}:{freq}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants