B4R Question HttpJob Anwers

Discussion in 'B4R Questions' started by Blueforcer, Nov 19, 2018.

  1. Blueforcer

    Blueforcer Active Member Licensed User

    Im using erels HttpJob Module to fetch weatherdata from the apixu API.
    The download link with a Test API Key is
    Code:
    http://api.apixu.com/v1/current.json?key=302824eba4de44efa0a134505181911&q=Maintal
    while my PC Browser gives me

    Code:
    {"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
    Code:
    P/1.1 200 OK
    Cache-Controlprivate
    Content-
    Typeapplication/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: Nov 19, 2018
  2. Erel

    Erel Administrator Staff Member Licensed User

    Tested with this code on an ESP8266:
    Code:
    #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.
     
  3. Blueforcer

    Blueforcer Active Member Licensed User

    youre right.
    With this minimal example it works..
    But why not in my project?
    Still getting something like that

    Code:
    *******************************
    JobName: WeatherApp
    Response: P/
    1.1 200 OK
    Cache-Controlprivate
    Content-
    Typeapplication/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
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Hard to say. Maybe TimeNIST? Try to disable it.
     
  5. Blueforcer

    Blueforcer Active Member Licensed User

    Well...its caused by WiFiUDP AND WiFiServerSocket.
    How can i fix this? i need it..
     
    Last edited: Nov 20, 2018
  6. Erel

    Erel Administrator Staff Member Licensed User

    rHttpUtils2 collects the response until the connection breaks. Disable other tasks that can interrupt the connection.
     
  7. Blueforcer

    Blueforcer Active Member Licensed User

    Stop before the httpJob and start after response doesnt work.

    Code:
    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: Nov 20, 2018
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice