1

I have an RPi which I want to use to interface to a number of different devices via I/O and/or COM. A PC will communicate with it via ethernet and a REST API. The app should be able to start up automatically at power-on and close down gracefully/safely when the power is removed.

If the project is successful I will need to deliver around 50 systems. Maintenance (updates, security patches etc) will be a concern.

I have many years experience with Java in a Windows environment and I have done a little work with Python. Java would therefore be my preference. However, I assume that Python support is built-in and that I would have to install and maintain a Java VM.

As I will need to access the GPIO digital and serial signals, I think that I will need to develop directly on the RPi.

I should also say that I have had little experience with Linux up to now.

What alternatives are there in 2020? In an older post from 2012, Ruby was the recommendation but I wonder if that is still current.

2

Ah, the language wars. Language recommendations are often almost religious.

Personally, I like Raisin, but I'm more comfortable with Perl. Flask is an option if you want to use Python. Whether Java is an option depends a bit on the size of your project; things like Pi4j allow you to access the GPIO port etc.

Some remarks though.

If you power-down a Pi, it usually does not have the time to gracefully shutdown. So, you either need some battery backup and do a graceful shut-down yourself, or you need to be sure that your application remains consistent at any time when it is powered down.

Python support is not build-in. Python is a separate installable package. Granted, all distributions install it, but it has its own update cycle.

So the recommendation:

  • Large project, lots of security concerns, etc: Java with Tomcat
  • Smaller projects: Python; look at Flask

And spend some time getting to know Linux.

| improve this answer | |
  • yes, Linux is going to be a challenge. My application shouldn't have a problem if the power is removed. How does Linux cope with that? – paul Oct 13 at 9:36
  • 1
    like Windows, if you don't shutdown properly, most of the times it is alright. using a journaled filesystem (standard nowadays) helps of course. If you're really worried, or have high demands for consistency, consider mounting important partitions as read-only. – Ljm Dullaart Oct 13 at 10:48
1

As you are an experienced Java developer, there is no doubt: JAVA: ;-)

You could use Spring with Pi4J but Spring Boot is a bit heavy for the Raspberry Pi.

Undertow is another option as shown in this example application: "JavaFX LED controller application".

If you start with the full Raspberry Pi OS with Imager you will have OpenJDK 11 pre-installed, so you can get started immediately!

For more info and ideas I can recommend you this article on Oracle Java Magazine: "Getting started with JavaFX on Raspberry Pi " and a very good book: "Getting Started with Java on Raspberry Pi" --> sidenote: I wrote these myself ;-)

| improve this answer | |
  • Also, consider using USB Boot instead of SD card as that will assure you won't run into non-safe-unpower-sd-corruptions, see foojay.io/blog/… – Frank Oct 14 at 13:17
1

I can't say which is best: I have only used Python. That includes using Python with Flask to present a REST API.

I have it setup to start at boot, but have not addressed the issue that you want it to close down gracefully when power is removed (in fact without precautions you cannot just remove power from a Raspberry Pi). To power down gracefully I can think of two options:

  1. Detect the removal of power and initiate a proper shutdown while retaining sufficient backup power to permit that to complete.
  2. Run the SD card in read-only mode (I'm sure I saw that somewhere in a MagPi magazine) so that it cannot be corrupted. I have never tried that so there are probably some precautions around programming that lead from that.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.