mac-zhou / midea-msmart

This is a library to allow communicating to a Midea AC via the Local area network.
MIT License
151 stars 38 forks source link

padding is incorrect #11

Closed seppe912 closed 4 years ago

seppe912 commented 4 years ago
15.06 15:26 msmart.cli   INFO     Discovering devices with UDP Broadcast
15.06 15:26 msmart.security ERRORaes_decrypt error: ValueError('Padding is incorrect.') - data: 0000000000000000b2c65aa3bf842cf537a3cf07dda75ce37ea68da00601c5f2f7d7a54947ac851233f45f1784c5bb1f661a21549e00596c8ad99d4f22407a12

Hi Mac-zhou. i got one user that has this error on UDP broadcast. you know whats wrong?

mac-zhou commented 4 years ago

run midea-discover -d to get more log

seppe912 commented 4 years ago

discover:

16.06 21:03 msmart.cli   INFO     Debug mode active
16.06 21:03 msmart.cli   INFO     Discovering devices with UDP Broadcast
16.06 21:03 msmart.security ERROR    aes_decrypt error: ValueError('Padding is incorrect.') - data: 0000000000000000d6c6ae4af516487d1cacc4ebba58f7cd7ea68da00601c5f2f7d7a54947ac8512d896a9be716fe3d6fa74c5e7430525f15d9fb6354cf5d1a8
16.06 21:03 __main__     ERROR    (<class 'SystemExit'>, SystemExit(), <traceback object at 0x75f9a968>)

try to apply() (with my pyton script):

16.06 21:16 __main__     DEBUG    False
16.06 21:16 __main__     DEBUG    True
16.06 21:16 __main__     DEBUG    28
16.06 21:16 __main__     DEBUG    ac.operational_mode_enum.auto
16.06 21:16 __main__     DEBUG    ac.fan_speed_enum.Auto
16.06 21:16 __main__     DEBUG    ac.swing_mode_enum.Horizontal
16.06 21:16 __main__     DEBUG    False
16.06 21:16 __main__     DEBUG    False
16.06 21:16 __main__     DEBUG    19791209317067
16.06 21:16 __main__     DEBUG    192.168.2.50
16.06 21:16 msmart.packet_builder DEBUG    add packet_time
16.06 21:16 msmart.packet_builder DEBUG    Finalize request data: aa23ac0000000000000240c22c6603ff0003000000000000000000000000300000008adc
16.06 21:16 msmart.lan   DEBUG    Sending to 192.168.2.50:6444 5a5a011168002000000000002a30101510061414cb420000001200000000000000000000000000009b5bf38cc78d3253e56be205d5753062b9a7000a54a01df6b6258a8709a5b0ff865fbd4b989cf275ffcf93f2ba34e67c708856f769ff86e871534ada009d0401.
16.06 21:16 msmart.lan   ERROR    (<class 'socket.timeout'>, timeout('timed out'), <traceback object at 0x75f39058>)
16.06 21:16 msmart.lan   INFO     wait 10 seconds, and retry
16.06 21:17 msmart.lan   INFO     retry 1/10 @ 192.168.2.50:6444 
16.06 21:17 msmart.lan   DEBUG    Sending to 192.168.2.50:6444 5a5a011168002000000000002a30101510061414cb420000001200000000000000000000000000009b5bf38cc78d3253e56be205d5753062b9a7000a54a01df6b6258a8709a5b0ff865fbd4b989cf275ffcf93f2ba34e67c708856f769ff86e871534ada009d0401.
16.06 21:17 msmart.lan   ERROR    (<class 'socket.timeout'>, timeout('timed out'), <traceback object at 0x75f39620>)
16.06 21:17 msmart.lan   INFO     wait 10 seconds, and retry
16.06 21:17 msmart.lan   INFO     retry 2/10 @ 192.168.2.50:6444 
16.06 21:17 msmart.lan   DEBUG    Sending to 192.168.2.50:6444 5a5a011168002000000000002a30101510061414cb420000001200000000000000000000000000009b5bf38cc78d3253e56be205d5753062b9a7000a54a01df6b6258a8709a5b0ff865fbd4b989cf275ffcf93f2ba34e67c708856f769ff86e871534ada009d0401.
16.06 21:17 msmart.lan   ERROR    (<class 'socket.timeout'>, timeout('timed out'), <traceback object at 0x75f396c0>)
16.06 21:17 msmart.lan   INFO     wait 10 seconds, and retry
16.06 21:17 msmart.lan   INFO     retry 3/10 @ 192.168.2.50:6444 
16.06 21:17 msmart.lan   DEBUG    Sending to 192.168.2.50:6444 5a5a011168002000000000002a30101510061414cb420000001200000000000000000000000000009b5bf38cc78d3253e56be205d5753062b9a7000a54a01df6b6258a8709a5b0ff865fbd4b989cf275ffcf93f2ba34e67c708856f769ff86e871534ada009d0401.
16.06 21:17 msmart.lan   ERROR    (<class 'socket.timeout'>, timeout('timed out'), <traceback object at 0x75f39710>)
16.06 21:17 msmart.lan   INFO     wait 10 seconds, and retry
16.06 21:18 msmart.lan   INFO     retry 4/10 @ 192.168.2.50:6444 
16.06 21:18 msmart.lan   DEBUG    Sending to 192.168.2.50:6444 5a5a011168002000000000002a30101510061414cb420000001200000000000000000000000000009b5bf38cc78d3253e56be205d5753062b9a7000a54a01df6b6258a8709a5b0ff865fbd4b989cf275ffcf93f2ba34e67c708856f769ff86e871534ada009d0401.
16.06 21:18 msmart.lan   ERROR    (<class 'socket.timeout'>, timeout('timed out'), <traceback object at 0x75f39760>)
16.06 21:18 msmart.lan   INFO     wait 10 seconds, and retry
16.06 21:18 msmart.lan   INFO     retry 5/10 @ 192.168.2.50:6444 
16.06 21:18 msmart.lan   DEBUG    Sending to 192.168.2.50:6444 5a5a011168002000000000002a30101510061414cb420000001200000000000000000000000000009b5bf38cc78d3253e56be205d5753062b9a7000a54a01df6b6258a8709a5b0ff865fbd4b989cf275ffcf93f2ba34e67c708856f769ff86e871534ada009d0401.
16.06 21:18 msmart.lan   ERROR    (<class 'socket.timeout'>, timeout('timed out'), <traceback object at 0x75f39508>)
16.06 21:18 msmart.lan   INFO     wait 10 seconds, and retry
16.06 21:18 msmart.lan   INFO     retry 6/10 @ 192.168.2.50:6444 
16.06 21:18 msmart.lan   DEBUG    Sending to 192.168.2.50:6444 5a5a011168002000000000002a30101510061414cb420000001200000000000000000000000000009b5bf38cc78d3253e56be205d5753062b9a7000a54a01df6b6258a8709a5b0ff865fbd4b989cf275ffcf93f2ba34e67c708856f769ff86e871534ada009d0401.
16.06 21:18 msmart.lan   ERROR    (<class 'socket.timeout'>, timeout('timed out'), <traceback object at 0x75f39378>)
16.06 21:18 msmart.lan   INFO     wait 10 seconds, and retry
16.06 21:18 msmart.lan   INFO     retry 7/10 @ 192.168.2.50:6444 
16.06 21:19 msmart.lan   DEBUG    Sending to 192.168.2.50:6444 5a5a011168002000000000002a30101510061414cb420000001200000000000000000000000000009b5bf38cc78d3253e56be205d5753062b9a7000a54a01df6b6258a8709a5b0ff865fbd4b989cf275ffcf93f2ba34e67c708856f769ff86e871534ada009d0401.
16.06 21:19 msmart.lan   ERROR    (<class 'socket.timeout'>, timeout('timed out'), <traceback object at 0x75f397b0>)
16.06 21:19 msmart.lan   INFO     wait 10 seconds, and retry
16.06 21:19 msmart.lan   INFO     retry 8/10 @ 192.168.2.50:6444 
16.06 21:19 msmart.lan   DEBUG    Sending to 192.168.2.50:6444 5a5a011168002000000000002a30101510061414cb420000001200000000000000000000000000009b5bf38cc78d3253e56be205d5753062b9a7000a54a01df6b6258a8709a5b0ff865fbd4b989cf275ffcf93f2ba34e67c708856f769ff86e871534ada009d0401.
16.06 21:19 msmart.lan   ERROR    (<class 'socket.timeout'>, timeout('timed out'), <traceback object at 0x75f393f0>)
16.06 21:19 msmart.lan   INFO     wait 10 seconds, and retry
16.06 21:19 msmart.lan   INFO     retry 9/10 @ 192.168.2.50:6444 
16.06 21:19 msmart.lan   DEBUG    Sending to 192.168.2.50:6444 5a5a011168002000000000002a30101510061414cb420000001200000000000000000000000000009b5bf38cc78d3253e56be205d5753062b9a7000a54a01df6b6258a8709a5b0ff865fbd4b989cf275ffcf93f2ba34e67c708856f769ff86e871534ada009d0401.
16.06 21:19 msmart.lan   ERROR    (<class 'socket.timeout'>, timeout('timed out'), <traceback object at 0x75f39440>)
16.06 21:19 __main__     ERROR    (<class 'SystemExit'>, SystemExit('Socket Error! Please Check your IP and ID from the AC and that your AC is connected to your Router'), <traceback object at 0x75f29850>)

i´ve changed in my script your code from (security.py):

        except ValueError as e:
            _LOGGER.error(
                "aes_decrypt error: {} - data: {}".format(repr(e), raw.hex()))
            return bytearray(0)

to

        except ValueError as e:
            _LOGGER.error(
                "aes_decrypt error: {} - data: {}".format(repr(e), raw.hex()))
            import sys
            sys.exit()

as well in lan.py from:

        except socket.timeout:
            _LOGGER.info("Connect the Device %s:%s TimeOut for 10s. don't care about a small amount of this. if many maybe not support." % (
                self.device_ip, self.device_port))
            return bytearray(0)

to

        except socket.error or socket.timeout:
            self._retries += 1
            print(str(sys.exc_info()))
            _LOGGER.error(str(sys.exc_info()))
            if(self._retries < 10):
                _LOGGER.info("wait 10 seconds, and retry")
                time.sleep(10) #give it some time
                _LOGGER.info("retry %s/10 @ %s:%s " %(self._retries, self.device_ip, self.device_port))
                return self.request(message)
            else:
                sys.exit("Socket Error! Please Check your IP and ID from the AC and that your AC is connected to your Router")

because with bytearray(0) there will be no error given back to my python script and it will end succesfull. maybe this is the root cause? But this code works for my Climate. Just another user from my Script has this problem as in the logs above.

mac-zhou commented 4 years ago

This just means that my library does not support your device. If it is supported, the device will respond within 10 seconds.

mac-zhou commented 4 years ago

new version 0.1.19 fix "Padding is incorrect"