Hi,
I was using jShell library on raspberry more then a year :
B4X:
Dim sh2 As Shell
sh2.Initialize("sh2", "curl", _
Array As String("http://192.168.52.139:8080/json.htm?type=command¶m=switchlight&idx=2&switchcmd=" & HPOn))
sh2.WorkingDirectory = "/home/pi/B4J"
sh2.Run(2000)
Wait For (sh2) ProcessCompleted(Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
affichelog("sh2 " & Success & " " & ExitCode )
If Success And ExitCode = 0 Then
Log("Success")
Log(StdOut)
Else
Log("Error: " & StdErr)
End If
Looks like a Domoticz Home Automation switch device is turned On | Off.
Please find an example using the jOkHttpUtils2 and Json library.
Tested on a Raspberry Pi 3B+ (with Domoticz v4.x) using the B4J Bridge.
B4X:
Private Const DOMOTICZURL As String = "http://192.168.NN.NNN:8080/json.htm?type=command¶m=switchlight&"
End Sub
Sub AppStart (Form1 As Form, Args() As String)
…
SwitchLight(118, "Off")
' SwitchLight(118, "On")
...
End Sub
'Switch a Domoticz device light On or Off
'Depends on the libraries jOkHttpUtils2 and Json
'idx - Domoticz device idx
'cmd - Switch command On | Off !Case sensitive
Sub SwitchLight(idx As Int, cmd As String)
Dim j As HttpJob
Log($"SwitchLight: ${DOMOTICZURL}${cmd}"$)
j.Initialize("", Me)
j.Download($"${DOMOTICZURL}idx=${idx}&switchcmd=${cmd}"$)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim parser As JSONParser
parser.Initialize(j.GetString)
Dim root As Map = parser.NextObject
Dim status As String = root.Get("status")
' Dim title As String = root.Get("title")
Log($"Result: ${status}"$)
End If
j.Release
Log($"Done"$)
End Sub