gazoodle / geckolib

Library to interface with Gecko Alliance spa pack systems via in.touch2 module
GNU General Public License v3.0
60 stars 23 forks source link

Run time error: Spa took too long to connect #12

Closed eranjo closed 2 years ago

eranjo commented 3 years ago

Hi,

Not able to connect to my spa so attaching my log file in case it will help to identify the issue. Looking forward to get this up and running already in HA :)

I'd like to start tracking temperature change vs. weather forecast -> The idea is to set rules to get my spa heating started at the right time based on the time I want to go in.

"I want my spa ready @6pm" --> calculate heating time based on the data collected vs. temp or Turn heating off if pump 2 not used for x hours or Reset due reminders after pushing IoT button etc.

client.log

Thanks, eranjo

gazoodle commented 3 years ago

Thanks for the log file. Very useful.

Your spa identifies itself as a inYT and gives the config and log structure versions as 64 which don't exist in the latest (v19) SpaPackStruct.xml file as downloaded from Gecko.

This is why the spa fails to connect, it can't find any of the descriptors and so waits until it times out.

This prompts the thought that my assumption on how to interpret the packet command FILES,inYT_C64.xml,inYT_S64.xml may be wrong.

I'm not sure how to handle this.

1) Throw an exception - I've got a local change that does just this but that's not a lot of use to you.

2) Update the code to use the last smaller version of the structures, but issue a warning in the log file that this was done. This might result in something awful happening if we write to the wrong structure locations so I'm reluctant to do this without further investigation

Interestingly my iOS app is able to connect cleanly to the simulator with your data loaded so it obviously has a way to deal with that.

I'll keep this thread updated as I find out what is going on.

sicarriere commented 3 years ago

Hi @gazoodle

I think that the latest "SpaPackStruct" is now included directly in the IOS/Android APP, because when I check the "About" in my IOS APP, it said that it's using Version 28 of the SpaPackStruct. But I never find it on the web.

eranjo commented 3 years ago

My iOS app also shows spa pack structure 28 image

gazoodle commented 3 years ago

Whoa! Ok, then let’s dig it out of there then.

eranjo commented 3 years ago

Hi @gazoodle

Let me know if there's anything I can do to help. Reverse engineering is new to me so learning as we go. I even tried looking into the APK file with JadxGUI but couldn't find SpaPackStruct.xml nor any other trace. Well at least I learned something new while trying to figure out how to look inside APK if nothing else :) Now I at least have the png files to repeat the look and wheel in HA once we get there eventually.

gazoodle commented 3 years ago

I've dug SpaPackStruct.xml V24.00 out of the 2.7.2 version of the Android app ... I'll post the procedure here when I've cleaned it up.

Obviously I can't post the actual file, or add it to the repo as we don't have the rights to that data.

I might also start a dialog with Gecko to see if we can get them to update the version that is on their website, or open a developer API (which would obviously be the best for everyone). I have no idea what they are like as a company or what their ethos is like, but if massive companies like Philips with their Hue product have a really nice API for home automation, there is no reason that Gecko couldn't too.

For 2.7.4, the assemblies have been obfuscated by some tool I expect which will make it much harder to extract meaningful data from but ... well, if the processor running the app can read it, then so can another processor elsewhere.

gazoodle commented 3 years ago

My procedure requires Windows, or at least the ability to run C# code.

You will need the following tools

  1. Download the APK and extract it to some folder
  2. Go to the assemblies folder
  3. In that folder, create a file called ExtractSpaStruct.linq with this content
<Query Kind="Program">
  <Reference>(Full path to)InTouchLib_Generic.dll</Reference>
</Query>

void Main()
{
    var assembly = Assembly.LoadFile(@"(Full path to)InTouchLib_Generic.dll");
        var resstm = assembly.GetManifestResourceStream("InTouchLib.Resources.SpaPackStruct.xml");
    var intouchdata = new InTouchLib.Util.InTouchData();
    var br = new BinaryReader(resstm);
    var d1 = br.ReadBytes((int)resstm.Length);
    var d2 = intouchdata.Read(d1);
    var xml = Encoding.GetEncoding("ISO-8859-1").GetString(d2);
    xml.Dump();
}

Ensure the (Full path to) is replaced with the actual path to the dll.

  1. Start LINQPad and load that script
  2. Run it, and it should dump the SpaPackStruct.xml into the output window. You can copy and paste this into the one that was downloaded by the geckolib library and see what happens.
eranjo commented 3 years ago

That is so cool! Just to let you know that I contacted Gecko already yesterday about getting up to date API or spa xml. I have not heard back from them yet thow.

Any chance getting the xml file to my inbox? I don't have a Windows computer. eranjo3 at hotmail dot com

agittins commented 3 years ago

I'd like to start tracking temperature change vs. weather forecast -> The idea is to set rules to get my spa heating started at the right time based on the time I want to go in.

For what it's worth, you can work this out fairly easily. Our spa has a 4KW heater and holds 1000 Litres. This online calculator can do the maths for you to work out how many degrees-per-hour your tub will heat up.

Ambient temperature will only affect your losses, which should be negligible over your heating time, otherwise the only thing that matters is the change in temperature you need. The calculator above said our hot tub should heat at 2 degrees C per hour. This matches exactly with timed observations I've done, so providing your insulation is OK (and you know the volume and the heater wattage), the calculator should be accurate. Of course, the other option is just turn it on, and time it while it heats up. You'll get the same answer either way.

I also measured our heat loss, we lose about 4 degrees a day (I don't know for sure, but that figure probably is more dependent on ambient temp).

Of course it will still be good to have remote/smart control of our hot tubs, but the above might be useful if that's a use-case for you.

rct commented 3 years ago

@agittins - Thanks for the info.

Once we can see/log how often the heat is running, I think we should be able to get some estimate of heat loss based on conditions at the time.

I believe in addition to ambient temperature, wind speed plays a factor in heat loss. Constant wind blowing around the tub should wick heat away faster than little to no wind.

agittins commented 3 years ago

Yes, it will definitely be interesting to see how much conditions affect it. If the installation is good though (ie, it's well-insulated) there should not be much difference, but there's only one way to know for sure 👍🏼 (also I'm in Oz so we have very mild to warm temps here).

eranjo commented 3 years ago

@gazoodle

I was able to get a windows machine and I followed your instructions. Could you advice how to proceed? I was not able to figure out this error. I used LinqPad 5 and identified the dll path with F4 command. I must be missing something simple but just can't figure that out.

I must be also way out of my league since I'm not fully following how this query is working and where it will get all the data for the xml. So I'd be also fine with a comment "wait until we get this figured out" :) image

gazoodle commented 3 years ago

@gazoodle

I was able to get a windows machine and I followed your instructions. Could you advice how to proceed? I was not able to figure out this error. I used LinqPad 5 and identified the dll path with F4 command. I must be missing something simple but just can't figure that out.

I’m sorry, I guess that’s what happens when you try to sanitise stuff to post without actually trying it out! I removed the two absolute paths in the LINQpad script, but it seems to need them. Go ahead and put the full path to the InTouchLib_Generic.dll in both places and try that. I’ll edit the post above too.

I was also working on a docker script to try to help which I’ll post once I’ve figured that out.

eranjo commented 3 years ago

@gazoodle

I don't know what to say other than a BIG thank you!!! My Spa is now connecting and I was able to turn both pumps and lights on and off :)

Starting discovery process...Found 1 spas Connecting to spa My Spa at 192.168.86.229 ... connected! Heater: Temperature 36.0°C, SetPoint 38.0°C, Real SetPoint 26.9°C, Operation Cooling Pump 1: OFF Pump 2: OFF Lights: OFF WaterCare: Waiting... Smart Winter Mode:Risk = NO Circulating Pump = OFF Ozone = OFF Smart Winter Mode:Active = False Filter Status:Clean = False Filter Status:Purge = False Welcome to the Gecko shell. Type help or ? to list commands.

My Spa$

eranjo commented 3 years ago

@agittins - Thanks for the info.

Once we can see/log how often the heat is running, I think we should be able to get some estimate of heat loss based on conditions at the time.

I believe in addition to ambient temperature, wind speed plays a factor in heat loss. Constant wind blowing around the tub should wick heat away faster than little to no wind.

@rct Good point about taking wind into consideration. I'll start collecting data now that I have my spa sending information that I can collect.

I live here in the Nordics so temp can vary anything between +30c to -25c. I think cooling/heating will be different on those extremes no matter what type of insulation you have. And yes we use our spa all year around:)

simonk1969 commented 3 years ago

@gazoodle

I don't know what to say other than a BIG thank you!!! My Spa is now connecting and I was able to turn both pumps and lights on and off :)

Starting discovery process...Found 1 spas Connecting to spa My Spa at 192.168.86.229 ... connected! Heater: Temperature 36.0°C, SetPoint 38.0°C, Real SetPoint 26.9°C, Operation Cooling Pump 1: OFF Pump 2: OFF Lights: OFF WaterCare: Waiting... Smart Winter Mode:Risk = NO Circulating Pump = OFF Ozone = OFF Smart Winter Mode:Active = False Filter Status:Clean = False Filter Status:Purge = False Welcome to the Gecko shell. Type help or ? to list commands.

My Spa$

I seem to have the same issue and was wondering if you wouldn't mind sending a copy of the SpaPackStruct.xml file to me so that I could try it too?

simonk1969 commented 3 years ago

I've tried to extract the SpaPackStruct.XML file but have this issue that I cannot resolve: Capture

gazoodle commented 3 years ago

I've tried to extract the SpaPackStruct.XML file but have this issue that I cannot resolve: Capture

I've seen that when the library didn't get loaded. Did you bind the LINQPad script to the intouch DLL? You can see if this is correct by pressing F4 and checking the assemblies that you've referenced. If it's not loaded, then select the file from your path (C:\APKTool\intouch2\unknown\assemblies\InTouchLib_Generic.dll)

simonk1969 commented 3 years ago

I checked the referenced assemblie and it looks correct as per screenshot but still receive the issue.

I have however been sent a copy of the ExtractSpaStruct by someone else, I've put this into root of config folder and replace the original and restarted Home Assistant but see errors still in the log as per attached image (strangely I did have to remove four zeros from the end of the file which where causing Parsing errors).
The file shows

Any help gratefully appreciated :-)

LinqPad

XML Error

Gecko Error

gazoodle commented 3 years ago

Can you turn logging on for the gecko components:

In Configuration.yaml ...

logger:
  default: info
  logs:
    custom_components.gecko: debug
    geckolib: debug

Then restart HA and pop the logs in here ... they'll be quite verbose, feel free to comment out/remove the logs: lines after to keep your log file manageable.

simonk1969 commented 3 years ago

home-assistant.log attached

home-assistant.log

gazoodle commented 3 years ago

home-assistant.log attached

home-assistant.log

Huh! Your spa did not respond to the AVERS command which is odd. I presume the Android/iOS app works fine? In fact on further investigation, it didn't respond to any of the commands (other than the initial discovery). Not sure what is going on here. Can you try the client.py python script? Instructions are in the README.md of this repo. Not seen this behaviour before ... BTW I'm re-opening this issue on the back of those logs.

simonk1969 commented 3 years ago

Yes the Android App is working, when I open the App there is about a 8 second delay before it fully loads the screen showing temp, etc. Not sure if this is normal?

The pip install geckolib installed without issue but I'm getting a error with GeckoShell usage

Capture

gazoodle commented 3 years ago

Gah!!! Looks like some Windows issue with readline (https://pypi.org/project/readline/) leading to (https://pypi.org/project/gnureadline/) : : Ok, since you don't need the simulator ... can you comment out (place a # symbol in col 1) on line 4 and on 53 of src/geckolib/driver/utils/simulator.py. Hopefully that will get you past this problem. If not, then we'll keep going until we've got the lib running on your box!

simonk1969 commented 3 years ago

Unfortunately RuntimeError: Spa took too long to connect :-(

Starting discovery process...Found 1 spas
Connecting to spa `HotTub` at 192.168.0.40 ... Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Simon\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\geckolib\utils\shared_command.py", line 37, in run
    with cls(first_commands) as cmd:
  File "C:\Users\Simon\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\geckolib\utils\shell.py", line 52, in __init__
    self.onecmd("discover")
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.496.0_x64__qbz5n2kfra8p0\lib\cmd.py", line 217, in onecmd
    return func(arg)
  File "C:\Users\Simon\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\geckolib\utils\shell.py", line 80, in do_discover
    self.onecmd("manage 1")
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.496.0_x64__qbz5n2kfra8p0\lib\cmd.py", line 217, in onecmd
    return func(arg)
  File "C:\Users\Simon\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\geckolib\utils\shell.py", line 97, in do_manage
    self.facade = spa.get_facade()
  File "C:\Users\Simon\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\geckolib\spa.py", line 48, in get_facade
    while not facade.is_connected:
  File "C:\Users\Simon\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\geckolib\automation\facade.py", line 68, in is_connected
    if not self._spa.is_connected:
  File "C:\Users\Simon\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\geckolib\spa.py", line 306, in is_connected
    raise RuntimeError("Spa took too long to connect ...")
RuntimeError: Spa took too long to connect ...
>>> Exception in thread Thread-3:
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.496.0_x64__qbz5n2kfra8p0\lib\threading.py", line 954, in _bootstrap_inner
    self.run()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.496.0_x64__qbz5n2kfra8p0\lib\threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Simon\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\geckolib\spa.py", line 282, in _ping_thread_func
    self.refresh()
  File "C:\Users\Simon\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\geckolib\spa.py", line 311, in refresh
    if not self.is_connected:
  File "C:\Users\Simon\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\geckolib\spa.py", line 306, in is_connected
    raise RuntimeError("Spa took too long to connect ...")
RuntimeError: Spa took too long to connect ...
gazoodle commented 3 years ago

There should now be a client.log file in the /test folder. Can I have that please - kinda hoping that it's got different info from the custom component but not holding out much hope now ;-)

simonk1969 commented 3 years ago

Client.log attached

I'm going to reboot the HotTub, just incase there is any issue there!

client.log

gazoodle commented 3 years ago

It's the same, as expected. I'm going to run the library on my Windows box and see if I get the same ... I remember reading somewhere that the low level socket library for Python is quite different on Windows.

simonk1969 commented 3 years ago

I can fire up a VM of another OS if that is likely to help in diagnosis.

gazoodle commented 3 years ago

It's the same, as expected. I'm going to run the library on my Windows box and see if I get the same ... I remember reading somewhere that the low level socket library for Python is quite different on Windows.

Wasn't that. It located and connected to my spa just fine...

I initially thought that it might be your AV or Windows firewall issue, but the intouch2 module responds to the discovery message with it's identity ... it just fails to respond to the targeted packets after that.

The other thing that we might have to try is a Wireshark session

gazoodle commented 3 years ago

I can fire up a VM of another OS if that is likely to help in diagnosis.

Oooh, that would certainly eliminate the Windows FW/AV possibilities.

simonk1969 commented 3 years ago

I'll have to create a VM, so what OS is required?

gazoodle commented 3 years ago

I'll have to create a VM, so what OS is required?

I'd go for Linux/Ubuntu 20.04 LTS/Focal Fossa if you can get the image easily, but 18.04 should be good too.

Also, might be worth checking your firewall to ensure that UDP traffic to/from your SPA is permitted to/from port 10022. The broadcast (multicast) packet might be treated differently.

simonk1969 commented 3 years ago

Exactly the same through Ubuntu 20.04

I've also tried my other Windows VM with same issue.

I was thinking I could take out my entire network out of loop by connecting laptop direct to in.touch2 but then it's not going to get an IP? Could see if I've got an old router laying around.

gazoodle commented 3 years ago

Exactly the same through Ubuntu 20.04

I've also tried my other Windows VM with same issue.

I was thinking I could take out my entire network out of loop by connecting laptop direct to in.touch2 but then it's not going to get an IP? Could see if I've got an old router laying around.

Hmmm have all the tests been on the same bare metal system? You sort of indicate that you had another Windows VM, but was that on the same box? Also, maybe your network is blocking the packet ... but that’s not likely as your Android app works fine ... Wireshark capture looks like the way to go. We need to understand where the packets are going.

simonk1969 commented 3 years ago

Initially I was doing the tests on my main Windows 10 PC, the VM was on a different PC running Proxmox with a fresh VM/Container of Ubuntu 20.04.

I've also dug out another router and connected my main Windows 10 PC directly to that and also the in.touch2, they both got a IP and I could ping it. The Android App didn't work but I beleive that requires internet access and using this router it didn't have internet. Got same result though 'Spa took to long to connect'. Since connecting them back up to the normal router I strangely cannot get the app to work now, just keeps saying Retry:-( I'll have a look at that!

Can I just confirm that what we are seeing is that we can successfully get a connection/response from the in.touch 2 device which also has the blue light on which shows that it is correctly connected to the other half on the Hot Tub but the hot tub board is not responding?

I've installed Wireshark but I don't know much about it, I've put in a filter of ip.addr == 192.168.0.40 and can see packets between my computer and in.touch 2 and vice-versa. Other than that I'm not sure what information can help? Is it normal for a DHCP Request packet every 60 seconds from the in.touch 2 unit?

Capture

agittins commented 3 years ago

noticed in the packets 'Ho tTub'

Nothing to worry about there, that's just formatting of the dump for readability by grouping into 8 bytes at a time - you can see the hex codes for "o" and "t" (6f, 74) are consecutive in the hex dump part.

Did you restart the intouch after moving everything back onto the main network? It might be borked and trying to renew it's lease against the temporary router which is no longer there - that might explain the DHCP traffic and the fact that the android app hasn't started working again. A reboot of the intouch might resolve that.

simonk1969 commented 3 years ago

Nothing to worry about there, that's just formatting of the dump for readability by grouping into 8 bytes at a time - you can see the hex codes for "o" and "t" (6f, 74) are consecutive in the hex dump part.

I deleted my post on this point just after I posted it as I realised what you said above!

Did you restart the intouch after moving everything back onto the main network?

I did unplug it breifly but I'll go and unplug it for longer.

agittins commented 3 years ago

Cool :-) I can't help you with the protocol stuff, so I'll leave that for when @gazoodle takes a look. It might help to have another wireshark dump like you did above, once you've got it talking to your android app again.

I assume 192.168.0.40 is the hot-tub and 192.168.0.241 is your windows pc?

gazoodle commented 3 years ago

Ok, I think we're getting somewhere. First you need to restore comms to your spa from your phone. I suspect that the advice from @agittins w.r.t. to getting it working might help.

Then, the evidence is that your Android app was always only able to connect using it's remote mode (in.touch2 -> your-router -> internet -> gecko servers -> internet -> your-router -> your phone) but was not connecting locally (in-touch2 -> your phone). You can see which mode it is using by looking in the Settings|Technical Info>Connection type on your Android app which is probably remote.

If you have a local DNS server (e.g. PiHole?) or a way to block sites on your router, you can block intouch.geckoal.com which will prevent both the intouch2 module and your phone from using the remote path, they then will try to use the local mode.

Then you need to faff around with your network so that you can control the app from the phone. Probably a foray into mDNS, multicast packets, router settings and a whole bunch of other stuff which depends on your network hardware and firewalls, but I think that once you've got to the bottom of being able to control your spa using local mode, then the geckolib drivers should work.

You might not even need the v24 SpaPackStruct.xml file!

Happy to give pointers where I can. If you get to the point of having a local connection, the Android app working but geckolib isn't then we can go for a wireshark capture using your filter and see if we can work out what the heck is going on!

Good luck!

BTW when developing the library, I did consider trying to talk to the Gecko servers, but they seem to encrypt that conversation and (personally) I'm only interested in local control of my HA devices so I didn't think to pursue this route, but maybe we need to have that as a fallback option...

simonk1969 commented 3 years ago

I assume 192.168.0.40 is the hot-tub and 192.168.0.241 is your windows pc? Yes, that's correct

First you need to restore comms to your spa from your phone. I don't seem to be able to get a connection again from my phone to hot tub, I did have this issue a few weeks ago too. I'm beginning to think I may have a intermittent hardware issue.

You can see which mode it is using by looking in the Settings|Technical Info>Connection type on your Android app which is probably remote. I'm looking in the Android app but cannot see Technical Info with the Settings Menu, Technical Suport just opens up a support webpage. I've attached a screen shot

I'll work on the rest of your pointers once I get the phone connected again!

Thanks for all your time and effort today :-)

Capture

insaneoctane commented 3 years ago

@gazoodle I just did all this. Wow, thanks! Mine didn't work at first either. I added the readline library for my first error (ie. pip install pyreadline) which seems to be an issue for Windows machines Then it ran, but wouldn't connect (but found it) Followed the instructions here and it worked. It ended up downloading a v24 XML file instead of the v19 that your script auto downloaded. Awesome stuff, thank you!

By the way here's my cheat sheet of crappy and quick notes of how I did this in case it helps someone else:

> _Installed Python 3.9 to C:\Python39 (for all users and added path choice)
> 
> Added geckolib
> pip install geckolib
> 
> Needed missing library
> 
> pip install pyreadline
> 
> ran shell from python....
> python.exe
> >>> from geckolib import GeckoShell
> >>> GeckoShell.run()
> 
> Errored out (just like in reported issues)
> https://github.com/gazoodle/geckolib/issues
> 
> Read about issue "Run time error: Spa took too long..."
> Followed those directions
> 
> Installed LINQPad to downloads (not installed version...unzipped)
> Downloaded 2.7.2 APK per instructions
> Renamed APK to .zip and extracted
> followed instructions on creating ExtractSpaStruct.linq here:
> C:\Users\xxx\Downloads\in touch 2_v2.7.2_apkpure.com_APK\assemblies
> Added FULL PATH: 
> var assembly = Assembly.LoadFile(@"C:\Users\xxx\Downloads\in touch 2_v2.7.2_apkpure.com_APK\assemblies\InTouchLib_Generic.dll");
> and
> <Reference>(C:\Users\xxx\Downloads\in touch 2_v2.7.2_apkpure.com_APK\assemblies\InTouchLib_Generic.dll</Reference>
> 
> Needed to install MS CORE (.NET) to run LINQPad (did this for x64)
> Ran LINQPad
> Opened .linq file
> Ran it
> It errored.  I manually (F4) added the library (InTouchLib_Generic.dll) and re-ran
> It worked and produced output for a new XML file
> copy-pasted the output to a new SpaPackStruct.xml file
> Now it worked!_
> 
NorthernMunkey commented 3 years ago

@gazoodle I was able to get a windows machine and I followed your instructions. Could you advice how to proceed? I was not able to figure out this error. I used LinqPad 5 and identified the dll path with F4 command. I must be missing something simple but just can't figure that out.

I’m sorry, I guess that’s what happens when you try to sanitise stuff to post without actually trying it out! I removed the two absolute paths in the LINQpad script, but it seems to need them. Go ahead and put the full path to the InTouchLib_Generic.dll in both places and try that. I’ll edit the post above too.

I was also working on a docker script to try to help which I’ll post once I’ve figured that out.

thanks for this, i too have a path issue

CS0246 The type or namespace name 'InTouchLib' could not be found (press F4 to add an assembly reference or import a namespace) this line here var intouchdata = new InTouchLib.Util.InTouchData();

any ideas?

maegibbons commented 3 years ago

Hi Guys

I've been looking into why SpaPackStruct would not extract from version 2.7.4. like it did from 2.7.2. The reason why it won't extract is that it is packed.

The APK uses the Xamarin package from Microsoft which has a function to compress DLL's and then uncompress them before use. This uses lz4 for compression algorithm and there are are a few Python scripts available to decompress the dlls once you have used apktool to extract the intouch2 APK.

Once decompressed you can use the LINQ scripts already provided to extract the embedded XML structure.

However, I noticed that 2.7.4 only has version 24 embedded within it and I suspected that the app was downloading the latest SpaPackStruct behind the scenes.

I probed this interaction with the servers using tcpdump/wireshark and unfortunately it is an https download and cannot be interpreted in terms of source URL or security tokens.

However, after much probing and trial and error, I have have managed to to extract version 33 from the data directory on an old Android phone using ADB.

It actually gets downloaded as an IT2 file type and you have to generate the xml using a similar LINQ program to that already given!

I can confirm that the definitions are there with latest versions for InYJ spas, InYT spas and InYE spas together I'm sure with many more.

If anybody needs further details please email me me at mgibbons@ (at domain in my profile web link).

Krs

Mark

rct commented 3 years ago

@maegibbons - thanks for working on this, lots of interesting bits here.

However, after much probing and trial and error, I have have managed to to extract version 33 from the data directory on an old Android phone using ADB.

It actually gets downloaded as an IT2 file type and you have to generate the xml using a similar LINQ program to that already given!

I can't find much about IT2 file types. It is a compression scheme or is it for obfuscation?

Any chance you can use file <filename>.it2 on a recent Linux system to see if file(1) recognizes the file? (Might be a long shot, but maybe lz4, or something similar?

The APK uses the Xamarin package from Microsoft which has a function to compress DLL's and then uncompress them before use.

One idea: It might be worth looking for URL strings (utf8/utf16) in the DLLs once uncompressed to see if the downloading of the current version can be figured out.

This uses lz4 for compression algorithm and there are are a few Python scripts available to decompress the dlls once you have used apktool to extract the intouch2 APK.

I don't do much with the Android ecosystem. I'm wondering if the in.touch APK is available from one of APK sites for sideloading. I've run other home automation stuff on the Blue Stacks emulator under windows. (It is handy to have on my laptop for devices that don't have a web interface.)

I can confirm that the definitions are there with latest versions for InYJ spas, InYT spas and InYE spas together I'm sure with many more.

I have an InYT controller. So far I haven't noticed any issues with the version 19 SpaStructPack that is readily available. Is there something I might be missing?

(My tub is a new a couple of years old, so maybe that's why I'm fine with the older definition file. Though this might mean in addition to knowing the controller type, there is another piece of identification metadata that is needed to know which version might be required.)

Assuming this isn't going to get easier soon, it would be helpful to begin compiling a list of what controllers work with version 19, and which will require extra efforts to obtain the current definitions file.

brandonmartin commented 3 years ago

Leaving a few data points here...

I have a brand new tub, I was able to get it working by taking the v24 xml file and then introducing a little bit of untruth to spa.py:

index 06ba934..d575f24 100644
--- a/src/geckolib/spa.py
+++ b/src/geckolib/spa.py
@@ -157,13 +157,16 @@ class GeckoSpa(GeckoUdpSocket, GeckoSpaPack):
         self.config_xml = self.gecko_pack_xml.find(
             GeckoConstants.SPA_PACK_CONFIG_XPATH.format(self.config_version)
         )
-        self.log_version = handler.log_version
+        #self.log_version = handler.log_version
+        self.log_version = handler.log_version - 1
         self.log_xml = self.gecko_pack_xml.find(

This resulted in everything working except my exterior LEDs

I was able to duplicate @maegibbons work using BlueStacks and adb

rough procedure:

  1. install BlueStacks
  2. install adb
  3. enable ADB in bluestacks (settings => advanced => enable debug bridge)
  4. install the gecko app on your emulated device
  5. run the app, login so it downloads from the API
  6. grab the it2 file from the device
windows> adb shell
device$ system/xbin/bstk/su
device# cp /data/data/com.geckoportal.intouch2/files/SpaPackStruct.it2 /mnt/sdcard
device# exit
device$ exit
windows> adb pull /mnt/sdcard/SpaPackStruct.it2 SpaPackStruct.it2

Now fire up the modified linq script, changing the path to the it2 file, loading the assembly and executing:

void Main()
{
    //var assembly = Assembly.LoadFile(@"C:\intouchhax\inTouchLib_Generic.dll");
    //var resstm = assembly.GetManifestResourceStream("InTouchLib.Resources.SpaPackStruct.xml");
    var intouchdata = new InTouchLib.Util.InTouchData();
    //var br = new BinaryReader(resstm);
    //var d1 = br.ReadBytes((int)resstm.Length);
    var d1 = File.ReadAllBytes(@"C:\intouchhax\gecko_it2\SpaPackStruct.it2");
    var d2 = intouchdata.Read(d1);
    var xml = Encoding.GetEncoding("ISO-8859-1").GetString(d2);
    xml.Dump();
}

This should result in a v33 xml file that you can install as above. I still don't have my secondary exterior lights but that may be an addition to geckolib and/or the integration...

I did investigate fetching it from the API via a script and that does seem possible at /api/spapackstructure you can get a token at https://api-intouch2.geckoal.com/sessions/new

I haven't quite worked out signing the request properly and setting all the headers so I am still getting 401 on that front. Anyhow hope this helps someone!

maegibbons commented 3 years ago

Excellent use of blue stacks!

Glad you got further in terms of direct download and session token retrieval!

Are you able to toggle the lights from the geckolib shell?

I.e. is this a library issue or HA integration issue?

Krs

Mark

brandonmartin commented 3 years ago

For the other lights, I haven't looked in to it much, but I suspect it is a geckolib issue and I also suspect this is the fabled "L120" device:

2021-06-28 13:19:48 DEBUG (Thread-6) [geckolib.automation.facade] Actual connect     ions are {'Out1': 'P1H', 'Out2': 'P2H', 'Out3': 'P1L', 'Out4': 'CP', 'Out5': 'P2L', 'OutHtr': 'HTR', 'HeatPumpCurrent': '0A', 'HeatPumpFuse': 'F3', 'Out6': 'P3L', 'Out7': 'P3H', 'Out8': 'Waterfall', 'Out9': 'L120', 'OutLi': 'LI'}
2021-06-28 13:19:48 DEBUG (Thread-6) [geckolib.automation.facade] Actual devices are {'Waterfall', 'L120', 'P2', 'LI', 'P1', 'P3', 'CP'}
2021-06-28 13:19:48 DEBUG (Thread-6) [geckolib.automation.facade] Actual user devices are ['Waterfall', 'L120', 'P2', 'LI', 'P1', 'P3']
2021-06-28 13:19:48 DEBUG (Thread-6) [geckolib.automation.facade] Handled user devices are ['Waterfall', 'P2', 'LI', 'P1', 'P3']

I tried plonking it into const but I need to come up with the gecko keypad constant for it which I'm not sure how to arrive at yet..

maegibbons commented 3 years ago

Have you used the geckolib shell to explore this?

brandonmartin commented 3 years ago

yes, this cycles the light in question although I have to send the User demand twice to get it to turn off:

M9$ get L120
L120 = OFF
M9$ set UdL120=ON
M9$ get L120
L120 = ON
M9$ set UdL120=OFF
M9$ set UdL120=OFF
M9$ get L120
L120 = OFF