B4J Question HTTPjob to Shelly error

schoors luc

New Member
Licensed User
hello ,

i am trying to do a httpjob to a shelly 1 plus but it gives an error on the wjob.download.

Dim wjob As HttpJob
wjob.Initialize("",Me)



wjob.Download("http://192.168.2.60/rpc/Input.SetConfig?id=0&config={"name":"Input0"}) ' this line gives an error

Wait For (wjob) JobDone(wjob As HttpJob)
If wjob.Success Then
Dim JSON As JSONParser
Dim Map1 As Map
JSON.Initialize(wjob.GetString) 'Read the text from a file.
Map1 = JSON.NextObject

For i = 0 To Map1.Size - 1
'Log("Key: " & Map1.GetKeyAt(i))
Log("Value: " & Map1.GetValueAt(i))
Next

End If



can anyone give me a solution .
thank you in advance
 

Attachments

B4X: Copy
wjob.Download("http://192.168.2.60/rpc/Input.SetConfig?id=0&config={"name":"Input0"})     '    this line gives an error
This line you have a Syntax error, the string includes quotes, you have to use smart string or escape them using chr(34)
It should be like this.
B4X: Copy
wjob.Download($"http://192.168.2.60/rpc/Input.SetConfig?id=0&config={"name":"Input0"}"$)
 
Last edited:
Upvote 0
see:
Not tested
B4X: Copy
Public Sub TESTGetURLWithParmeters
    Dim Link As String = "http://192.168.2.60/rpc/Input.SetConfig"
    Dim Parameters() As String = Array As String ("id", 0, "config", $"{"name":"Input0"}"$)
    Wait For (GetURLWithParmeters(Link, Parameters)) Complete (DataResult As String)
    Log(DataResult)
   
    Dim Link As String = "http://192.168.2.60/rpc/Switch.Set"
    Dim Parameters() As String = Array As String ("id", 0, "on", "false")
    Wait For (GetURLWithParmeters(Link, Parameters)) Complete (DataResult As String)
    Log(DataResult)
   
    Dim Link As String = "http://192.168.2.60/relay/0"
    Dim Parameters() As String = Array As String ("turn", "toggle")
    Wait For (GetURLWithParmeters(Link, Parameters)) Complete (DataResult As String)
    Log(DataResult)
   
End Sub

'Get With parameter
Public Sub GetURLWithParmeters(Link As String, Parameters() As String) As ResumableSub
    Dim Result As String
    Dim j As HttpJob
    Try
        j.Initialize("", Me)
        j.Download2(Link, Parameters)
        j.GetRequest.SetHeader("Content-Type","application/json")
        j.GetRequest.Timeout = 60000
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Result = j.GetString
        End If
    Catch
        Log(LastException)
    End Try
    j.Release
    Return Result
End Sub
 
Upvote 0
option parametro json

B4X: Copy
    Dim Link As String = "http://192.168.2.60/rpc/Input.SetConfig"
    Dim m As Map = CreateMap("name": "Input0")
    
    Dim Parameters() As String = Array As String ("id", 0, "config", m.As(JSON).ToString)
    Wait For (GetURLWithParmeters(Link, Parameters)) Complete (DataResult As String)
    Log(DataResult)
 
Upvote 0
Upvote 0
Back
Top