iOS Question httpJob with event handling using Particle Photon

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.
 

Erel

B4X founder
Staff member
Licensed User
Longtime 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:
B4X:
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:
Upvote 0

alizeti

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:
B4X:
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?


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"}
 
Upvote 0

alizeti

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.

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
 
Upvote 0
Top