B4J Question Shutdown RPi via Bluetooth

Mark Read

Well-Known Member
Licensed User
Longtime User
I am using a tablet running a B4A app connecting via Bluetooth to an Raspberry Pi running a B4J app headless.

My question, how can I send a command to the Pi to shutdown the Pi?

Many thanks.
 

jayel

Active Member
Licensed User
Longtime User
Hello,

Did you manage to execute the shutdown command?
If Yes, how did you do it?

Greets
John
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Did you manage to execute the shutdown command?

Sorry, got waylaid with other parts of my app and had no time to try a solution. Shouldn't be too difficult to send "shutdown now" via jShell.
 
Upvote 0

jayel

Active Member
Licensed User
Longtime User
OK I made a sh script on my raspberry

B4X:
#!/bin/sh

sudo shutdown -h now
I execute my script like this on B4J program :

B4X:
Sub Shutdown
    Dim myshell As Shell
    myshell.Initialize("shl","shutdown.sh",Null)
    myshell.WorkingDirectory = "/home/pi/telmachine/"
    myshell.Run(10000)
   
   
End Sub

When I try to execute I get this error


Error: org.apache.commons.exec.ExecuteException: Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program "shutdown.sh" (in directory "/home/pi/telmachine"): error=2, Bestand of map bestaat niet)
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
just a thought. Not able to try it.

B4X:
Sub Shutdown
    Dim myshell As Shell
    myshell.Initialize("myshell","shutdown.sh",Null)
    myshell.WorkingDirectory = "/home/pi/telmachine/"
    myshell.Run(-1)
  
  
End Sub
 
Upvote 0

jayel

Active Member
Licensed User
Longtime User
B4X:
Sub Shutdown
    Dim myshell As Shell
    myshell.Initialize("shl","sh",Array as string("shutdown.sh"))
    myshell.WorkingDirectory = "/home/pi/telmachine/"
    myshell.Run(10000)
  
  
End Sub

That was the solution !
 
Upvote 0
Top