From 82e5518961f41a6aad1d651f05869319426d39bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20L=C3=A9tal?= Date: Thu, 30 Jul 2026 14:52:56 +0200 Subject: [PATCH] Log the server's error when registration is refused MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A refused registration is currently silent. RegisterResponse carries the reason in Error — "invalid key: API key does not exist" for a bad auth key — but do_register() only reads Node, which a successful response omits too, so nothing tells the two apart. The first visible symptom is therefore "node not found" from the MapRequest that follows, reported by a different function and pointing at peer fetching rather than at the key: E ml_coord: RegisterResponse error: invalid key: API key does not exist (new) E ml_coord: MapResponse JSON parse failed near: node not found (was all) Tested against controlplane.tailscale.com on an ESP32-S3, with an unknown machine key and an invalid auth key. (cherry picked from commit 4cc3ddeddff3d65505fe4cc9cfa597c9bc51aa1b) Upstream-PR: CamM2325/microlink#23 --- components/microlink/src/ml_coord.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/microlink/src/ml_coord.c b/components/microlink/src/ml_coord.c index 8da8d4d..7a02812 100644 --- a/components/microlink/src/ml_coord.c +++ b/components/microlink/src/ml_coord.c @@ -944,6 +944,14 @@ static int do_register(microlink_t *ml, ml_noise_state_t *noise) { free(resp_buf); return 0; /* Not fatal - we'll get peers in MapResponse */ } + /* The server reports a refused registration only in Error — a rejected auth + * key gives "invalid key: unable to validate API key". Node is absent either + * way, so without this the first symptom is MapResponse "node not found". */ + const cJSON *reg_error = cJSON_GetObjectItem(resp_json, "Error"); + if (cJSON_IsString(reg_error) && reg_error->valuestring[0] != '\0') { + ESP_LOGE(TAG, "RegisterResponse error: %s", reg_error->valuestring); + } + parse_start[parse_len] = saved; free(resp_buf);