B4J Question jShell Exit code 139

Fabrice La

Active Member
Licensed User
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&param=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
Since yesterday the program crash with
sh2 True 139
from
affichelog("sh2 " & Success & " " & ExitCode )"
and
Log("Error: " & StdErr)
give nothing
 

rwblinn

Well-Known Member
Licensed User
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&param=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
JSON Responses Examples

OK
B4X:
http://192.168.NN.NNN:8080/json.htm?type=command&param=SwitchLight&idx=118&switchcmd=Off
{
   "status" : "OK",
   "title" : "SwitchLight"
}
ERROR - using the wrong IP address
B4X:
http://192.168.N.NNN:8080/json.htmtype=command&param=SwitchLight&idx=118&switchcmd=Off[/COLOR][/FONT][/LEFT]
{
   "message" : "Error sending switch command, check device/hardware !",
   "status" : "ERROR",
   "title" : "SwitchLight"
}
 
Last edited:
Top