dib0 / elro_connects

The ELRO Connects uses a propriety protocol on the local network over UDP. This is the reversed engineered python implementation of the protocol.
MIT License
16 stars 7 forks source link

loosing device #18

Open adr1200c opened 2 years ago

adr1200c commented 2 years ago

my elro devices ( # 3 in total) are not always shown in the elro program publishing to MQTT broker.

Most of the time 2 only are seen.

When the connection on the fire alarm is reestablished ( push 3 times) to the elro connection hub the device is visible in the elro hub to MQTT again.

is it a known issue? is the elro_connects program capable of resetting device list . does it have a cache of devices?

depuits commented 2 years ago

Currently this app does not support the management of the elro network. There is an issue to implement the management of device names using the cli but currently there has no work been done to implement that. I remember reading some reviews of other users using the official app with the same issue so I guess it's an issue in the system/protocol.

Skons commented 2 years ago

The devices are now requested on connect with

msg = self.construct_message('{"cmdId":' + str(Command.SYN_DEVICE_STATUS.value) + ',"device_status":""}')

The app itself does this with (https://github.com/Siterwell/familywell-lidl-android/blob/6218fdd314a031c4745e71f101061065cc27bbfc/branch/lidl/app/src/main/java/me/hekr/sthome/service/SiterService.java#L811)

String crc = CoderUtils.getEqCRC(this, ConnectionPojo.getInstance().deviceTid);
sed.synGetDeviceStatus(crc);

The getEqCRC eventually does some magic on the State of the device, see https://github.com/Siterwell/familywell-lidl-android/blob/6218fdd314a031c4745e71f101061065cc27bbfc/branch/lidl/app/src/main/java/me/hekr/sthome/crc/CoderUtils.java#L186

This results in a json like this

{"msgId":1,"action":"appSend","params":{"devTid":"ST_xxxx","ctrlKey":"xxxx","data":{"cmdId":29,"device_status":"000e00000000xxxx00000000xxxx"}}}
000e 0000 0000 xxxx 0000 0000 xxxx
listlengthcalculated nonexistingdevice nonexistingdevice CRCMakerChar(devicestate) nonexistingdevice nonexistingdevice CRCMakerChar(devicestate)

It is not difficult to create the device status crc string (CRCMakerChar), the difficulty is; what is the data that should be there. It seems that the state is used because of this command allEquipmentInformation.get(eqid.indexOf(String.valueOf(i))).getState() but the state itself seems not to be device specific. If it is being used, i think that the last state should be remembered and used to get all device upon restart of the script. This could be done though through mqtt and the retain message flag. With this, no database should have to be created.

listlengthcalculated is Integer.toHexString(listLength*2+2). In this case the list is 6 and e == 14.

I already got a python implementation of CRCMakerChar (it looks a lot like the one i already reverse engineerd in https://github.com/dib0/elro_connects/pull/20).

I also dumped the database from my android app, the allEquipmentInformation eventually is constructed from information from the database, and the state database field (which i believe is used in the getState() function) is present as the device state in the database (0464AAXX).

Skons commented 2 years ago

To add to this, i do not understand how the listlength is 6, in my case there are only 2 devices

Skons commented 2 years ago

The 6 is the id of the device. The app does not use the number of devices as length, but the id of the last device. With this i can now hopefully implement the device discovery the same way the app does this and thus having all devices upon restart

Skons commented 2 years ago

PR #23 should have solved this issue, @adr1200c can you verify this?