Local Deployment for SureFlap / SurePetCare Connect using only local MQTT Broker

You should really reword the intro to this post and remove the official integration link. It’s really easy to glance at this and think the thread is regarding that particular repo. You should just title it, like, Cloudless Local SureFlap / SurePetCare Connect integration or whatever. Just makes the whole thing stand out on it’s own for people that might be kinda skimming pages looking to see what is already out there built.

Anyone else’s just randomly stop working? Nothing out of the ordinary as far as I can tell. @peterl any chance you’re still around?

edit: Seems it was this. Thanks @jacotec

Hi! I’m new to Home Assistant and I was very glad to see a replacement for the Sure petcare cloud suite that has caused me so much frustration.

I am in the process of setting up the docker version in Portainer on my unraid server and I have assigned the container a static IP and set up DNS poisoning on my router. I had version 2.201 before and I followed the instructions on how to downgrade, but the hub never stop blinking. It aternate left right green LEDs for 10 sec then alternating red left right for 10 sec and does that over and over again.

Is it safe to restart the hub or the container? Is this standard procedure? In the container terminal I can see the firmware files up to no. 76 has been uploaded.

I just realized that I don’t think there’s a way to set a pet as inside only with this, is there? Holy shit, one of our indoor only cats could have been using this the whole time!

@peterl

No there is no way to set curfews for individual pets with Pethublocal from my understanding.

How can I change the curfew times? If I go to the IP of my PHB instance i get to the server UI but the columns is all empty even though everything works in HA as expected.

Has anyone had this issue when running pethublocal setup? (I have <> some of the personal content.)

What seems to be happening is when I ask the script to download the firmware, it downloads an empty .bin file which obviously doesn’t have the xor key so the 2.43 firmware bin can’t be configured with it, the script then fails. is there something I can do from myside to help this along?

I have managed to get the pethublocal app running and it is passing data to the MQTT but I suspect this is from the .config file and not from the hub.

By the way Peter, Fantastic work and cant wait to use it

  • C

INFO:pethublocal:Loading Config file pethubconfig.json
INFO:pethublocal:Current Deployment Cloud
Use exist SurePetCare Cloud (C) or build empty Local config (L) C/L ? C
INFO:pethublocal:Building from Cloud Configuration, starting DNS check
INFO:pethublocal:This is VITAL as you need to update your internal DNS to point hub.api.surehub.io to this host running PetHubLocal so that the hub connects to this host not the internet
INFO:pethublocal:External DNS entry for hub.api.surehub.io: 54.87.205.181
INFO:pethublocal:Internal DNS entry for hub.api.surehub.io: x.x.x.x <>
Is the Internal DNS updated to point to this host Y/N?
Y

Start File start-20230110-025407.json download new start Y/N? Y
INFO:pethublocal:Check Token Expiry JWT {‘iss’: ‘https://app.api.surehub.io/api/auth/login’, …’} <>
INFO:pethublocal:JWT Token Expiry 2024-01-07 12:59:53
INFO:pethublocal:Cloud Config: Using JWT Bearer Token to download configuration
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): app.api.surehub.io:443
DEBUG:urllib3.connectionpool:https://app.api.surehub.io:443 “GET /api/me/start HTTP/1.1” 200 1605
INFO:pethublocal:{‘devices’:…}}} <>
INFO:pethublocal:Cloud Config: Download successful response: <Response [200]>
DEBUG:pethublocal:Adding Pet <>
DEBUG:pethublocal:Adding Pet <>
INFO:pethublocal:Start parsed and saved to config
Download Credentials and Firmware for Hub (highly recommended)? Y/N Y
INFO:pethublocal:Current Hub Firmware 233.364
INFO:pethublocal:Downloading Current Firmware for H010-064xxxx
INFO:pethublocal:SureHub Host hub.api.surehub.io IP Address: 44.198.20.107
INFO:pethublocal:Firmware already downloaded H010-0646816-1.177-00.bin
INFO:pethublocal:Your device has been upgraded to version 233.364 and since it isn’t running 2.43 this version the Hub now checks the server certificate is legitimate before connecting (boo! :frowning: ) so you will need to downgrade the hub to 2.43 which for the moment is easy as holding the reset button underneath the hub when the DNS is poisoned to point to PetHubLocal (Yay!)
Traceback (most recent call last):
File “/home/pi/.local/bin/pethublocal”, line 8, in
sys.exit(cli())
File “/home/pi/.local/lib/python3.7/site-packages/click/core.py”, line 1130, in call
return self.main(*args, **kwargs)
File “/home/pi/.local/lib/python3.7/site-packages/click/core.py”, line 1055, in main
rv = self.invoke(ctx)
File “/home/pi/.local/lib/python3.7/site-packages/click/core.py”, line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/pi/.local/lib/python3.7/site-packages/click/core.py”, line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/pi/.local/lib/python3.7/site-packages/click/core.py”, line 760, in invoke
return __callback(*args, **kwargs)
File “/home/pi/.local/lib/python3.7/site-packages/click/decorators.py”, line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/pi/.local/lib/python3.7/site-packages/pethublocal/cli/init.py”, line 72, in setup
pethubconfig = config_load(True, force)
File “/home/pi/.local/lib/python3.7/site-packages/pethublocal/functions.py”, line 385, in config_load
xor_key, long_serial = find_firmware_xor_key(serial_number, BOOTLOADER)
File “/home/pi/.local/lib/python3.7/site-packages/pethublocal/functions.py”, line 1200, in find_firmware_xor_key
record_count = int(header[2], 16)
IndexError: list index out of range

It doesn’t look like you followed the steps to get it reset to the 2.43 firmware.

Hi Fly,

Sadly I don’t get to reset the hub firmware because, from this set of instructions, I don’t get the two firmware files (.bin) after running the “pethublocal setup” so can’t reboot the hub as directed for the downgraded firmware.

I’ve now read through the code and I think the python fails with the log message, I mentioned above (link) because, in the first stage a 1.177 firmware file is downloaded then deXor’s to return a key, which is used in the 2nd stage, but because the first file is empty, then the second stage fails to Xor the 2.43 bin file.

So bottom line, I have no firmware files to use to reset the firmware to 2.43.

IIRC, holding in the reset button and plugging it in resets the firmware to default. That process is somewhere on @peterl’s Github page.

Magic! Thanks Fly. I’ll try that a little later today.

1 Like

Hi Fly,

I tried the reset button method you mentioned, but sadly the hub remains on the 233.xx version (tried a few times). Do you know of a way to force a compile of the 2.43 firmware without using the “pethublocal setup” option?

C

I don’t have time to look right now, but I’m 99% sure the steps to reset are in his github docs.

I didn’t think it was so clear, that if the hub succeeded in downgrading the firmware or not. I could not see the firmware version. Maybe in the log files? In the pethub config file there was only the original firmware version I think. It’s hard to remember all steps, especially if you have to tinker a lot to get it up and running.

Are your DNS poisoning working as it should?

Hi Pum,

Yes the DNS poisoning works as defined. The setup process find the correct internal and external addresses perfectly. The script finds the cloud account, extracts all the data for the hub, pwr door and pets and creates the related config files BuT when it asks if I want to download the firmware, it starts the process but then fails.

My assumption, based on reading the code, is that the script has three stages. 1) downloads a v1.177 bin file, 2) extracts the long code from it then 3) uses that code to create a new bin file for my hub.

Because the first bin is not found it can’t extract the king code and therefore can’t create the new hub firmware.

Firmware downgrade is listed here: Hub Firmware | Pet Hub Local

Thanks Fly,

Yes, I have seen this and, short of opening the hub and connecting wires to it, I followed this to the letter.

The “After the configuration is built using pethublocal setup the current directory should have two groups of firmware images” from the below extract, is where my problem starts. I don’t get the “… two groups of firmware images…” so no matter how often I press the reset button on the hub, it’s not going to downgrade the firmware.

The reason for the missing two firmware images is found here… " …during the setup when downloading the current firmware from SurePetCare the script finds the XOR key for that firmware as the project includes the DeXORed 2.43 firmware and builds a hub specific image with the XOR key just found…" - the “when downloading the current firmware from SurePetCare” doesnt happen, so the script cannot find “**the XOR key for that firmware" and so cannot "build[s] a hub specific image with the XOR key just found**”

Unless I can download an image manually, then edit the script to run from that point on, I’m never going to get the 2nd firmware image.


" If your Firmware above is not 2.43 and 2.201 or anything higher then you will need to flash on the older firmware to make it work. Thankfully I have made this as straight forward a process as possible as during the setup when downloading the current firmware from SurePetCare the script finds the XOR key for that firmware as the project includes the DeXORed 2.43 firmware and builds a hub specific image with the XOR key just found.

After the configuration is built using pethublocal setup the current directory should have two groups of firmware images:

H0xx-0xxxxxx-2.43-nn.bin

and

H0xx-0xxxxxx-1.177-nn.bin

Where H0xx-0xxxxxx is your Hub Serial Number and 2.43 version of files is the custom firmware built to your Hub, and 1.177 is what was downloaded from SurePet and then the XOR key found as 1.177 is the version of the bootloader on the hub, which I hope SurePetCare don’t upgrade to lock me out of doing this :pray:

The Hub requests the firmware over HTTP on port 80 to hub.api.surehub.io so we are in luck as it doesn’t check the certificate and will download fine from PetHubLocal… hence why we can downgrade and upgrade without the issue of the need to validate a Certificate over HTTPS.

Hi Fly, I found and used the "pethublocal firmware -sn Hxxx-xxxxxxx -f " command and this is the output (below). You can see from the error, it’s just not finding the 1.177 firmware at the http://35.168.106.54/api/firmware address.

Any help on where I might find my hub’s firmware would be a huge help.

INFO:pethublocal:Download Firmware Serial Number: H010-0XXXXXX
INFO:pethublocal:SureHub Host hub.api.surehub.io IP Address: 35.168.106.54
INFO:pethublocal:Downloading first firmware record to get header information
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): 35.168.106.54:80
DEBUG:urllib3.connectionpool:http://35.168.106.54:80 “POST /api/firmware HTTP/1.1” 200 0
Traceback (most recent call last):
File “/usr/local/bin/pethublocal”, line 8, in
sys.exit(cli())
File “/usr/local/lib/python3.9/site-packages/click/core.py”, line 1130, in call
return self.main(*args, **kwargs)
File “/usr/local/lib/python3.9/site-packages/click/core.py”, line 1055, in main
rv = self.invoke(ctx)
File “/usr/local/lib/python3.9/site-packages/click/core.py”, line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/usr/local/lib/python3.9/site-packages/click/core.py”, line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/usr/local/lib/python3.9/site-packages/click/core.py”, line 760, in invoke
return __callback(*args, **kwargs)
File “/usr/local/lib/python3.9/site-packages/click/decorators.py”, line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File “/usr/local/lib/python3.9/site-packages/pethublocal/cli/init.py”, line 50, in firmware
log.info(download_firmware(serialnumber, force))
File “/usr/local/lib/python3.9/site-packages/pethublocal/functions.py”, line 103, in download_firmware
recordcount = int(byte[2], 16) + 6
IndexError: list index out of range

I wonder if they changed something to prevent this. :frowning: I’ll try to check and see if it works for me later today.

Hi everyone,

I must admit I don’t use HA, but Peter’s great work should also be usable outside the HA world, I assume. In the end I need to make use of the MQTT messages being sent by pethublocal in my FHEM installation. 90 % of the time I spent on the setup was due to my Truenas Scale K8s Setup, especially with the core requirements on ports (80,443) and the Mosquitto setup. But I guess I managed now to get it working, at least I believe so. The hub is connected, ears are solid green and it sends messages via MQTT to mosquitto. Also the information in the pethublocal frontend looks promising.

My question is now related to what pethublocal actually sends via MQTT. When looking at the topics received at mosquitto they are:

  • pethub/hub
  • pethub/ha

I am pretty sure that during my testing (aka struggeling during setup) I also saw a “homeassistant” topic, which seems to be the enhanced information sent by pethublocal.

Can someone confirm this? And if yes, what is missing / probably going wrong if this information is missing?

Thanks everyone and especially to Peter. Fantastic work and brilliant documentation.

Cheers

The messages that go into /hub are the Hub messages to and from the hub as both PHL and the hub itself post to the same topic and the /ha ones are the translated version.

If you want some light reading on all the different mesasges.