B4R Question HttpJob Anwers

Blueforcer

Well-Known Member
Licensed User
Longtime User
Im using erels HttpJob Module to fetch weatherdata from the apixu API.
The download link with a Test API Key is
B4X:
http://api.apixu.com/v1/current.json?key=302824eba4de44efa0a134505181911&q=Maintal

while my PC Browser gives me

B4X:
{"location":{"name":"Maintal","region":"Hessen","country":"Germany","lat":50.15,"lon":8.83,"tz_id":"Europe/Berlin","localtime_epoch":1542635731,"localtime":"2018-11-19 14:55"},"current":{"temp_c":6.0,"condition":{"icon":"//cdn.apixu.com/weather/64x64/day/296.png"},"uv":2.0}}

the HttpJob response in B4R is only
B4X:
P/1.1 200 OK
Cache-Control: private
Content-Type: application/json; charset=utf-8
X-Powered-By

The most time something from the response is cut off and every request its a different length.
very rare i get the desired JSON, but also there some bytes are missing
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Tested with this code on an ESP8266:
B4X:
#Region Project Attributes
   #AutoFlushLogs: True
   #CheckArrayBounds: True
   #StackBufferSize: 600
#End Region

Sub Process_Globals
   Public Serial1 As Serial
   Private wifi As ESP8266WiFi
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   If wifi.Connect("dlink") Then
       Log("Connected to router.")
   Else
       Log("Failed to connect to router.")
       Return
   End If
   HttpJob.Initialize("Example")
   HttpJob.Download("http://api.apixu.com/v1/current.json?key=302824eba4de44efa0a134505181911&q=Maintal")
End Sub


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

Works fine here.
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
youre right.
With this minimal example it works..
But why not in my project?
Still getting something like that

B4X:
*******************************
JobName: WeatherApp
Response: P/1.1 200 OK
Cache-Control: private
Content-Type: application/json; charset=utf-8
X-Powered-By: ASP.NET
access-control-allow-origin: *
access-control-allow-headers: content-type
Date: Tue, 20

thats really weird
I think its exactly the same (exept the project size)
Ive uploaded my project inkl. the needed (modified) Libs.
The magic happens in WeatherApp.bas
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
Well...its caused by WiFiUDP AND WiFiServerSocket.
How can i fix this? i need it..
 
Last edited:
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
Stop before the httpJob and start after response doesnt work.

B4X:
Sub inizialize
    socket.Initialize(51042, "server_NewConnection")
    Start
End Sub

Sub Start
    udp.Initialize(52829,"PacketArrived")
    socket.Listen
End Sub

Sub Stop
    udp.Close
    socket.Socket.Close
End Sub
 
Last edited:
Upvote 0
Top