The JES / JavaFX Application, Part 3.

Following on from http://jperedadnr.blogspot.com/2012/12/arduinofx-javafx-gui-for-home_17.html part, ,

 

Now, in this 3rd part, we are going to create the embedded server in the GuiPi, with the following main tasks: 

  • Back-end task: it will repeatedly read the serial port to get the measures from the MIMIC card and store them in a database.
  • Web services: it will respond to web requests returning the current values measured.
  • RESTful web services: it will respond to REST requests returning lists in json format with the data measured between two dates.

And then, in the 4th we will create the JavaFX based client application, that will mainly:

  • Connect to the server to get last measures and show them in a LED Matrix Panel control.
  • Connect to the server to get a list of measures between two dates, showing them in a chart
  • Show the status of the connection anytime.

Embedded application development is fundamentally cross-platform work. The target device on which the application will be deployed, the Raspberry Pi in this case, doesn’t have the hardware resources to support development tools such as Netbeans. Therefore, we must build on our host computer, copy the required build artefacts to the target, and debug and tune the application running on the target. 

 

We need to install Java Embedded Suite 7.0, per point 4 of
http://jperedadnr.blogspot.com.es/2012/12/arduinofx-javafx-gui-for-home.html – installation

Once we have the Soft-wheezy OS installed, the first thing to remember to do, before continuing with the JavFX stuff, is to

Turning off the UART functioning as a serial console (see http://www.raspberry-projects.com/pi/programming-in-c/uart-serial-port/using-the-uart)

(This is based on Clayton Smiths nifty guide).

Backup the /boot/cmdline.txt file before you edit it just in case of screw-ups:

sudo cp /boot/cmdline.txt /boot/cmdline_backup.txt

Edit the file:

sudo vi /boot/cmdline.txt

Running “2012-09-18-wheezy-raspbian.img” the file contained the following:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Delete and parameters involving the serial port “ttyAMA0”, which in this example is:

console=ttyAMA0,115200 kgdboc=ttyAMA0,115200

Which gives:

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Press ESC to return to the vi command mode and then type “:wq” (without the quotation marks) to save and exit (even if it appears vi is still in editing mode just type the “:wq” command).  If you need to exit without saving type “:q”.

You also need to edit this file:

 

sudo vi /etc/inittab

Search for the serial port usage by typing:

/ttyAMA0/

This should find the line of the file specifying the serial port (if there is one), move the cursor to the start of the line and press “i” to select insert and cursor and then press “#” to comment out the line.  Then press ESC and enter “:wq” to save and exit. 

Enter “sudo reboot” to restart the pi and now the UART will be available for another process to use it.

 

Running Test #3, as per
http://jperedadnr.blogspot.com.es/2012/12/arduinofx-javafx-gui-for-home.html – installation

Now, for 4. Java Embedded Suite 7.0: (There was a problem with the path. On the Pi it is: /usr/java/jes7.0/samples/run). I only ran the db sample, and it was sloooooow….

 

Let’s move on to Test #4:

Some problems here…

So I did: sudo wget http://rxtx.qbang.org/pub/rxtx/rxtx-2.2pre2-bins.zip and unzip rxtx-[].zip

Added http://debian.mirror.neology.co.za/debian/ to sources.list, and it didn’t work….no Wheezy!

Finally, by pointing the sources.list to Australia (http://how-to.linuxcareer.com/debian-apt-get-wheezy-sourceslist ), I got it going!

We also need Geany (add shortcut to desktop), to do code entry and compilation of ‘EmbSerial’: I got javac..command not found, so I installed “sudo apt-get install openjdk-6-jre openjdk-6-jdk” !!BUT WE DOWNLOADED JDK1.8.0 ON TO THE PC – WE DON’T WANT TO COMPILE ON THE RASP-PI !!!!

THIS WORKED:

Using

For the HelloService, if you’re not patient, you get…

When it’s ready, we get:

Good progress, now we’ll tackle “3. Embedded Server”

3. Embedded Server

So far, everything up to point 7 has worked OK. (I got the source from Jose’s GitHub, at https://github.com/jperedadnr/ArduinoFX-server/tree/master/src/java/com/jpl/embedded/service )

To be able to accurately debug this applications suite, I think we should make at least one of our Mimic Cards “look like” Jose Arduino Uno (so we don’t have to buy same).

Small diversion to do this…..Done!

pi@raspberrypi ~/java $ cd /usr/java/jes7.0/samples/dist/run/

pi@raspberrypi /usr/java/jes7.0/samples/dist/run $ ./gfhost.sh ../../embedded/dist/embedded.war

Apr 29, 2013 4:52:25 PM org.hibernate.validator.util.Version <clinit>

INFO: Hibernate Validator 4.2.0.Final

Deploying ../../embedded/dist/embedded.war …

ERROR: failed to deploy ../../embedded/dist/embedded.war

Stopping server com.sun.enterprise.glassfish.bootstrap.StaticGlassFishRuntime$1@870fb

 

Finally, we got Jose’s sample running perfectly (apart from the funny character before the degree-Celsisu), with a Mimic Simulator impersonating his Arduino.

Our last venture is to get this working with his JavaFX application. (Nope, because from my DynFX JavaFX app, I see we use “-cp /opt/jdk1.8.0/jre/lib/jfxrt.jar”, and I don’t have time now to sort JavaFX issues on the Soft-Wheezy…….)

Caveat: I got an error when I tried to re-run http://192.168.16.12:8080/embedded/count :

java.sql.SQLNonTransientConnectionException: No current connection.

at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)

at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)

at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)

at org.apache.derby.impl.jdbc.Util.noCurrentConnection(Unknown Source)

at org.apache.derby.impl.jdbc.EmbedStatement.checkStatus(Unknown Source)

at org.apache.derby.impl.jdbc.EmbedStatement.getConnection(Unknown Source)

at org.apache.derby.impl.jdbc.EmbedStatement.checkExecStatus(Unknown Source)

at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)

at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)

at com.jpl.embedded.service.CStore.record(CStore.java:124)

at com.jpl.embedded.service.XBee$1.run(XBee.java:77)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)

at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)

at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

at java.lang.Thread.run(Thread.java:722)

Caused by: java.sql.SQLException: No current connection.

at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)

at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)

… 19 more

BeanHT{id=1, T=12.3°C, HR=45.6 %, time=Tue Apr 30 09:02:37 SAST 2013}

Servlet XBee time access: 0 s

java.sql.SQLNonTransientConnectionException: No current connection.

at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)

at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)

at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)

at org.apache.derby.impl.jdbc.Util.noCurrentConnection(Unknown Source)

at org.apache.derby.impl.jdbc.EmbedStatement.checkStatus(Unknown Source)

at org.apache.derby.impl.jdbc.EmbedStatement.getConnection(Unknown Source)

at org.apache.derby.impl.jdbc.EmbedStatement.checkExecStatus(Unknown Source)

at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)

at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)

at com.jpl.embedded.service.CStore.record(CStore.java:124)

at com.jpl.embedded.service.XBee$1.run(XBee.java:77)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)

at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)

at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

at java.lang.Thread.run(Thread.java:722)

Caused by: java.sql.SQLException: No current connection.

at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)

at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)

… 19 more

 

The Mimic Card is currently sending data every 500 milliseconds:

 


 

 

 

In part 4, we’ll start transforming his sample to work with the actual Mimic Card Protocol.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s