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 protected]", "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: 9,182
    First Anniversary First Post Name Dropper
    Forumite
    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: 1,123
    First Post First Anniversary Name Dropper
    Forumite
    edited 5 February at 6: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?
  • JohnSwift10
    JohnSwift10 Posts: 261
    First Anniversary First Post Name Dropper
    Forumite
    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: 206
    First Anniversary First Post Name Dropper Photogenic
    Forumite
    edited 5 February at 6: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: 1,951
    First Post Photogenic First Anniversary Name Dropper
    Forumite
    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: 1,123
    First Post First Anniversary Name Dropper
    Forumite
    edited 6 February at 9: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?
  • JohnSwift10
    JohnSwift10 Posts: 261
    First Anniversary First Post Name Dropper
    Forumite
    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: 1,123
    First Post First Anniversary Name Dropper
    Forumite
    edited 6 February at 10: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?
  • JohnSwift10
    JohnSwift10 Posts: 261
    First Anniversary First Post Name Dropper
    Forumite
    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.
  • AstonSmith
    AstonSmith Posts: 138
    First Anniversary First Post Photogenic Name Dropper
    Forumite
    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

Categories

  • All Categories
  • 341.8K Banking & Borrowing
  • 249.7K Reduce Debt & Boost Income
  • 449.2K Spending & Discounts
  • 233.9K Work, Benefits & Business
  • 606.1K Mortgages, Homes & Bills
  • 172.5K Life & Family
  • 246.8K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 15.8K Discuss & Feedback
  • 15.1K Coronavirus Support Boards