iOS Question httpJob

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

  1. alizeti

    alizeti Member Licensed User

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

    Code:
    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Please reproduce it in a small project and upload the project.
     
  3. OliverA

    OliverA Well-Known Member Licensed 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.
     
    Erel likes this.
  4. alizeti

    alizeti Member Licensed User

    I would like to do it, but I can't. There is some information that I can't share since it's some keys for cloud processing.
     
  5. alizeti

    alizeti Member Licensed User

    Yes, since, the minute I put I break point, it works
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Which version of B4i are you using?

    Hard to say much without running the code.
     
  7. alizeti

    alizeti Member Licensed User

    Version 5
     
  8. alizeti

    alizeti Member Licensed User

    Code:
    '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
    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.
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    HttpJob should never be a global variable. Always create a new HttpJob inside the sub.
     
  10. alizeti

    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()?
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    No. Maybe the server you are communicating with never returns a response and keeps the connection open.
     
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