Send Raw Command problem
Posted: Fri Mar 17, 2023 9:45 am
Hi all,
I'm trying to send a Turn On signal to a Nexa receiver using the Raw command method. I've created a Python script that generates a (what I believe) correct raw message string (Python snippet below - I've attached the code as attachment for those interested):
(Needless to say, the Python string generator is a Python rewrite of the ProtocolNexa.cpp's methods getStringSelflearning and getStringSelflearningForCode.)
Then I go on sending this as follows:
As you can see above, it doesn't work - I haven't been able to find out any more details as to why. After several verifications of the message string I tried to send it using tdtool:
As you can see: It says success - BUT the receiver doesn't react on the signal (i.e. the lamp stays off). If I use the standard functionality (i.e. tdtool --on 21), the lamp turns on as expected.
Would anyone be able to help me find out what's wrong? I've done some extensive browsing in various forums (especially this one, obviously), and this seems like a tricky topic, though I believe it should work.
Regards and thanks beforehand,
Roger
PS. I couldn't upload any file,regardless of extension, so I paste getRawCommand code here below:
I'm trying to send a Turn On signal to a Nexa receiver using the Raw command method. I've created a Python script that generates a (what I believe) correct raw message string (Python snippet below - I've attached the code as attachment for those interested):
Code: Select all
>>> c = getRawCommand(13786098, 3, const.TELLSTICK_TURNOFF)
>>> c
u'T\x7f\xff\x18\x01\x84\x9a\x8a\x88\xa8\xaa\x88\xaa\x8a\x88\xaa\x8a\x88\xaa\x88\xa8\xaa\x88\xa8\xa8\xa8\xa8\xa8\xaa\x8a\x88\xaa\x8a\x8a\x8a\x8a\x88\xaa\x8a+'
Then I go on sending this as follows:
Code: Select all
>>> from tellcore.telldus import TelldusCore
>>> import tellcore.constants as const
>>> core = TelldusCore()
>>> core.send_raw_command(c)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/tellcore/telldus.py", line 253, in send_raw_command
return self.lib.tdSendRawCommand(command, reserved)
File "/usr/local/lib/python2.7/dist-packages/tellcore/library.py", line 257, in check_int_result
raise TelldusError(result)
tellcore.library.TelldusError: Could not connect to the Telldus Service (-6)
Code: Select all
echo -ne 'T\x7f\xff\x18\x01\x84\x9a\x8a\x88\xa8\xaa\x88\xaa\x8a\x88\xaa\x8a\x88\xaa\x88\xa8\xaa\x88\xa8\xa8\xa8\xa8\xa8\xaa\x8a\x88\xaa\x8a\x8a\x8a\x8a\x88\xaa\x8a+' | tdtool --raw -
Sending raw command: Success
Would anyone be able to help me find out what's wrong? I've done some extensive browsing in various forums (especially this one, obviously), and this seems like a tricky topic, though I believe it should work.
Regards and thanks beforehand,
Roger
PS. I couldn't upload any file,regardless of extension, so I paste getRawCommand code here below:
Code: Select all
def getRawCommand(house, unit, method, level = 0):
# Input
houseInt = int(house)
codeInt = int(unit)-1
levelInt = int(level)
# Initial
command = u''
startSeq = u'T' + unichr(127) + unichr(255) + unichr(24) + unichr(1)
command += startSeq
if method == const.TELLSTICK_DIM:
command += unichr(147)
else:
command += unichr(132)
# m: House
m = ''
for i in reversed(range(26)):
if houseInt & 1 << i == 0:
m += '01'
else:
m += '10'
m += '01'
# m: Handle on/off/dim
if method == const.TELLSTICK_DIM:
m += '00'
elif method == const.TELLSTICK_TURNOFF:
m += '01'
elif method == const.TELLSTICK_TURNON:
m += '10'
else:
return ''
# m: Code (Unit)
for i in reversed(range(4)):
if codeInt & 1 << i == 0:
m += '01'
else:
m += '10'
# m: Dim Level
if method == const.TELLSTICK_DIM:
newLevel = levelInt / 16
for i in reversed(range(4)):
if newLevel & 1 << i == 0:
m += '01'
else:
m += '10'
# m: Make even last index
m += '0'
# Add m to command
code = 9
for i in range(len(m)):
code <<= 4
if m[i] == '1':
code |= 8 # b1000
else:
code |= 10 # b1010
if i % 2 == 0:
command += unichr(code)
code = 0
# Final
command += u'+'
return command