Android Question NTRIP Mount Points

Terradrones

Active Member
Hi All

I need help again please. I want to access the Service Provider (www.trignet.co.za) that has GPS Base Stations all over South Africa that transmits GPS corrections. I have registered with Trignet and have a Username and Password. I also know the IP address and Port number of Trignet.

I am trying to access the mountpoints with the following code:

B4X:
Sub FindMountPoints
    Dim su As StringUtils
    Dim HttpClient As HttpJob
    HttpClient.Initialize("NTRIP", Me)
    
    ' Set the NTRIP caster URL and credentials
    Dim IPAddress As String = CGlobals.DF(64)
    Dim Port As String = CGlobals.DF(65)
    Dim NTRIP_URL As String = "http://" & IPAddress & ":" & Port '& "/caster"
    Dim Username As String = CGlobals.DF(66)
    Dim Password As String = CGlobals.DF(67)
    
    ProgressDialogShow2("Searching Mount Points...", True)
    
    Dim AuthString As String = Username & ":" & Password
    Dim AuthHeader As String = "Basic " & su.EncodeBase64(AuthString.GetBytes("UTF8"))
    HttpClient.Download(NTRIP_URL)
    
    ' Set headers before sending the request
    HttpClient.GetRequest.SetHeader("Authorization", AuthHeader)
    HttpClient.GetRequest.SetHeader("User-Agent", "Ceaser")
    HttpClient.GetRequest.SetHeader("Accept", "*/*")
    HttpClient.GetRequest.SetHeader("Connection", "close")
    
    ' Send the request
'    HttpClient.Download(NTRIP_URL)
End Sub

Sub JobDone (Job As HttpJob)
    If Job.Success Then
        CmbMountPoints.cmbBox.Clear
        Dim response As String = Job.GetString
'        Log("NTRIP Response: " & response)
        
        ' Process the NTRIP data here to extract mount points
        Dim MountPoints As List
        MountPoints.Initialize
        Dim Lines() As String = Regex.Split(CRLF, response)
        For Each Line As String In Lines
            Log(Line)
            If Line.StartsWith("STR") Then
                CmbMountPoints.cmbBox.Add(Line)
'                Log(Line)
                MountPoints.Add(Line)
            End If
        Next
        Log("Available Mount Points: " & MountPoints)
    Else
        Log("Job failed: " & Job.ErrorMessage)
        Log("HTTP Status Code: " & Job.Response.StatusCode) ' Log the status code for more details
'        Log("Full Response: " & Job.GetString) ' Log the full response to understand why it fails
        MsgboxAsync("Mount Points Are Not Available" & CRLF & "The Server Might Be Down", "No Mount Points")
    End If
    Job.Release
    ProgressDialogHide
End Sub

It is giving me the following error:

ResponseError. Reason: java.net.ProtocolException: Unexpected status line: SOURCETABLE 200 OK, Response:
Job failed: java.net.ProtocolException: Unexpected status line: SOURCETABLE 200 OK
HTTP Status Code: -1

What does "sourcetable 200 ok" mean?
 

Terradrones

Active Member
Thanks.

I have now used a Socket and I can connect, but I do not receive anything back from Trignet for the GPS corrections.

A question: if I have the IP Address and the Port number, surely that is all that I require to access the correct "room" on the Website?

Modified code:

B4X:
Sub GetMountPoints_Click
    'Get the Mount Points

    Select Case CGlobals.DF(50)
        Case 1
            'Leica
        Case 2
            'Emlid
            FindMountPoints
        Case 3,4,5,10
            'Foif, Rinonav,E-Survey, StoneX
            FindMountPoints
        Case 6
            'Tersus
            FindMountPoints
        Case 7
            'Geomax
        Case 8
            'ComNav
        Case 9
            'CHC
    End Select
End Sub

Sub FindMountPoints
    sckt.Initialize("sckt")
    sckt.Connect(CGlobals.DF(64), CGlobals.DF(65), 5000)     'DF(64)=IP Address & DF(65)=Port
End Sub

Sub sckt_Connected(Successful As Boolean)
    If Successful Then
        Log("Connection successful")
        
        ' Build NTRIP request message
        Dim msg As String
        'msg = "GET /caster HTTP/1.1" & CRLF ' Switching to HTTP/1.1
        msg = "GET /HTTP/1.1" & CRLF
        msg = msg & "Host: " & CGlobals.DF(64) & CRLF
        msg = msg & "User-Agent: NTRIP Client" & CRLF
        msg = msg & "Accept: */*" & CRLF
        msg = msg & "Connection: close" & CRLF
        
        ' Add authorization header if username and password are provided
        If CGlobals.DF(66).Length > 0 And CGlobals.DF(67).Length > 0 Then        'DF(66)=User Name & DF(67)=Password
            Dim credentials As String = CGlobals.DF(66) & ":" & CGlobals.DF(67)
            Dim data() As Byte = credentials.GetBytes("UTF8")
            Dim auth As String = su.EncodeBase64(data)
            msg = msg & "Authorization: Basic " & auth & CRLF
        End If
        msg = msg & CRLF
        
        Log("Request message: " & msg)

        ' Initialize AsyncStreams
        AStream.Initialize(sckt.InputStream, sckt.OutputStream, "AStream")
        
        ' Send request
        AStream.Write(msg.GetBytes("UTF8"))
    Else
        Log("Connection failed")
    End If
End Sub

Sub AStream_NewData(Buffer() As Byte)
    Dim receivedData As String = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
    Log("Received Data Chunk: " & receivedData)
    response = response & receivedData
End Sub

Sub AStream_Terminated
    Log("Connection terminated. Full response: " & response)
    
    ' Process the response here
    Dim mountPoints As List = ParseMountPoints(response)
    For Each mountPoint As String In mountPoints
        Log(mountPoint)
    Next
End Sub

Sub ParseMountPoints(response1 As String) As List
    Dim mountPoints As List
    mountPoints.Initialize
    Dim lines() As String = Regex.Split(CRLF, response1)
    For Each line As String In lines
        If line.StartsWith("STR;") Then ' NTRIP response contains lines starting with "STR;" for mount points
            mountPoints.Add(line)
        End If
    Next
    Return mountPoints
End Sub

Any ideas?

Thank you
Michael
 
Upvote 0
Top