NSPManager / NSPanelManager

Sonoff NSPanel custom firmware for responsive and intuitive use
https://discord.gg/RwXvAH56fE
153 stars 11 forks source link

Wrong/No MQTT user/pass blocks panel from being found #48

Closed phaeton82 closed 1 year ago

phaeton82 commented 1 year ago

When configuring the panel as a test I havent added a user/pass to the configuration. In my Mosquitto logs I can see the device being rejected. In NSPanelManager the panel doesn't appear. It seems that if the device cannot access MQTT it doesn't appear.

I'd suppose it might be nice to be able to correct the mistake from NSPanelManager.

Update Due to the wifi connection being made I could enter the web interface of the device. It allowed me to fix the issue. An update to the docs (FAQ?) might be helpfull. Even though it might be preferable to be able to fix this from the manager (for less advanced users)

tpanajott commented 1 year ago

Thanks for the report. This seems like a strange issue as it should register to the manager but show as offline. I will have to look into this and try to recreate it.

phaeton82 commented 1 year ago

Ahhh, found it! Followed the instructions for the home assistant add-on but missed the configuration instructions which are written down for the docker installation. I added them to the readme. Hope I did that properly.

tpanajott commented 1 year ago

So the panel showed up after you added information for Home Assistant? That shouldn't really matter. The registration of the panel is a HTTP GET request directly to the manager and it should show up even though MQTT is not working. That being said, without MQTT it wont magically appear but a manual refresh of the page should show it.

phaeton82 commented 1 year ago

Nope, still doesn't show :( I'll go through the logs.

tpanajott commented 1 year ago

That's very strange. How is the panel, does it go past the "Registring to manager..."-phase during boot?

phaeton82 commented 1 year ago

I am using MQTT to retrieve logs. Last log is: E0:E2:E6:0C:D4:2C;WARNING; NSPanel.cpp:215 f(.init) No stored MD5 for TFT. Is the panel flashed with NSPanel Manager TFT? Which makes sense. I haven't seen it in the manager so no TFT has been uploaded. It still doesn't show up. What is the best way to see all logs?

phaeton82 commented 1 year ago

changed logging to info... Now I see more

tpanajott commented 1 year ago

Hm, that would be all the logs. You can change the log-level in the web interface for the panel and that affects what logs are sent out via MQTT. But I'll ask again, how does the panel look? Is it stuck on "Registring to manager"?

phaeton82 commented 1 year ago

You mean the panel itself? That might be a thing. It already has a custom TFT. So that TFT now shows. So I dont see any messages there .

current last log: E0:E2:E6:0C:D4:2C;INFO; NSPanel.cpp:186 f(.init) Trying to connect to display.

tpanajott commented 1 year ago

Ah, sorry. My bad, didn't really think. You wont see our boot screen as it not flash, duh... Hm, can you perhaps try to restart the panel and look at the docker container logs? It should show a few requests from the panel.

phaeton82 commented 1 year ago

Found it! Used HTTP:// in the manager address :) Removed it and now it is visible.

phaeton82 commented 1 year ago

thanks for the help. I will help updating some documentation later on. To prevent others like me to fall into some traps

tpanajott commented 1 year ago

Ah, great!

iNaiks commented 1 year ago

I've always this error in MQTT log: disconnected, not authorised

I've used a lot of type of users and passwords but never work. Any idea?

tpanajott commented 1 year ago

I've always this error in MQTT log: disconnected, not authorised

I've used a lot of type of users and passwords but never work. Any idea?

How are you running MQTT?

iNaiks commented 1 year ago

Yes, with this configuration on the add-on (6.2.1)

logins: []
require_certificate: false
certfile: fullchain.pem
keyfile: privkey.pem
customize:
  active: false
  folder: mosquitto
allow_anonymous: true

And the log on the MQTT:

2023-07-30 09:39:51: New connection from 10.0.0.45:62415 on port 1883.  ###this is an nspannel already flashed and I suppose that has the same error
2023-07-30 09:39:51: Client NSPM_NSPn-Nico-180:64:6F:C4:F4:38 disconnected, not authorised.
2023-07-30 09:39:54: New connection from 10.0.0.45:62416 on port 1883.
2023-07-30 09:39:54: Client NSPM_NSPn-Nico-180:64:6F:C4:F4:38 disconnected, not authorised.
2023-07-30 09:39:56: New connection from 10.0.0.45:62417 on port 1883.
2023-07-30 09:39:56: Client NSPM_NSPn-Nico-180:64:6F:C4:F4:38 disconnected, not authorised.
2023-07-30 09:39:58: New connection from 10.0.0.45:62418 on port 1883.
2023-07-30 09:39:58: Client NSPM_NSPn-Nico-180:64:6F:C4:F4:38 disconnected, not authorised.
2023-07-30 09:39:59: New connection from 172.30.32.2:38292 on port 1883. ###This is the connection from the NSPannel manager add-on (installed in home assistant)?
2023-07-30 09:39:59: Client <unknown> closed its connection.
MQTT Add-on

On NSPannel Manager:

NSPannel Manager

But always sais "Failed to connect to MQTT server. Retrying..." on a red label in Pannels View.

I'm using the username and password allocated on the device mqtt in home assistant

Captura de pantalla 2023-07-30 a las 9 46 10

I'm not sure that is this the username and password. But already tried to add a login in the configuration of mqtt add-on and the same think.

On NSPannel Manager add-on appear this log:

Setting /etc/timezone to Europe/Madrid
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.
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 0x7f8f053c3110>: Failed to establish a new connection: [Errno 111] Connection refused'))
Starting server
Watching for file changes with StatReloader
[30/Jul/2023 07:48:58] "GET /api/get_mqtt_manager_config HTTP/1.1" 200 464
INFO:root:Got config, will start MQTT Manager.
DEBUG:environ.environ:get 'MQTT_SERVER' casted as 'None' with default '<NoValue>'. ## some problem starting here?
DEBUG:environ.environ:get 'MQTT_PORT' casted as 'None' with default '<NoValue>'
DEBUG:environ.environ:get 'MQTT_USERNAME' casted as 'None' with default '<NoValue>'
DEBUG:environ.environ:get 'MQTT_PASSWORD' casted as 'None' with default '<NoValue>'
DEBUG:environ.environ:get 'HOME_ASSISTANT_ADDRESS' casted as 'None' with default '<NoValue>'
DEBUG:environ.environ:get 'HOME_ASSISTANT_TOKEN' casted as 'None' with default '<NoValue>'
DEBUG:environ.environ:get 'OPENHAB_ADDRESS' casted as 'None' with default '<NoValue>'
DEBUG:environ.environ:get 'OPENHAB_TOKEN' casted as 'None' with default '<NoValue>'
DEBUG:asyncio:Using selector: EpollSelector
INFO:root:Connecting to HTTP://10.0.0.28:1883 as 'NSPanelManager_02:42:ac:1e:21:0e'
ERROR:root:Failed to connect to MQTT HTTP://10.0.0.28:1883. Will try again in 10 seconds. Code: 0
Traceback (most recent call last):
  File "/usr/src/app/./mqtt_manager.py", line 312, in connect_and_loop
    client.connect(mqtt_server, mqtt_port, 5)
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 914, in connect
    return self.reconnect()
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 1044, in reconnect
    sock = self._create_socket_connection()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 3685, in _create_socket_connection
    return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/socket.py", line 827, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/socket.py", line 962, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno -2] Name or service not known
INFO:websockets.server:server listening on 0.0.0.0:8001
INFO:websockets.server:server listening on [::]:8001
DEBUG:websockets.server:= connection is CONNECTING
DEBUG:websockets.server:< GET / HTTP/1.1
DEBUG:websockets.server:< Host: casarosada.duckdns.org:8001
DEBUG:websockets.server:< Pragma: no-cache
DEBUG:websockets.server:< Accept: */*
DEBUG:websockets.server:< Sec-WebSocket-Key: E4i8lQ9LSE9U67UmskwYTA==
DEBUG:websockets.server:< Sec-WebSocket-Version: 13
DEBUG:websockets.server:< Accept-Language: es-ES,es;q=0.9
DEBUG:websockets.server:< Sec-WebSocket-Extensions: permessage-deflate
DEBUG:websockets.server:< Cache-Control: no-cache
DEBUG:websockets.server:< Accept-Encoding: gzip, deflate
DEBUG:websockets.server:< Origin: http://casarosada.duckdns.org:8000
DEBUG:websockets.server:< User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15
DEBUG:websockets.server:< Connection: Upgrade
DEBUG:websockets.server:< Upgrade: websocket
DEBUG:websockets.server:< Cookie: csrftoken=Sf99pHvKr12KyjnXJc7crFP9qccYAQJC
DEBUG:websockets.server:> HTTP/1.1 101 Switching Protocols
DEBUG:websockets.server:> Upgrade: websocket
DEBUG:websockets.server:> Connection: Upgrade
DEBUG:websockets.server:> Sec-WebSocket-Accept: z7hx/0EccAB/72qV3uL1Ow2xamc=
DEBUG:websockets.server:> Sec-WebSocket-Extensions: permessage-deflate; server_max_window_bits=12
DEBUG:websockets.server:> Date: Sun, 30 Jul 2023 07:48:59 GMT
DEBUG:websockets.server:> Server: Python/3.11 websockets/10.4
INFO:websockets.server:connection open
DEBUG:websockets.server:= connection is OPEN
DEBUG:root:Sending mqttmanager_status.
DEBUG:websockets.server:> TEXT '{"type": "mqttmanager_status", "mqtt": {"connec...e, "connected": false}}' [192 bytes]
DEBUG:websockets.server:< TEXT '{"cmd_id":1,"command":"get_nspanel_status","args":{}}' [53 bytes]
DEBUG:websockets.server:> TEXT '{"cmd_id": 1, "nspanels": {"1": {"id": 1, "mac"...ddress": "10.0.0.45"}}}' [142 bytes]

Thanks for respond so quickly! 🤩

Roukie686868 commented 1 year ago

Remove the HTTP:// part in the MQTT address. Only use that numbers part. I had the same problem.

iNaiks commented 1 year ago

Yesssss, I unistalled mqtt completely and reinstalled and removed the "HTTP" on the add-on. IT WORKS! 🥳

All working fantastic!! Very very thanks! Now I can update the GUI of the NSPannel!

Fantastic project !!!