mob41 / broadlink-java-api

A clean Broadlink API for Java
MIT License
22 stars 25 forks source link

A1 Sensors information are not being successfully retrieved #5

Closed javieu closed 6 years ago

javieu commented 6 years ago

Hi, sorry if this is not the proper way to raise this question; I have downloaded and tested your project (BTW congrats and thanks!) but I am obtaining weird data from A1 sensor after a succesful auth:

EnvironmentalSensorRaw [temperature=-82.2, humidity=53.8, light=-28, airquality=3, noise=-73]

And basically I am getting always exactly same values.

Is EnvironmentalSensorRaw -> getTemperature() supposed to return a Celsius temperature?

I must first confess I have never coded a line of Python, but in the mjg59 python-broalink library, I see that in A1 the payload is decrypted using this code:

payload = self.decrypt(bytes(response[0x38:]))

While in your code it is like this:

byte[] pl = aes.decrypt(data);

I am not sure what bytes(response[0x38:]) does, but is this equivalent?

Thanks in advance :) I am available if you do not own a A1 device and want me to do any kind of test.

Best regards and thank U!

mob41 commented 6 years ago

Hi,

At first, this library is currently alpha and unstable. I currently noticed we are getting invalid RM2 temperature sometimes. Thank you for telling me about the A1 device also, I will take a look for this within this week.

The code response[0x38:] gets the data/bytes from the offset 0x38 to the end of the array. I have implemented a method to do this in Java. BLDevice.subbytes()

There is a way to trigger debug logs in your application:

Please download the slf4j simplelogger.properties file located in broadlink-java-api/src/test/resources and put it nearby your application or add it to the class-path.

And run your application in a console environment. Like command prompt or terminal.

Post your logs afterwards. Thank you for your help!

javieu commented 6 years ago

Hi, thanks for the quick response... I can give you some feedback. After replace the line: byte[] pl = aes.decrypt(data);

By this one:

byte[] pl = aes.decrypt(chgLen(subbytes(data, 56, 1024), 1024));

I am getting correct results (the same as the Broadlink app) :)