### System Check

Example of performing remotely some Raspberry Pi system checks from a Windows device using B4J.
The output can be used to trigger any actions or display the information.
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
• Bash script on the Raspberry Pi which is executed by the SSH.execCommand
Bash Script on the Raspberry Pi
Create a bash script rpisyscheck.sh with content below in folder /home/pi/.
Use nano to create: sudo nano rpisyscheck.sh.
Make the script executable: sudo chmod 755 rpisyscheck.sh and check running ./rpisyscheck.sh.
/bin/bash
Get CPU Temperature - divide by 1000 in the B4J application
cat /sys/class/thermal/thermal_zone0/temp
Get Disc space used
df -H | grep 'root' | awk '{ print $5 }'
Get RAM used
free -o -h | head -n2 | tail -n1 | awk '{print $3}' | tr -d [=M=]
Get RAM free
free -o -h | head -n2 | tail -n1 | awk '{print $4}' | tr -d [=M=]
B4J Code
`Sub Class_Globals
Private btnSysCheck 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 syscheckexec as String = "/home/pi/rpisyscheck.sh"
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
SHH command executed result
`Sub SSH_CmdExecuted (Success As Boolean, Result As List, TaskId As Int)
Log($"SSH_CmdExecuted. Result entries ${Result.Size}"$)
For Each s As String In Result
Log(s)
Next
End Sub`
Button System Check
`Sub btnSysCheck_Action
Log("Control Unit System Check initiated.")
Try
SSH.execCommand(syscheckexec, port)
Catch
Log($"Control Unit System Check Error:${LastException.Message}"$)
End Try
End Sub`
Example Output
SSH Connection has been established at 09:48:53
SSH_CmdExecuted. Result entries 4
36318
18%
277
157

Changed: , Category: Raspberry Pi Remote Control, File: T6C237M1733.htm, ID: 1733