From 2c093032b57e8d6a54d09d58d9d729d211bd33f2 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sun, 13 Feb 2022 19:52:24 +0200 Subject: [PATCH 1/5] Remove a noisy debug statement from WSClient::connect --- src/sensesp/net/ws_client.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/sensesp/net/ws_client.cpp b/src/sensesp/net/ws_client.cpp index eeffde9e5..c2065f2ca 100644 --- a/src/sensesp/net/ws_client.cpp +++ b/src/sensesp/net/ws_client.cpp @@ -367,9 +367,6 @@ bool WSClient::get_mdns_service(String& server_address, uint16_t& server_port) { } void WSClient::connect() { - debugI("WSClient websocket connect attempt (state=%d)", - get_connection_state()); - if (get_connection_state() != WSConnectionState::kWSDisconnected) { return; } From 0ba099882233fe405093062b9685f4e564c81e76 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Mon, 14 Feb 2022 12:04:41 +0200 Subject: [PATCH 2/5] Validate the token using the websocket endpoint --- src/sensesp/net/ws_client.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/sensesp/net/ws_client.cpp b/src/sensesp/net/ws_client.cpp index c2065f2ca..afd27b25d 100644 --- a/src/sensesp/net/ws_client.cpp +++ b/src/sensesp/net/ws_client.cpp @@ -425,10 +425,11 @@ void WSClient::test_token(const String server_address, HTTPClient http; String url = - String("http://") + server_address + ":" + server_port + "/signalk/"; + String("http://") + server_address + ":" + server_port + "/signalk/v1/stream"; debugD("Testing token with url %s", url.c_str()); http.begin(wifi_client_, url); - String full_token = String("JWT ") + auth_token_; + String full_token = String("Bearer ") + auth_token_; + debugD("Authorization: %s", full_token.c_str()); http.addHeader("Authorization", full_token.c_str()); int httpCode = http.GET(); if (httpCode > 0) { @@ -441,8 +442,9 @@ void WSClient::test_token(const String server_address, } else { debugD("Returned payload is empty"); } - if (httpCode == 200) { - // our token is valid, go ahead and connect + if (httpCode == 426) { + // HTTP status 426 is "Upgrade Required", which is the expected + // response for a websocket connection. debugD("Attempting to connect to Signal K Websocket..."); server_detected_ = true; token_test_success_ = true; @@ -588,7 +590,7 @@ void WSClient::connect_ws(const String host, const uint16_t port) { set_connection_state(WSConnectionState::kWSConnecting); this->client_.begin(host, port, path); this->client_.onEvent(webSocketClientEvent); - String full_token = String("JWT ") + auth_token_; + String full_token = String("Bearer ") + auth_token_; this->client_.setAuthorization(full_token.c_str()); } From 3a7c858e7f730998ae52893d73ba96bee0b0196e Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Mon, 14 Feb 2022 14:26:37 +0200 Subject: [PATCH 3/5] Add debug information on network settings --- src/sensesp/net/networking.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sensesp/net/networking.cpp b/src/sensesp/net/networking.cpp index a4afe468b..09279cf2d 100644 --- a/src/sensesp/net/networking.cpp +++ b/src/sensesp/net/networking.cpp @@ -80,6 +80,8 @@ void Networking::wifi_station_connected() { debugI("Connected to wifi, SSID: %s (signal: %d)", WiFi.SSID().c_str(), WiFi.RSSI()); debugI("IP address of Device: %s", WiFi.localIP().toString().c_str()); + debugI("Default route: %s", WiFi.gatewayIP().toString().c_str()); + debugI("DNS server: %s", WiFi.dnsIP().toString().c_str()); this->emit(WifiState::kWifiConnectedToAP); } From ab7674f059486af67405d2ef3e8f4517d35795f4 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Mon, 14 Feb 2022 14:27:16 +0200 Subject: [PATCH 4/5] Fix mDNS responder log output --- src/sensesp/net/discovery.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sensesp/net/discovery.cpp b/src/sensesp/net/discovery.cpp index 235ea8c84..a8cb7adc3 100644 --- a/src/sensesp/net/discovery.cpp +++ b/src/sensesp/net/discovery.cpp @@ -18,7 +18,7 @@ void MDNSDiscovery::start() { if (!MDNS.begin(hostname.c_str())) { // Start the mDNS responder for hostname.local debugW("Error setting up mDNS responder"); } else { - debugI("mDNS responder started at %s", hostname); + debugI("mDNS responder started for hostname '%s'", hostname.c_str()); } mdns_instance_name_set(hostname.c_str()); // mDNS hostname for ESP32 MDNS.addService("http", "tcp", 80); From f82800001ec7b800d5c34e8aff31918aac4fd8e1 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Mon, 14 Feb 2022 14:27:39 +0200 Subject: [PATCH 5/5] Add some debugging about the access request URL and headers --- src/sensesp/net/ws_client.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sensesp/net/ws_client.cpp b/src/sensesp/net/ws_client.cpp index afd27b25d..0698aab72 100644 --- a/src/sensesp/net/ws_client.cpp +++ b/src/sensesp/net/ws_client.cpp @@ -479,10 +479,13 @@ void WSClient::send_access_request(const String server_address, String json_req = ""; serializeJson(doc, json_req); + debugD("Access request: %s", json_req.c_str()); + HTTPClient http; String url = String("http://") + server_address + ":" + server_port + "/signalk/v1/access/requests"; + debugD("Access request url: %s", url.c_str()); http.begin(wifi_client_, url); http.addHeader("Content-Type", "application/json"); int httpCode = http.POST(json_req);