home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.75k stars 30k forks source link

Axis cameras only able to use port 80 #8403

Closed stew2000 closed 7 years ago

stew2000 commented 7 years ago

Home Assistant release (0.48.1):

Python release (3.42):

Component/platform: Axis camera

Description of problem: After update to 0.48, Axis cameras using any port other than port 80 would not load.

Additional info: My Axis cameras running on port 80 experienced no issues but the cameras operating on non-standard port settings failed to load after upgrading to 0.48.0. Attempts to delete the cameras and configure from scratch only yielded "failure to register" errors whether configuring manually in configuration.yaml or when utilizing the automatic configurator. Cameras could only be restored in Home Assistant by configuring the units to use port 80.

Kane610 commented 7 years ago

I don't really see why the changes done would really do anything to affect this. But lets see what can be the reason behind this :)

Would you mind being going in to more details on how the cameras are set up and what functions aren't working?

stew2000 commented 7 years ago

Most of my cameras are the Axis 1364 and were configured to discrete ports so that they were reachable behind my home router to the outside world. The cameras were configured to ports 8091, 8092, 8093, etc... Additionally, I have two of the cameras that were set to standard port of 80. After upgrading to HA 48.0, the port 80 cams experienced no issues but all of the other cameras would not initialize on HA startup, meaning the cameras were not found by the system and in the HA log the system appears to only be trying port 80 when searching for the camera before giving up. It doesn't find the camera or any associated motion sensors from them. I then decided to delete my Axis.conf file and let the cameras be detected automatically to setup again. After reboot of HA, the configurator finds the cameras but when I attempt to configure them with login/pass etc.. thru the automatic configurator, the system returns a dialog stating, "Failed to Register Device". The next step was to try setting up the cams manually via the configuration.yaml with individual entries for each camera. Now when HA booted up it would show the labels of the cameras but again was only trying to make a connection to the cameras on port 80 so it failed to find and initialize the camera. After all of this, I set the cameras to all use port 80 and after doing so they were immediately returned to HA upon rebooting. If anyone else is successfully using Axis cameras in a non-standard port on HA 0.48 or greater then I will consider this issue exclusive to me and continue troubleshooting but because of the circumstances under which it arose I felt strongly that it may be an upgrade issue others were also experiencing.

Merlinuf commented 7 years ago

Have the same problem, only works with port 80

Kane610 commented 7 years ago

How do you specify this other port in your HASS config?

Kane610 commented 7 years ago

I have one idea you could try to single out the issue, and that would be to alter the camera/axis.py to the old one to see if that still works (https://github.com/home-assistant/home-assistant/blob/416b8e0efe15566f476c9a516b5f15ff3ef09066/homeassistant/components/camera/axis.py). If it does then you have probably verified that it is my change that affected this.

Merlinuf commented 7 years ago

Hello, thanks for the response. but it wont take the port input that is why i said it only works on port 80. So now i only let hass auto detect them and there is also no way to add port

stew2000 commented 7 years ago

The only way to specify a port other than 80 in HA has always been to add a colon and port number to the end of the IP address. Whether adding cameras in configuration.yaml or by using the automatic configurator when the cameras are discovered and then going into the axis.conf file and adding the colon and port number. This always worked for me on all of my HA cameras but after the Axis component upgrade in 0.48 it would no longer work on my axis cameras until I changed them back to port 80. At your suggestion I rolled back the axis.py file. To get this to work I had to roll back the copy in both the /components AND the /components/camera directories. After doing this the Axis cams were again able to use ports other than 80. It would seem that when parsing the IP address from the config file that it is not capturing the colon or proceding port number after the IP address any longer.

Kane610 commented 7 years ago

Alright, now I understand. Then it is definitely my wrong here. I though you meant that the Axis component stopped working after a upgrade, but you used the mjpeg component previously?

A last small verification and I can make a fix for this

Select one of your cameras and hardcode your port for it directly in the axis camera file.

If you inside the axis camera file (https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/camera/axis.py)

Add a ':' and your port number for one of your cameras after the '{}' on lines 24 and 26.

stew2000 commented 7 years ago

Sorry I dropped off for a while but I was in Hurricane Irma's path last week.

To be very clear, in answer to your first question in the last post: NO, I was not using MJPEG for those cameras previously and YES they did stop working after the upgrade.

The point is that whether Axis cameras were configured manually within the configuration.yaml like this: Example configuration.yaml entry axis: m1065lw: host: IP ADDRESS include:

OR if you let the configurator create an axis.conf file, the result is the same. Home assistant will no longer see the colon and port number added to the ip address like it used to or what I really think after some testing is that it just has some issues with camera discovery and if discovered properly it would see that setting once again in the conf file.

I believe you understand the parsing issue and are on the right track but I tried your suggestion of adding ':' and my port number for one of the cameras after the '{}' on lines 24 and 26. This edit had no effect on the problem but I think it just needed to happen further upstream because that would only fix getting the stream from the camera but since the camera has not been discovered in the first place I decide to place this edit in the component/axis.py file and it worked.

Line 154 of components/axis.py host = discovery_info[CONF_HOST] + ":8094"

After adding the port number to this line in the discovery section, the HA configurator popped up having identified the camera and port number and set the camera up in the system as it should. Live streams and still shots work properly and the port is recognized in config files.

Kane610 commented 7 years ago

I hope everything is OK with you and your family!

I've added a new config option to specifically set the port which should solve your problems. I'm awaiting acceptance of this PR

stew2000 commented 7 years ago

Great News.. Thanks!

(only lost a fence and power for a few days from storm but many got it worse)

Kane610 commented 7 years ago

Glad to hear! Hard to imagine being in the middle of it . Like a catastrophe movie.

When you're back on track (if the PR hasn't gotten merged yet) I'd be glad if you would verify the suggested solution.

Merlinuf commented 7 years ago

9db0f60e-9196-4d94-9c58-98221101802a

My logs are getting raped since I activated my cameras again Maybe due to port problems

Kane610 commented 7 years ago

Would you mind posting the full logs. A screenshot doesn't help much. A PR to fix this has been published. You can try it out if you want to

Merlinuf commented 7 years ago

home-assistant.log.zip

Kane610 commented 7 years ago

@merlinuf yes it looks like the port issue, if the device IP is correct and you've changed your web port. The PR will solve this by allowing you to specify the port in the config.

Merlinuf commented 7 years ago

Okay, ull wait until a release then deactivated cameras in confit for now

stew2000 commented 7 years ago

OK, I tried with the two new files from the PR but it has issues. It throws up an invalid config on the Axis Component with the log complaining about line 186.

home-assistant.zip

Even though the Axis component crashed, the automatic configurator popped up after the two cameras were discovered but any attempts to setup the camera resulted in "Failed To Register" errors. Also, even though the log file shows that it figured out the port numbers for each camera, the automatic configurator didn't seem to be using them and only tried to register the camera on port 80 and I didn't see anywhere to specify it manually. In the picture below you can see that IP address of each cam is listed but not the port, but when I was experimenting a week ago and made the edit of manually adding the port to line 154 of the component file like this: host = discovery_info[CONF_HOST] + ":8094" then the port did show up at the end of the IP address in the configurator (where it is circled in the picture) and let me register the camera. I'm not saying that's where the code change should be but just using it as an example of how the configurator screen looked when I had it working correctly.

error

Kane610 commented 7 years ago

You're right! I had forgotten about adding the configuration to auto discovered devices. It will work if you just add your port as "port": xx in your axis.conf file. I've also pushed an update that would allow you to configure the devices port.

stew2000 commented 7 years ago

Unfortunately I had tried that too before I gave up. Well, I at least tried it like it worked before by adding a colon and port number to the end of the IP in the conf file like it used to work. I didn't try it like I think you mean though, by creating a separate parameter in the conf file.

Kane610 commented 7 years ago

I had also removed a check that would fail the component setup if auto discovery was used but the component didn't have a reference in the configuration.yaml.

The PR is now merged so next release this will be fixed

Kane610 commented 7 years ago

@pvizeli would you mind closing this as it is also solved by #9293

Kane610 commented 7 years ago

@balloob would you mind closing this as it is also solved by #9293