### Run B4J Applications

Running B4J on the TinkerForge RED-Brick.
Install the B4J Bridge
Create folder /home/pi/b4j ($mkdir b4j) from the /home/pi folder
Change to the folder /home/pi/b4j ($cd b4j)
Run $wget http://www.b4x.com/b4j/files/b4j-bridge.jar
Run the B4J Bridge
Important: Ensure to run the B4J Bridge as sudo.
$sudo java -jar b4j-bridge.jar
Install and Run a B4J Application on the RED Brick
This example B4J Application obtains Yahoo Weather data for a given id and write the result to the standard output.
It is called yahoow.jar, Main Class is b4j.example.main.
The app runs every 60secs and writes its output to the continous_log file.
The argument given is 656958 , which is the town Hamburg Germany
The folder for this program is /home/tf/programs/Yahoo_Weather/bin/yahoow.jar.
Configuration File
executable = /usr/bin/java
arguments.length = 4
environment.length = 2
working_directory = .
stdin_redirection = pipe
stdin_file_name =
stdout_redirection = continuous_log
stdout_file_name =
stderr_redirection = stdout
stderr_file_name =
start_mode = interval
continue_after_error = false
start_interval = 60
start_fields =
arguments.item0 = -cp
arguments.item1 = /home/tf/programs/Yahoo_Weather/bin/yahoow.jar:/usr/tinkerforge/bindings/java/Tinkerforge.jar
arguments.item2 = b4j.example.main
arguments.item3 = 656958
environment.item0 = PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
environment.item1 = LANG=en_US.UTF-8
custom.name = Yahoo Weather
custom.language = java
custom.description =
custom.first_upload = 1420366603
custom.last_edit = 1420366603
custom.java.jar_file = yahoow.jar
custom.java.class_path.item0 = yahoow.jar
custom.java.class_path.item1 = /usr/tinkerforge/bindings/java/Tinkerforge.jar
custom.java.class_path.length = 2
custom.java.main_class = b4j.example.main
custom.java.options.length = 0
custom.java.start_mode = main_class
custom.editable_arguments_offset = 3
custom.editable_environment_offset = 0
Install and Run a B4J Webserver on the Red Brick (1)
This B4J Webserver App is accessed via the webbrowser by ipaddress:port.
It is called wstest.jar, Main Class is b4j.example.main.
It shows a JQuery Mobile page with several buttons. Button outputs are written to the log file.
Steps
• Create a folder on the Red Brick /home/tf/rob/programs/wstest
• Copy from development PC the files wstest.jar and the www folder to the new folder
• Start the TF Brick Viewer (brickv)
• Add new program under tab SetUp > Programs. Type Java, Main Class is b4j.example.main, Add Directory /home/tf/rob/programs/wstest
• After installation, the program is listed and can be accessed by ipaddress:port, like 192.168.0.24;51043.
• To stop the program, select the program and press Kill.
• To look at the details, start the Reb brick Webinterface ipaddress, like 192.168.0.24. The added app is listed.
Configuration File
The B4J Webserver Application is called wstest.jar, Main Class is b4j.example.main.
This app runs continously.
executable = /usr/bin/java
arguments.length = 3
environment.length = 2
working_directory = .
stdin_redirection = pipe
stdin_file_name =
stdout_redirection = continuous_log
stdout_file_name =
stderr_redirection = stdout
stderr_file_name =
start_mode = always
continue_after_error = false
start_interval = 60
start_fields =
arguments.item0 = -cp
arguments.item1 = /home/tf/programs/wstest/bin/wstest.jar:/usr/tinkerforge/bindings/java/Tinkerforge.jar
arguments.item2 = b4j.example.main
environment.item0 = PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
environment.item1 = LANG=en_US.UTF-8
custom.name = wstest
custom.language = java
custom.description =
custom.first_upload = 1420368054
custom.last_edit = 1420368054
custom.java.jar_file = wstest.jar
custom.java.class_path.item0 = wstest.jar
custom.java.class_path.item1 = /usr/tinkerforge/bindings/java/Tinkerforge.jar
custom.java.class_path.length = 2
custom.java.main_class = b4j.example.main
custom.java.options.length = 0
custom.java.start_mode = main_class
custom.editable_arguments_offset = 3
custom.editable_environment_offset = 0
Install and Run a B4J Webserver on the Red Brick (2)
This B4J Webserver App is accessed via the webbrowser by ipaddress:port.
It is called webtemp.jar, Main Class is rwblinn.webtemp.main.
It shows a temperature line chart obtained from a TF Temperature Bricklet using Google Charts, jQuery Mobile.
Steps
• Create a folder on the Red Brick /home/tf/rob/programs/webtemp
• Copy from development PC the files webtemp.jar, settings.txt and the www folder to the new folder
• Start the TF Brick Viewer (brickv)
• Add new program under tab SetUp > Programs. Type Java, Main Class is b4j.example.main, Add Directory /home/tf/rob/programs/wstest
• After installation, the program is listed and can be accessed by ipaddress:port, like 192.168.0.24;51043.
• To stop the program, select the program and press Kill.
• To look at the details, start the Reb brick Webinterface ipaddress, like 192.168.0.24. The added app is listed.
Configuration File
executable = /usr/bin/java
arguments.length = 3
environment.length = 2
working_directory = .
stdin_redirection = pipe
stdin_file_name =
stdout_redirection = continuous_log
stdout_file_name =
stderr_redirection = stdout
stderr_file_name =
start_mode = always
continue_after_error = false
start_interval = 60
start_fields =
arguments.item0 = -cp
arguments.item1 = /home/tf/programs/WebTemp/bin/webtemp.jar:/usr/tinkerforge/bindings/java/Tinkerforge.jar
arguments.item2 = rwblinn.webtemp.main
environment.item0 = PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
environment.item1 = LANG=en_US.UTF-8
custom.name = WebTemp
custom.language = java
custom.description = WebTemp is a B4J Server app to display temperature measured using the Temperature Bricklet. Port used is 51043.
custom.first_upload = 1420988682
custom.last_edit = 1420988682
custom.java.jar_file = webtemp.jar
custom.java.class_path.item0 = webtemp.jar
custom.java.class_path.item1 = /usr/tinkerforge/bindings/java/Tinkerforge.jar
custom.java.class_path.length = 2
custom.java.main_class = rwblinn.webtemp.main
custom.java.options.length = 0
custom.java.start_mode = main_class
custom.editable_arguments_offset = 3
custom.editable_environment_offset = 0

Changed: , Category: TinkerForge RED Brick, File: T6C268M1999.htm, ID: 1999