Tapo changed its IP address now can't read it with Raspberry Pi

2

Comments

  • MeteredOut
    MeteredOut Posts: 2,782 Forumite
    1,000 Posts Second Anniversary Name Dropper
    If it stopped working the very day you changed ISPs, that is the most likely root cause. I asked above - is there firewall settings in the new router that is stopping the comms?
    I never changed ISPs and I don't know how firewall settings in a router can affect a python program running in a raspberry pi, I wouldn't know how to check that.

    If it is relevant the app on my phone, tablet and bluestacks app on my computer all work OK.
    Ok, change of router - same thing. if the new router has firewall rules that apply to internal network routing, they could be blocking the connection.

    You computer to the Tapo will all be over the local network. 192.168.x.x.  What apps run on your phone, table and bluestacks, and are they all local network executed or do they go via the cloud. Do they use the same PyP100 library?

    Not wanting to sound harsh, but you're running someone elses software locally on your computer. Knowing what it does, and about firewalls, is probably a good idea.
  • MeteredOut
    MeteredOut Posts: 2,782 Forumite
    1,000 Posts Second Anniversary Name Dropper
    edited 6 February 2024 at 3:16PM
    I agree with MeteredOut. The code does not handle the exception - it always assumes it can extract the encryption key from the response.
    So the easiest way to find out what's going on is to find out what the response is. It's probably going to be either blank/empty, or an error message, or an empty JSON structure.
    It might be interesting to visit the address it's trying to connect to using a web browser, i.e. http:// (the Tapo's IP here) /app to see what happens.
    I've got a couple of Tapo's.

    When I go to http://{IP]/app, I get a standard 200 OK response

    OP, can you try that in your browser and see if you get the same response?
  • MeteredOut
    MeteredOut Posts: 2,782 Forumite
    1,000 Posts Second Anniversary Name Dropper
    edited 6 February 2024 at 3:24PM
    Another suggestion, if you feel comfortable editing the library code (PyP110.py). Change 

    		r = requests.post(URL, json=Payload)
    
    		encryptedKey = r.json()["result"]["key"]
    		self.tpLinkCipher = self.decode_handshake_key(encryptedKey)
    
    		try:
    			self.cookie = r.headers["Set-Cookie"][:-13]
    
    		except:
    			errorCode = r.json()["error_code"]
    			errorMessage = self.errorCodes[str(errorCode)]
    			raise Exception(f"Error Code: {errorCode}, {errorMessage}")<br>
    to

    		r = requests.post(URL, json=Payload)
    
    		try:
    			<b>encryptedKey = r.json()["result"]["key"]</b>
    			<b>self.tpLinkCipher = self.decode_handshake_key(encryptedKey)</b>
    			self.cookie = r.headers["Set-Cookie"][:-13]
    
    		except:
    			errorCode = r.json()["error_code"]
    			errorMessage = self.errorCodes[str(errorCode)]
    			raise Exception(f"Error Code: {errorCode}, {errorMessage}")<br>

    ie. put the line that is causing the error inside the try/except block. It might cause the true error to bubble up and be displayed to you. But, it might not.

    You could also edit that file to display the response, eg, 

    		r = requests.post(URL, json=Payload)
                    print(r.json())
    		encryptedKey = r.json()["result"]["key"]
    		self.tpLinkCipher = self.decode_handshake_key(encryptedKey)
    
    		try:
    			self.cookie = r.headers["Set-Cookie"][:-13]
    
    		except:
    			errorCode = r.json()["error_code"]
    			errorMessage = self.errorCodes[str(errorCode)]
    			raise Exception(f"Error Code: {errorCode}, {errorMessage}")

  • MeteredOut
    MeteredOut Posts: 2,782 Forumite
    1,000 Posts Second Anniversary Name Dropper
    Interesting. There could be a few different reasons for this

    You don't have the right IP address (ie. you've checked it is the same as the Tapo Device Info, such as this):



    Or, the device you have is no  longer accepting HTTP requests. Do you have the same firmware as I have above?

    Or something on your network is blocking HTTP requests, eg a firewall on your router

    Is your new router on the same subnet as the previous one? eg, 192.168.0.x v 192.168.1.x
  • I agree with MeteredOut. The code does not handle the exception - it always assumes it can extract the encryption key from the response.
    So the easiest way to find out what's going on is to find out what the response is. It's probably going to be either blank/empty, or an error message, or an empty JSON structure.
    It might be interesting to visit the address it's trying to connect to using a web browser, i.e. http:// (the Tapo's IP here) /app to see what happens.
    I've got a couple of Tapo's.

    When I go to http://{IP]/app, I get a standard 200 OK response

    OP, can you try that in your browser and see if you get the same response?
    http://192.168.0.130/app/   gives 200 OK. It needs the /
  • MeteredOut
    MeteredOut Posts: 2,782 Forumite
    1,000 Posts Second Anniversary Name Dropper
    I agree with MeteredOut. The code does not handle the exception - it always assumes it can extract the encryption key from the response.
    So the easiest way to find out what's going on is to find out what the response is. It's probably going to be either blank/empty, or an error message, or an empty JSON structure.
    It might be interesting to visit the address it's trying to connect to using a web browser, i.e. http:// (the Tapo's IP here) /app to see what happens.
    I've got a couple of Tapo's.

    When I go to http://{IP]/app, I get a standard 200 OK response

    OP, can you try that in your browser and see if you get the same response?
    http://192.168.0.130/app/   gives 200 OK. It needs the /
    Ah, mine didn't. I suspect you'll have to try one of the more technical ideas i gave above (code) to give more details on why it might be failing.
  • Hi MeteredOut, any chance of a copy of your PyP100.py file as that is what seems to be the problem, there are various versions of that file.
  • Here is my device info details.
  • MeteredOut
    MeteredOut Posts: 2,782 Forumite
    1,000 Posts Second Anniversary Name Dropper
    edited 12 February 2024 at 5:04PM
    I sent a response to your DM earlier - I just looked at the one on GitHub:

    https://github.com/fishbigger/TapoP100/blob/main/PyP100/PyP100.py

    I have the same P110 hardware/firmware version as you have above

    (note, I've not tried to run the code - I just looked at it. I'll see if I can make some time to try get it running)
  • MeteredOut
    MeteredOut Posts: 2,782 Forumite
    1,000 Posts Second Anniversary Name Dropper
    edited 12 February 2024 at 4:56PM
    I've just done a quick test. The TAPO is returning: 

    {'error_code': 1003}

    It looks like a firmware security update has caused this. 

    See https://community.openhab.org/t/single-tapo-p100-suddenly-stopped-working-error-code-1003/149740

    The Py100 pacakge owner would need to update the package, but since its not been updated in 2 years, I'm not sure that's going to happen.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 349.8K Banking & Borrowing
  • 252.6K Reduce Debt & Boost Income
  • 453K Spending & Discounts
  • 242.8K Work, Benefits & Business
  • 619.6K Mortgages, Homes & Bills
  • 176.4K Life & Family
  • 255.7K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16.1K Discuss & Feedback
  • 15.1K Coronavirus Support Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.