NSPManager / NSPanelManager

Sonoff NSPanel custom firmware for responsive and intuitive use
https://nspanelmanager.com/
126 stars 10 forks source link

Failed to connect to MQTT server. Readying... #113

Open zminde opened 6 months ago

zminde commented 6 months ago

Log of the nspanel manager add-on is "INFO: root: Connected to MQTT Server"

Enyone know that? Thanks.

20231207_174113.jpg

tpanajott commented 6 months ago

Have you configured the mqtt-settings in the settings-page in the manager?

zminde commented 6 months ago

Have you configured the mqtt-settings in the settings-page in the manager?

Thank for your reply,. yes, I already configured mqtt information in the settings-page, and the log info below :

Setting /etc/timezone to Asia/Shanghai Running migrations... Home Assistant token has changed. Will update database. Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions, web Running migrations: No migrations to apply. Starting server ERROR:root:ERROR: Failed to get config. Will try again in 5 seconds. ERROR:root:HTTPConnectionPool(host='127.0.0.1', port=8000): Max retries exceeded with url: /api/get_mqtt_manager_config (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f92be82c590>: Failed to establish a new connection: [Errno 111] Connection refused')) Watching for file changes with StatReloader INFO:root:Got config, will start MQTT Manager. DEBUG:environ.environ:get 'MQTT_SERVER' casted as 'None' with default '' DEBUG:environ.environ:get 'MQTT_PORT' casted as 'None' with default '' DEBUG:environ.environ:get 'MQTT_USERNAME' casted as 'None' with default '' DEBUG:environ.environ:get 'MQTT_PASSWORD' casted as 'None' with default '' DEBUG:environ.environ:get 'HOME_ASSISTANT_ADDRESS' casted as 'None' with default '' DEBUG:environ.environ:get 'HOME_ASSISTANT_TOKEN' casted as 'None' with default '' DEBUG:environ.environ:get 'OPENHAB_ADDRESS' casted as 'None' with default '' DEBUG:environ.environ:get 'OPENHAB_TOKEN' casted as 'None' with default '' [07/Dec/2023 10:25:26] "GET /api/get_mqtt_manager_config HTTP/1.1" 200 365 DEBUG:asyncio:Using selector: EpollSelector INFO:root:Connecting to 192.168.0.240:1883 as 'NSPanelManager_02:42:ac:1e:21:09' DEBUG:environ.environ:get 'IS_HOME_ASSISTANT_ADDON' casted as 'None' with default '' INFO:root:Connecting to Home Assistant at ws://supervisor/core/websocket INFO:root:OpenHAB values not configured, will not connect. INFO:root:Connected to MQTT Server INFO:root:Connected to MQTT Server INFO:root:WebSocket connection to Home Assistant opened. DEBUG:asyncio:Using selector: EpollSelector DEBUG:root:Sending mqttmanager_status. INFO:root:Sending auth to Home Assistant INFO:root:Home Assistant auth OK. Requesting existing states. DEBUG:asyncio:Using selector: EpollSelector DEBUG:root:Sending mqttmanager_status. DEBUG:root:Sending mqttmanager_status. DEBUG:root:Sending mqttmanager_status. INFO:root:Connected to MQTT Server INFO:root:Connected to MQTT Server ...

tpanajott commented 6 months ago

It doesn't look like there are any values stored for mqtt for the manager. Are there any values shown on the page?

zminde commented 6 months ago

Please forgive me, I know that the log info contains a lot of information, but I don't know what information is helpful in solving the problem. I saw some error messages, but I don't know whether this is the cause of the problem.

... connection handler failed Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1302, in close_connection await self.transfer_data_task File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 959, in transfer_data message = await self.read_message() ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1029, in read_message frame = await self.read_data_frame(max_size=self.max_size) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1104, in read_data_frame frame = await self.read_frame(max_size) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1161, in read_frame frame = await Frame.read( ^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/websockets/legacy/framing.py", line 68, in read data = await reader(2) ^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/asyncio/streams.py", line 734, in readexactly await self._wait_for_data('readexactly') File "/usr/local/lib/python3.12/asyncio/streams.py", line 527, in _wait_for_data await self._waiter asyncio.exceptions.CancelledError The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/websockets/legacy/server.py", line 240, in handler await self.ws_handler(self) File "/usr/src/app/mqtt_manager_libs/websocket_server.py", line 30, in _connection_handler async for message in websocket: File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 497, in aiter yield await self.recv() ^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 568, in recv await self.ensure_open() File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 944, in ensure_open raise self.connection_closed_exc() websockets.exceptions.ConnectionClosedError: sent 1011 (unexpected error) keepalive ping timeout; no close frame received connection handler failed Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 959, in transfer_data message = await self.read_message() ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1029, in read_message frame = await self.read_data_frame(max_size=self.max_size) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1104, in read_data_frame frame = await self.read_frame(max_size) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 1161, in read_frame frame = await Frame.read( ^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/websockets/legacy/framing.py", line 68, in read data = await reader(2) ^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/asyncio/streams.py", line 734, in readexactly await self._wait_for_data('readexactly') File "/usr/local/lib/python3.12/asyncio/streams.py", line 527, in _wait_for_data await self._waiter File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 1009, in _read_ready__data_received data = self._sock.recv(self.max_size) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ConnectionResetError: [Errno 104] Connection reset by peer The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/websockets/legacy/server.py", line 240, in handler await self.ws_handler(self) File "/usr/src/app/mqtt_manager_libs/websocket_server.py", line 30, in _connection_handler async for message in websocket: File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 497, in aiter yield await self.recv() ^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 568, in recv await self.ensure_open() File "/usr/local/lib/python3.12/site-packages/websockets/legacy/protocol.py", line 935, in ensure_open raise self.connection_closed_exc() websockets.exceptions.ConnectionClosedError: no close frame received or sent INFO:root:Connected to MQTT Server INFO:root:Connected to MQTT Server

tpanajott commented 6 months ago

The thing is this message: MQTT_SERVER' casted as 'None' with default ''

It indicates that there is not mqtt server address configured. The same applies for port, username and password.

zminde commented 6 months ago

The thing is this message: MQTT_SERVER' casted as 'None' with default ''

It indicates that there is not mqtt server address configured. The same applies for port, username and password.

I have indeed configured the mqtt server information on the settings page and used the default port 1883. Since the mqtt server does not require authentication, use the default blanks in the username and password fields. 20231207_193139.jpg

tpanajott commented 6 months ago

Well, that looks right so I wonder why it didn't use those values. Have you tried restarting the addon/container? Shouldn't be necessary but might as well try.

zminde commented 6 months ago

Just after I try to enter the MQTT server username and password, it seems that the problem disappears, the red banner of the web page is not, although there is still no MQTT information in log info.

zminde commented 6 months ago

Well, that looks right so I wonder why it didn't use those values. Have you tried restarting the addon/container? Shouldn't be necessary but might as well try.

after trying every possible way it looks like the problem is solved as the red banner is gone. Still not sure if the issue is actually resolved, anyway thank you for your continued help with the issues I'm having.

Stoffe commented 6 months ago

Im having similar problems, using the docker container nspanelmanager/nspanelmanager-amd64:latest After setting the MQTT settings in the Settings page, I get the red banner popping up, looking in the logs it says the following:


Starting server Watching for file changes with StatReloader [14/Dec/2023 14:16:20] "GET /api/get_mqtt_manager_config HTTP/1.1" 200 365 INFO:root:Got config, will start MQTT Manager. DEBUG:environ.environ:get 'MQTT_SERVER' casted as 'None' with default '' DEBUG:environ.environ:get 'MQTT_PORT' casted as 'None' with default '' DEBUG:environ.environ:get 'MQTT_USERNAME' casted as 'None' with default '' DEBUG:environ.environ:get 'MQTT_PASSWORD' casted as 'None' with default '' DEBUG:environ.environ:get 'HOME_ASSISTANT_ADDRESS' casted as 'None' with default '' DEBUG:environ.environ:get 'HOME_ASSISTANT_TOKEN' casted as 'None' with default '' DEBUG:environ.environ:get 'OPENHAB_ADDRESS' casted as 'None' with default '' DEBUG:environ.environ:get 'OPENHAB_TOKEN' casted as 'None' with default '' DEBUG:asyncio:Using selector: EpollSelector INFO:root:Connecting to xxx.xxx.xxx.xxx:1883 as 'NSPanelManager_xx:xx:xx:xx:xx:xx' INFO:root:Connecting to Home Assistant at ws://xxx.xxx.xxx.xxx:8123/api/websocket INFO:root:OpenHAB values not configured, will not connect. INFO:root:Connected to MQTT Server INFO:root:WebSocket connection to Home Assistant opened. DEBUG:asyncio:Using selector: EpollSelector DEBUG:root:Sending mqttmanager_status.


Looking in my MQTT logs I get the following:

2023-12-14 15:19:14: New client connected from xxx.xxx.xxx.xxx:54265 as NSPanelManager_xx:xx:xx:xx:xx:xx (p2, c1, k5, u'MQTTuser').


(obviously, I replaced the mac and ips with 'x' :) and the username with a fake one)

So, apparently, there is some sort of connection beeing made, but the red banner is comming up all the time, and looking in the logs it seems like there are no values, but the values are there in the settings page and retained thru restarts (so Im guessing its in the sqlite db)

There seems to be some problems here at least with the latest docker container.

Stoffe commented 6 months ago

Just to add a comment, that if I look with MQTT Explorer, I see a topic, nspanel, with 2 subs in it, one config and one status. So, apparently, it is communicating with the MQTT server, however there is still the red banner telling me there is something wrong with the MQTT Manager... Not really sure why that is, it would have been nice with a log message here to why that is...

tpanajott commented 6 months ago

Hey, sorry I can't really help you all that much right now. Feeling pretty sick but you could have a look at the logs for the container itself. That should say why it doesn't work.

Stoffe commented 6 months ago

Yeah, those are the logs I sent in my previous comment, the first ones are from the container itself, and the second ones are from the mqtt server. So, not making me any more wiser unfortunately. :/

tpanajott commented 2 months ago

Hi @Stoffe, it's been a while. I'm sorry I couldn't figure something out about the above issue, simply couldn't replicate it. There is currently a beta available if you want to have a try at it again. The whole MQTTManager backend portion of the project has been rewritten from messy python to a more structured C++ approach.

I will leave this issue open a bit longer and close it in the future if there is no new development in this issue.