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

I have a python program that reads the details from my Tapo P110 smart socked, well it used to until until I got a new router and  left the socket unplugged for a while.

Now the socket has a new IP address and even though I change the IP address in my program the program will no longer run.

Anyone had this problem and found a solution?

 from PyP100 import PyP110

p110 = PyP110.P110("192.168.X.X", "email@gmail.com", "Password123") #Creating a P110 plug object

p110.handshake() #Creates the cookies required for further methods
p110.login() #Sends credentials to the plug and creates AES Key and IV for further methods

#PyP110 has all PyP100 functions and additionally allows to query energy usage infos
p110.getEnergyUsage() #Returns dict with all the energy usage



«13

Comments

  • DullGreyGuy
    DullGreyGuy Posts: 17,199 Forumite
    10,000 Posts Second Anniversary Name Dropper
    Have you looked in the control panel of the router? With some you can specify that certain devices are assigned fixed IPs and therefore you could revert it back to the old IP address. 
  • MeteredOut
    MeteredOut Posts: 2,742 Forumite
    1,000 Posts Second Anniversary Name Dropper
    edited 5 February 2024 at 7:00PM
    Assuming you've double-checked the new IP address is correct, it should work.

    Any firewall on the new router? What protocol/port does the PyP110 library use to communicate with the device. HTTP? HTTPS?

    What network error does the program provide when it tries to connect?
  • Here is the error message

    Traceback (most recent call last):
      File "/home/pi/tapo/p110.py", line 9, in <module>
        p110.handshake() #Creates the cookies required for further methods
      File "/usr/local/lib/python3.9/dist-packages/PyP100/PyP100.py", line 129, in handshake
        encryptedKey = r.json()["result"]["key"]
    KeyError: 'result'
  • Billxx
    Billxx Posts: 286 Forumite
    Fifth Anniversary 100 Posts Name Dropper Photogenic
    edited 5 February 2024 at 7:40PM
    Put a DHCP reservation in the router for the device (you'll need the MAC address) to fix it's IP address.  Can you ping it?

    Kind Regards,

    Bill
  • Spies
    Spies Posts: 2,241 Forumite
    Part of the Furniture 1,000 Posts Photogenic Name Dropper
    Possible firmware update on the plug preventing this method now working?
    4.29kWp Solar system, 45/55 South/West split in cloudy rainy Cumbria. 
  • MeteredOut
    MeteredOut Posts: 2,742 Forumite
    1,000 Posts Second Anniversary Name Dropper
    edited 6 February 2024 at 10:29AM
    Here is the error message

    Traceback (most recent call last):
      File "/home/pi/tapo/p110.py", line 9, in <module>
        p110.handshake() #Creates the cookies required for further methods
      File "/usr/local/lib/python3.9/dist-packages/PyP100/PyP100.py", line 129, in handshake
        encryptedKey = r.json()["result"]["key"]
    KeyError: 'result'
    Get your coding hat on and dump out the r.json() response. It looks like whoever wrote that package is not error handling (it assumes the response will have a result attribute), and the JSON might well contain the actual error message.

    Have you checked you have the latest package?
  • Here is the error message

    Traceback (most recent call last):
      File "/home/pi/tapo/p110.py", line 9, in <module>
        p110.handshake() #Creates the cookies required for further methods
      File "/usr/local/lib/python3.9/dist-packages/PyP100/PyP100.py", line 129, in handshake
        encryptedKey = r.json()["result"]["key"]
    KeyError: 'result'
    Get your coding hat on and dump out the r.json() response. It looks like whoever wrote that package is not error handling (it assumes the response will have a result attribute), and the JSON might well contain the actual error message.

    Have you checked you have the latest package?
    I did not code it, I lifted it from a web site.

    PyP100 · PyPI

    I think it stopped working because I got my router replaced by Virgin Media when I was upgraded from 132 mbs to 1000 mbs fibre.which probably caused the IP address change which has probably nothing to do with the code no longer working.


  • MeteredOut
    MeteredOut Posts: 2,742 Forumite
    1,000 Posts Second Anniversary Name Dropper
    edited 6 February 2024 at 11:51AM
    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?
  • 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.
  • 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.
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.7K Work, Benefits & Business
  • 619.5K Mortgages, Homes & Bills
  • 176.3K Life & Family
  • 255.6K 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.