### Shutdown

Example of shutting down a Raspberry Pi remote from a Windows device using B4J.
Requires
• Library: jkSSH2 (see https://www.b4x.com/android/forum/threads/libary-jkssh2-ssh2-communication-in-b4a.20048/#post-307308) for the remote connection.
• Raspberry Pi: host ip address, port, username and password. Example: 192.168.0.79, 22, pi, raspberry
B4J Code
`Sub Class_Globals
Private btnShutdown As Button
' Remote Connection jkSSH2 library
Private SSH As jkSSH2
'
Private hostname as String = "192.168.0.79"
Private port as Int = 22
Private username as String = "pi"
Private password as String = "raspberry"
Private shutdownexec as String = "sudo shutdown -h"
End Sub`
SHH connection with the raspberry pi
Try
Log($"Initialize the SSH Connection with Host ${hostname} and Port ${port}"$)
SSH.Initialize("SSH", hostname, port)
SSH.authenticateWithPassword(username, password)
'Set debugoutput to false as debugging not supported by B4J. Debugging is by default using android/utils.
SSH.DebugOutput = False
Log($"SSH Connection has been established at ${DateTime.time(DateTime.now)}"$)
Catch
Log($"SSH connection Error:${LastException.Message}"$)
End Try
Button shutdown
`Sub btnShutdown_Action
Log("Control Unit Shutdown initiated.")
Try
SSH.execCommand(shutdownexec, port)
Catch
Log($"Control Unit Shutdown Error:${LastException.Message}"$)
End Try
End Sub`

Changed: , Category: Raspberry Pi Remote Control, File: T6C237M1731.htm, ID: 1731