max-christian / homebridge-texecom

A plugin for homebridge (https://github.com/nfarina/homebridge) to integrate Texecom Premier Elite zones into HomeKit
MIT License
28 stars 8 forks source link

Weird Issue with strings from Texecom #20

Open benepixx opened 4 years ago

benepixx commented 4 years ago

So Sometimes (rarely) i'll get an accepted command which comes through as ZXXX1 or ZXXX0, but most of the time texecom is sending a pre-fix as follows:

[8/1/2020, 6:40:45 PM] [Texecom] IP data received: t4w"Z0061

[8/1/2020, 6:40:45 PM] [Texecom] Unknown string from Texecom: t4w"Z0061

Which results in it not understanding which zone it is, most of the time it begins with a t but the 2nd & 3rd character is variabale. eg. t.2"Z0051.

Any Ideas?

benepixx commented 4 years ago

Just to follow up - when connected directly to the IP com in a TCP session the data looks like this? t:³"Z0061 t; "Z0060 t<Ç"Z0061 t=•"Z0031 t>n"Z0060 t?ý"Z0061 t@Ú"Z0030

Ive looked at the code and this isn't expected behaviour. I changed "Startswith" "Z to "contains" which got me half way there but i can't chomp left as the characters aren't consistent. any ideas?

benepixx commented 4 years ago

Fixed it: If anyone is interested/ has the same issue - I'm guessing to do with firmware of the Texecom Panel - here's the code you need to edit - i just changed the way the code processes the strings - this method should be backwards compatible too as it crops all the string including the Z using the between function.

function processData(data) { // Received data is a zone update if(S(data).contains('"Z')){

            // Extract the data from the serial line received
            var zone_data = Number(S(S(data).between('Z')).left(4).s);
            // Extract the zone number that is being updated
            var updated_zone = Number(S(S(data).between('Z')).left(3).s);
            // Is the zone active?
            var zone_active = S(zone_data).endsWith('1');

            platform.log("Zone update received for zone " + updated_zone + " active: " + zone_active);