fix: NTRIP v2 compatibility + flush() for reliable ESP32 connection#5
Open
yasunorioi wants to merge 1 commit into
Open
fix: NTRIP v2 compatibility + flush() for reliable ESP32 connection#5yasunorioi wants to merge 1 commit into
yasunorioi wants to merge 1 commit into
Conversation
Problem: - Intermittent timeout when connecting to BKG-style NTRIP casters - ESP32 WiFiClient::print() does not guarantee immediate TCP send without flush(), causing some casters to time out waiting for the complete request - Only NTRIP v1 response (ICY 200 OK) was accepted, but many modern casters respond with HTTP/1.1 200 OK (NTRIP v2) Changes: - Add flush() after print() in reqSrcTbl() and reqRaw() to ensure the HTTP request is fully transmitted before waiting for response - Upgrade request to HTTP/1.1 with Host header and Ntrip-Version: 2.0 - Accept both v1 (ICY 200 OK) and v2 (HTTP/1.1 200, HTTP/1.0 200) responses - Skip HTTP response headers when connecting to v2 casters - Fix inverted strncmp() logic in reqSrcTbl() (was returning false on success) - Add stop() on connection failure to clean up socket resources - Harden readLine() with per-byte timeout and buffer overflow guard - Reduce reqRaw() timeout from 20s to 10s for faster failure detection Tested against: - rtk.toiso.fit:2101 (NTRIP v1, ICY 200 OK) - BKG-style casters (NTRIP v2, HTTP/1.1 200 OK) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
flush()afterprint()to ensure HTTP request is fully sent on ESP32 (lwIP stack does not guarantee immediate TCP send without flush)HTTP/1.1 200 OK,HTTP/1.0 200 OK) in addition to v1 (ICY 200 OK)readLine()with per-byte timeout and buffer overflow guardprint()後にflush()を追加し、HTTPリクエストの送信を確実にしました(lwIPスタックはflush()なしでは即時TCP送信を保証しません)ICY 200 OK)に加え、v2レスポンス(HTTP/1.1 200 OK、HTTP/1.0 200 OK)に対応しましたreadLine()にバイト単位のタイムアウトとバッファオーバーフローガードを追加しました
Problem
Intermittent timeout when connecting to BKG-style NTRIP casters. The root cause is twofold:
Missing flush(): On ESP32, WiFiClient::print() buffers data internally. Without flush(), the TCP segment may not be sent immediately, causing casters to time out waiting for the complete request.
v1-only response parsing: Many modern NTRIP casters (especially BKG-based) respond with HTTP/1.1 200 OK (NTRIP v2 protocol), which was not recognized.
BKG系NTRIPキャスターへの接続時に、断続的にタイムアウトが発生する問題です。原因は2つあります:
flush()の欠落: ESP32のWiFiClient::print()は内部バッファにデータを保持します。
flush()なしではTCPセグメントが即座に送信されず、キャスターがリクエスト待ちでタイムアウトすることがあります。v1レスポンスのみ対応: 多くの現代的なNTRIPキャスター(特にBKG系)は
HTTP/1.1 200 OK(NTRIP v2プロトコル)で応答しますが、従来のコードでは認識できませんでした。reqSrcTbl()のstrncmp()戻り値チェックが反転していた問題を修正(成功時にfalseを返していた)stop()を呼びソケットリソースを解放するよう修正reqRaw()のタイムアウトを20秒から10秒に短縮し、障害検出を高速化Additional fixes
Tested against
Changes
Only src/NTRIPClient.cpp is modified. No changes to the header file or examples.
変更は
src/NTRIPClient.cppのみです。ヘッダーファイルやexamplesへの変更はありません。