iOS Question httpJob

alizeti

Member
Licensed User
This code is not working unless I put a break point.
Any idea?

B4X:
Dim job As HttpJob
   job.Initialize("", Me)
  
   'check result
   currentState = MANUAL_MODE
   If state == 1 Then
       'not activate, so need to activate
       job.PostString("https://api.particle.io/v1/devices/" & deviceName & "/zoneCtrlId", "access_token=" & accessToken & "&params=" & controlPin & "," & ON)
       manControlFlag = True
   Else If state == 0 Then
       'not activate, so need to activate
       job.PostString("https://api.particle.io/v1/devices/" & deviceName & "/zoneCtrlId", "access_token=" & accessToken & "&params=" & controlPin & "," & OFF)
       manControlFlag = False
   End If
  
  
   Wait For (job) JobDone(job As HttpJob)
   If job.Success = True Then
       Log(job.GetString)
       cloudRx = job.GetString
       updateState
       Log("result from Post is : " & result)
   Else
       Log("job failed")
   End If
  
   job.Release
End Sub
 

OliverA

Expert
Licensed User
Longtime User
Are you sure state (the variable) is always a 1 or 0? If it is not, then you hit the Wait For without having started a job, at which point the Wait For will wait forever.
 
Upvote 0

alizeti

Member
Licensed User
B4X:
'global
 Dim job As HttpJob
 jobPost.Initialize("jobPost", Me)

Private Sub manualControl (zone As String, controlPin As String, state As Int)
  
 
   'check result
   currentState = MANUAL_MODE
   If state == 1 Then
       'not activate, so need to activate
       jobPost.PostString("https://api.particle.io/v1/devices/" & deviceName & "/zoneCtrlId", "access_token=" & accessToken & "&params=" & controlPin & "," & ON)
       manControlFlag = True
   Else If state == 0 Then
       'not activate, so need to activate
       jobPost.PostString("https://api.particle.io/v1/devices/" & deviceName & "/zoneCtrlId", "access_token=" & accessToken & "&params=" & controlPin & "," & OFF)
       manControlFlag = False
   End If

End Sub

Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    
    If Job.Success = True Then
        Select Job.JobName
            Case "jobGet"
                Log(Job.GetString)
                cloudRx = Job.GetString
            Case "jobPost"
                Log(Job.GetString)
                cloudRx = Job.GetString
                'could check for error code to see if command was successfull
        End Select
        
        updateState
    Else
        Log("Error: " & Job.ErrorMessage)
        'mess'messagePToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub
Which version of B4i are you using?

Hard to say much without running the code.

If I used the jobDone as as Sub function for both global httpJob object, it works perfectly. But if I try the way you guys suggest, it does not.
That what I found weird.
 
Upvote 0

alizeti

Member
Licensed User
I just noticed that the job.download() works find, but the job.postString() is not working properly.

All the examples with the jobDOne routine inside the sub is always with the job.download() and never with the job.postString().

Is it possible that the job.download() waits for a response and not job.postString()?
 
Upvote 0
Top