iOS Question httpJob with event handling using Particle Photon

Discussion in 'iOS Questions' started by alizeti, Jun 13, 2018.

  1. alizeti

    alizeti Member Licensed User

    On windows terminal using curl, this is my steps :

    step 1 : start the event listening
    command :
    curl "https://api.particle.io/v1/devices/dasilvaCore/events?access_token=access_token"
    Response :
    :eek:k

    Step 2 : generate the event on the cloud through the particle module

    Step 3 : Receive the event on windows terminal after 10 sec (for test purpose)
    Response:
    event: manCtrlTimer
    data: {"data":"Valve close","ttl":60,"published_at":"2018-06-08T14:14:46.017Z","coreid":"device_id"}


    On the App, if I do the same steps, I get nothing.
    jobDone is not triggered.
    I just replace all the global jobDone function with local to to Subs and still nothing.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Posting hundreds of lines of code will not help.

    Where is the documentation of this web service API?

    Create a new project with this code:
    Code:
    Private Sub Application_Start (Nav As NavigationController)
       NavControl = Nav
       Page1.Initialize(
    "Page1")
       Page1.Title = 
    "Page 1"
       Page1.RootPanel.Color = 
    Colors.White
       NavControl.ShowPage(Page1)
       
    Dim j As HttpJob
       j.Initialize(
    "", Me)
       j.Download(
    "https://api.particle.io/v1/devices/dasilvaCore/events?access_token=access_token")
       
    Wait For (j) JobDone (j As HttpJob)
       
    Log(j.Success)
       
    Log(j.ErrorMessage)
       
    If j.Success Then
           
    Log(j.GetString)
       
    End If
       j.Release
    End Sub
    What happens?
     
    Last edited: Jun 14, 2018
  3. alizeti

    alizeti Member Licensed User


    This is the link for the documentation
    https://docs.particle.io/reference/api/#events

    I did the new project. Nothing happens. The app start, but no log appears like if it never quit the "Wait For"

    At the same time, i open an cmd line terminal on windows and this is the output :

    >curl https://api.particle.io/v1/devices/dasilvaPhoton/events?access_token=acces_token
    :eek:k



    event: manCtrlTimer
    data: {"data":"Zone 8 is now CLOSE","ttl":60,"published_at":"2018-06-14T12:25:37.693Z","coreid":"dasilvaPhoton"}


    event: manCtrlTimer
    data: {"data":"Zone 8 is now CLOSE","ttl":60,"published_at":"2018-06-14T12:25:56.710Z","coreid":"dasilvaPhoton"}
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    As @OliverA wrote in the other thread the internal HTTP framework doesn't support server events. iOS doesn't support it natively.

    Check whether they provide a different method. Maybe websockets.
     
  5. alizeti

    alizeti Member Licensed User

    like @OliverA said :
    If you look at the API docs of particle.io for events (https://docs.particle.io/reference/api/#events) you'll see the mentioning of streams. All this supports my "guess" that particle.io is using Server Side Events (SSEs) for publishing events and that HttpJob is currently not the right tool to deal with SSEs. A possible solution may be an implementation of this library (https://github.com/launchdarkly/ios-eventsource) for B4i. Please note that library was just a quick search (two others had no activity in awhile: https://github.com/neilco/EventSource and https://github.com/travisjeffery/TRVSEventSource).

    What do you think
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    You can post it in the wishlist forum. There is good support for other long lasting connections (MQTT and WebSockets). I'm not sure that it will be added.
     
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