Android Question HTTP2UTILS syntax

hakha4

Member
Licensed User
Longtime User
Hi, trying to send commands to a wifi IR-blaster (https://github.com/mdhiggins/ESP8266-HTTP-IR-Blaster) and log on B4A says that job is ok. Message is received in Arduino IDE as Connection received but there is something wrong with my code since IR-code is not sent. According to IR-blaster, command should be sent like this: http://192.168.1.10:667/msg?code=C03F7887:NEC:32&pass=alstad99. If I send this from web browser everything works fine, but not from my TESTcode :

B4X:
 Process_Globals

    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim ip_port As String
    Dim pass As String
    Dim username As String
    Dim stringtosend As String
    ip_port="http://192.168.1.10:667"
    pass= "&pass=alstad99"
    username="blaster"                        ' not sure if this is neccesary ?
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private ImageView1 As ImageView
    Private tgl_onoff As ToggleButton
    Private vol_up As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
 
  
  
    Activity.LoadLayout("ir_main")
 End Sub 

 
 Sub Send_ir(tmpcode As String)
   'Send a POST request
    Dim job1 As HttpJob
   job1.Initialize("Job1", Me)
   job1.Username=username
   job1.Password=pass
    job1.PostString(ip_port,tmpcode)
    
    Log(ip_port & tmpcode)

 
End Sub

Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
        stringtosend=""
        Job.Release
    
   Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
   End If
   End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub vol_up_Click' volume up
    stringtosend="/msg?code=C03F906F:NEC:32"
    Send_ir(stringtosend.trim)'       remove eventual spaces just in case
    
End Sub

Sub tgl_onoff_CheckedChange(Checked As Boolean)' on/off
    stringtosend="/msg?code=FFFFFFFFFFFFFFFF:NEC:0"
    Send_ir(stringtosend.Trim)


I've tryed sending string exactly as from browser, like :
job1.PostString("http://192.168.1.10:667","/msg?code=C03F906F:NEC:32&pass=alstad99)

and without password and setting password in job1.password like:
job1.PostString("http://192.168.1.10:667","/msg?code=C03F906F:NEC:32)

All with same result. What is the proper way to set credentials? Have I missed something fundamental in code ? I've tried to figure out from forum but I'm stucked. I am a newbie so any hint in right direction is appreciated
Regards
 

OliverA

Expert
Licensed User
Longtime User
You need to use Download or Download2 (GET), not PostString (POST)
 
Upvote 0
Top