B4R Question Why does the serial debugging assistant output the entire response?

byz

Active Member
Licensed User
Why does the serial debugging assistant output the entire response?Actually, I only need the content between ******************************* to be returned.
B4R:
Sub Process_Globals
    Public Serial1 As Serial
    Private wifi As ESP8266WiFi
    Private timer1 As Timer
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    'example of connecting to a local network
    If wifi.Connect2("HONOR 20", "12345678") Then
        Log("connect WiFi")
        Log(JoinStrings(Array As String("esp8266 IP :",wifi.LocalIp)))
        HttpJob.Initialize("getip")
        timer1.Initialize("Timer1_Tick",10000)
        timer1.Enabled=True
    Else
        Log(" WiFi filed")
    End If
End Sub

Private Sub Timer1_Tick
    HttpJob.Download("https://ipservice.ws.126.net/locate/api/getLocByIp")
End Sub

Sub JobDone (Job As JobResult)
    Log("*******************************")
    If Job.Success Then
        If Job.JobName = "getip" Then
            Log(Job.Response)
        End If
    Else
        Log("ErrorMessage: ", Job.ErrorMessage)
        Log("Status: ", Job.Status)
        Log(Job.Response)
    End If
    Log("*******************************")
End Sub

serial' http response:
trying to connect to: ipservice.ws.126.net port: 443 ssl: 1

connected: ipservice.ws.126.net

HTTP/1.1 200 OK
Server: nginx
Date: Sat, 13 Apr 2024 10:31:08 GMT
Content-Type: application/json;
 charset=utf-8
Content-Length: 361
Connection: close
Vary: Accept-Encoding
vary: Accept-Encoding

x-envoy-upstream-service-time: 9
X-Content-From: netease

{"message":"查询成功","status":20
0,"result":{"administrativeCode":"32300","areaCode":"86","areaLat":"31.74043","areaLng":"119.57757"
,"city":"city1","company":"chinaunicom.com","continentCode":"AP","country":"china","countrySymbol"
:"CN","ip":"172.195.38.71","network":"AP","operator":"联通","province":"江苏","timezone":"Asia/S
hanghai","utc":"UTC+8"}}
*******************************
{"message":"查询成功","status":20
0,"result":{"administrativeCode":"32300","areaCode":"86","areaLat":"31.74043","areaLng":"119.57757"
,"city":"city1","company":"chinaunicom.com","continentCode":"AP","country":"china","countrySymbol"
:"CN","ip":"172.195.38.71","network":"AP","operator":"联通","province":"江苏","timezone":"Asia/S
hanghai","utc":"UTC+8"}}
*******************************

i use:
esp8266 ch340 wifi
b4r 4.0
openjdk14
Arduino IDE 2.3.2
 

Attachments

  • b4r test.zip
    1.2 KB · Views: 95

Daestrum

Expert
Licensed User
Longtime User
Could you not use something like (not tested)
B4X:
Dim resp As String = Job.Response
Log(resp.SubString(resp , resp.IndexOf("{")))
as { appears to be the start of the data you want.
 
Upvote 0

byz

Active Member
Licensed User
Could you not use something like (not tested)
B4X:
Dim resp As String = Job.Response
Log(resp.SubString(resp , resp.IndexOf("{")))
as { appears to be the start of the data you want.
Even if I don't output anything, the HTTP response returns the entire content of the request.?I wonder if @Erel forgot to close the library's debug output
 
Upvote 0

byz

Active Member
Licensed User
I found the reason in the rHttpUtils2.b4xlib source code
1713010696839.png
 
Upvote 0
Top