B4J Question [IoT] reboot RB from an application

derez

Expert
Licensed User
How should I tell the RB to reboot from inside a sever appliction running in it ?
Or run another application (I can put the command in a script file).
 

inakigarm

Well-Known Member
Licensed User
You can use jshell to execute a command or script to reset the RB

B4X:
sudo shutdown –h  or sudo shutdown –r now
(halt or restart)

P.D: I can't test it for now...
 

derez

Expert
Licensed User
Thanks !
This works:
B4X:
Dim shl As Shell
shl.Initialize("shl", "reboot", Array As String())   
shl.Run(-1)
 

derez

Expert
Licensed User
Now I have another problem...
The GPIO library doesn't work with OrangePi but I have found these commands that when run from the terminal - turn the pin on and off:
http://www.orangepi.org/orangepibbsen/forum.php?mod=viewthread&tid=148
B4X:
echo 1 > /sys/class/gpio_sw/PA1/data
echo 0 > /sys/class/gpio_sw/PA1/data
When I perform it from an application, like this:
B4X:
shl.Initialize("shl", "echo 1 > /sys/class/gpio_sw/" & pin_name & "/data", Null)
It doesn't work.
How should I use shell in this case ?
 

Roycefer

Well-Known Member
Licensed User
Looking at those commands, all you're doing is writing the numbers 1 and 0 to the file /sys/class/gpio_sw/PA1/data. You might as well try doing that with a TextWriter or a File.WriteString() call. The single greater-than sign means you're NOT appending to the file so make sure the TextWriter doesn't, either.
 

derez

Expert
Licensed User
Thanks ! It works with File.writestring:
B4X:
public Sub WritePin(pin_name As String, pin_on As Boolean)
    If pin_on Then
        File.WriteString("/sys/class/gpio_sw/" & pin_name & "/","data","1")
    Else
        File.WriteString("/sys/class/gpio_sw/" & pin_name & "/","data","0")
    End If
End Sub
To define the function of the pin (input or output) I use
B4X:
Public Sub DefinePin(pin_name As String, Write As Boolean)
    If Write Then
        File.WriteString("/sys/class/gpio_sw/" & pin_name & "/","cfg","1")
    Else
        File.WriteString("/sys/class/gpio_sw/" & pin_name & "/","cfg","0")
    End If
End Sub
(not tested yet...)
How should I work with this command, for reading the data from a pin ?
B4X:
cat /sys/class/gpio_sw/PA1/data
Edit: I have found that cat provides data, I'll test and find the type of it, but anyway there are more required definitions (pwm, digital or analog read etc), we do need a librry here,

Can someone find the code of wiringpi library ? it might help to find the definitions.
 
Last edited:
Top