steffo
Posts: 25
Joined: Sat Jan 18, 2014 12:43 pm

Basic Java question from beginner

Fri Jun 19, 2015 12:49 pm

Hello all,
I have managed to create a java application to control the heat in a mash tun with Pi4J and java, I am using eclipse on my windows laptop to write the code and exporting executable JAR's to the Raspberry.

Now I can hardcode (or read from file) the tempertures to regulate upon but I would really like to learn how to have a web page to my raspberry where I change paremters on my JAR application.
Like if I have 70 degrees in the heater and I like to raise it to 75, Now i restart the program with new command line attributes but there must be a easy way to do this via WEB gui!

Thanks very much if you can hint me a direction :)

User avatar
xranby
Posts: 540
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: Basic Java question from beginner

Tue Jun 23, 2015 2:36 pm

steffo wrote:Now I can hardcode (or read from file) the tempertures to regulate upon but I would really like to learn how to have a web page to my raspberry where I change paremters on my JAR application.
Like if I have 70 degrees in the heater and I like to raise it to 75, Now i restart the program with new command line attributes but there must be a easy way to do this via WEB gui!
There is several ways that you can create a WEB gui, i will list some options:

A) webapplication using java EE server with GUI using jetty or tomcat
use one of the jetty or tomcat examples as a gui

Code: Select all

sudo apt-get install jetty
http://www.eclipse.org/jetty/documentation/current/
http://www.eclipse.org/jetty/documentat ... mples.html

Code: Select all

sudo apt-get install tomcat7
http://www.ntu.edu.sg/home/ehchua/progr ... mples.html



B) minimal webapplication using rupy
to test the rupy code you need to install ant
sudo apt-get install ant
https://github.com/tinspin/rupy
example: https://github.com/tinspin/rupy/wiki/Tutorial#remote
example code: https://github.com/xranby/rupy-test



C) display a html5 GUI using swing + caciocavallo-web
write your GUI as a regular desktop swing GUI then when you want to deploy it as a WEB gui you use "cacio-web" to expose the server side gui to the web.
"cacio-web" is only available from source
it is easy to compile and setup if you first install mercurial and maven

Code: Select all

sudo apt-get install mercurial maven
then follow the guide at
https://rkennke.wordpress.com/2012/12/1 ... web-howto/



D) launch a CGI script using perl or php using the apache webserver that executes the commands to restart your java application.
instructions to setup apache and php: https://www.raspberrypi.org/documentati ... /apache.md
instructions how to write CGI using perl: http://httpd.apache.org/docs/2.2/howto/cgi.html


E) create a java application that opens a server socket and listen to bytes sent from a client
https://docs.oracle.com/javase/tutorial/networking/
After your server socket is working you may write the client GUI using any language.



Good luck!
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

User avatar
xranby
Posts: 540
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: Basic Java question from beginner

Wed Jun 24, 2015 11:04 am

I think you should split your application into two parts:
one server part that receives the temperature in degrees and updates the heater, you can extend the java code you already have to become a server by writing the minimal amount of code to let the server listen to an incomming socket.

you then put the most effort in creating a nice GUI into the client part that can be an android/ios application, a html5 application, a java applet or some other type of native application. choose the option how you write the client application that will work best with the device you want to run the client on.

today it is possible to create a html5 client GUI application using javascript that will run on most mobile phones and desktop systems.
html5 allows you to create a websocket to your server in order to transmit the selected temperature.
http://www.html5rocks.com/en/tutorials/ ... ts/basics/
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

richrarobi
Posts: 271
Joined: Sun Feb 08, 2015 1:13 pm

Re: Basic Java question from beginner

Wed Jun 24, 2015 10:12 pm

I think you should split your application into two parts:
one server part that receives the temperature in degrees and updates the heater, you can extend the java code you already have to become a server by writing the minimal amount of code to let the server listen to an incomming socket.
Another variation on that theme could be to use messages e.g. rabbitmq instead of sockets.http://www.rabbitmq.com/

RichR

Return to “Java”