'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
Sub Process_Globals
Private SSH As jkSSH2
Private hostname As String = "IPADDRESS"
Private port As Int = 22
Private username As String = "pi"
Private password As String = "**********"
Private command As String = "cat /sys/class/thermal/thermal_zone0/temp"
Private temp As Double
End Sub
Sub AppStart (Args() As String)
If SSH_Connect Then
SSH_RunCmd(command)
End If
StartMessageLoop
End Sub
Sub SSH_Connect As Boolean
Dim Result As Boolean
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 at ${DateTime.time(DateTime.now)}"$)
Result = True
Catch
Log($"SSH Connection Error:${LastException.Message}"$)
Result = False
End Try
Return Result
End Sub
Sub SSH_RunCmd(cmd As String)
Try
SSH.execCommand(cmd, port)
Catch
Log($"Error:${LastException.Message}"$)
End Try
End Sub
Sub SSH_CmdExecuted (Success As Boolean, Result As List, TaskId As Int)
' Log($"SSH Command Executed. Result entries ${Result.Size}"$)
If Result.Size = 1 Then
temp = NumberFormat(Result.Get(0) * 0.001, 0,2)
Log($"Raspberry Pi CPU Temperature: ${temp}°C"$)
End If
End Sub