Arduino: Command line requires X11

Created on 1 Apr 2014  ·  45Comments  ·  Source: arduino/Arduino

I'd like to use the CLI in Arduino 1.5 on a headless Raspberry Pi (accessed through SSH only, no X11 environment), to make a continuous integration platform.

When calling arduino in the command line, Java complains that the X11 environment is not set and is required (which should not be necessary for CLI programs).

CLI output:

$ arduino --verify foo.ino
Exception in thread "main" java.lang.ExceptionInInitializerError
    at processing.app.Base.main(Base.java:113)
Caused by: java.awt.HeadlessException: 
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
    at sun.awt.HeadlessToolkit.getMenuShortcutKeyMask(HeadlessToolkit.java:231)
    at processing.core.PApplet.<clinit>(Unknown Source)
    ... 1 more
zsh: exit 1     arduino --verify foo.ino
CLI IDE Bug

Most helpful comment

If you're closing this, please BLATANTLY document that the "CLI" mode for the arduino editor + macro button isn't actually a CLI mode.

I just wasted a bunch of time and installed 220 MB worth of cruft only to discover that the CLI mode is completely broken and is in fact just a GUI mode without some draw calls.

The fact that you need a functional X11 install should be in bold text at the top of the official docs pages that refer to it, such as http://playground.arduino.cc/Learning/CommandLine

All 45 comments

This seems related to #1970, but it's probably a separate problem. I'll put this on my list to investigate, thanks for reporting.

@matthijskooijman

Thinking about this a bit more, I think this will not be easy to fix. Right now, when running the CLI commands, all of the normal initialization happens normally,except for creating and showing the window. To fix this, we'd need to refactor the GUI code to be less coupled with the compilation functionality, which won't be very easy. We should do this eventually anyway, but this will probably require a significant effort.

I'd like to comment that I have the same issue, and would love to be able to run the compile and upload commands via SSH (without X11).

Hi matthijskoijman same issue on a Debian Virtual Machine without GUI, I have try using arduino-mk, but doesn't work anyway...

Same issue with 1.5.8 on Debian Wheezy (Raspbian) running in a Raspberry Pi.

Same issue - trying to do Continuous Integration on a Jenkins OS X node to verify Arduino files, but it needs to be headless. I've tried ino but it seems quite outdated. Is there any other workaround in the meanwhile? I've heard of bii hive, I'll give it a try too, but any other recommendations welcome.

Cheers,
Raquel

We use jenkins all the time. To workaround the needs of the IDE, we have installed https://wiki.jenkins-ci.org/display/JENKINS/Xvnc+Plugin

Thanks so much @ffissore, I'll give it a try.

Sorry if this is getting a bit off-topic. @ffissore, In which platform are your running that plugin? I'm trying to test Arduino verification on a Jenkins Mac node and after much configuring and working around, I've got stuck.

On mac we don't use that plugin because the node is launched via java web start. This allows the java process on mac node to access the display. Indeed, every once in a while, the IDE pops up and executes its functional tests

I'm not sure I understand. Does that mean it's impossible to test this on a Mac node? :(

Quite the contrary. We do it all the time. But you need to start the mac node properly. I don't remember which tutorial I used to set it up, but the result is that our mac main user has a startup "start jenkins" app that connects to master using java web start

Oh, I see. I'll google it! Thanks a lot!

Closing as wontfix. Fixing would require dismantling the IDE. We make small steps everyday, but can't really set a schedule

If you're closing this, please BLATANTLY document that the "CLI" mode for the arduino editor + macro button isn't actually a CLI mode.

I just wasted a bunch of time and installed 220 MB worth of cruft only to discover that the CLI mode is completely broken and is in fact just a GUI mode without some draw calls.

The fact that you need a functional X11 install should be in bold text at the top of the official docs pages that refer to it, such as http://playground.arduino.cc/Learning/CommandLine

Try PlaformIO, it works perfectly for me.

@wollew - That's where I wound up, after going through 3 or 4 other options.

Note that this is actually documented at https://github.com/arduino/Arduino/blob/ide-1.5.x/build/shared/manpage.adoc#bugs, which is the primary documentation for commandline mode as linked from the page you referenced.

@agdl, could you perhaps update the link at http://playground.arduino.cc/Learning/CommandLine to point it to https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc since the current link might end up breaking in the future.

I'm reopening this issue, since I believe this issue should be fixed at some point. It does require significant refactoring of the code, so this will not be something that will be fixed soon, but "wontfix" seems to harsh a resolution.

@matthijskooijman sorry but just noticed the tag to me.... link updated sorry again

Doing this with vi is definitely asking for trouble. Doing it with eclipse is mostly about having the will to start and 1/2 day to take it to the end. The ide is not very big. It is a bit disorganized, but there is no reflection or any invisible dependencies anywhere. Even if it takes you a day if focus, it is still just a single day for a product that has been around for years...
The only pb with doing it is that it means taking responsibility for the whole thing, which looking at how some of the code was altered over the years, seems to have been something some wanted to avoid (I assume out of the desire to be able to pull-in easily any fixes/improvements from processing). But the reality is that the code lost compatibility a while ago... unfortunately without taking advantage so far of the resulting freedom (i mean on the core).
Someone ought to give it a shot, it is IMHO truly not as complicated as it looks.

If it helps, I've put a workaround here: http://playground.arduino.cc/Main/Headless (from developers mail list, thanks to Matthew Beckler)

Ugh, how is this still an issue? Workaround above still assumes java display. export JAVA_TOOL_OPTIONS='-Djava.awt.headless=true' doesn't help, even with #5132 as you still get an error on the splash screen. Is there no way to compile and upload a sketch on a headless display?

Still not fixed... unfortunatelly.

Bumping this as it affects us too, running the CLI on an embedded device we would really prefer not having to run Xvfb to flash an attached board. 😄

FYI, as @wollew suggested, I switched to PlatformIO which can perform headless builds and uploads of Arduino sketches. For those who can run Python in their headless environment, it can be a temporary workaround. It works a wonder for Travis testing for example.

It's very ironic multi-target PlatformIO framework can do it and official Arduino-only IDE can't. Oh, my

It's very ironic multi-target PlatformIO framework can do it and official Arduino-only IDE can't. Oh, my

Irony aside, I would like to point out the amount of work needed to achieve that. The Arduino IDE is a fork of Processing that has been designed from the beginning as a GUI application: it surely requires much more work to obtain a "pure" CLI application compared to an application that... well... is born as command line utility! :-)
Consider also that the amount of users that runs the IDE from CLI is a small minority (and who is using it "head-less" on Linux is even a share of them), that's why this issue has not been our top priority, given also the fact that a simple workaround exists.

Anyway, I've just pushed https://github.com/arduino/Arduino/pull/5578 that should solve this issue once for all.

Thank you very much for your efforts on this @cmaglie

It will be really good to be able to verify Arduino builds automatically, using the official toolchain.

Sorry if I've been rude, that wan't my intention...I was only amazed. I apologize
As @njh has said, thank you very much for your excellent work on this and on any other issue, @cmaglie.

"Consider also that the amount of users that runs the IDE from CLI is a small minority"
Considering all the above, how many did you expected?

"running-arduino-cli-from-a-headless-linux-machine" hits <0.01% of our user base that is mostly Windows / Mac with a desktop PC. BTW now it's fixed, there is no point in discussing this further.

Thanks for this work! It will enable all sorts of things from letting people use their favourite text editor or IDE for arduino code to automated rebuilds and deploy.

I'm still noticing the need for this X11 workaround as recently as the 1.8.5 build, as part of development work on a Continuous Integration system for Arduino (https://github.com/ianfixes/arduino_ci).

In addition to what I assume was the splash screen popping up, some errors were presented graphically instead of via the console, which caused a hang -- waiting for a graphical "ok" before continuing.

Is there a command line switch I'm missing?

I notice this too with 1.8.5 - even if I run with X Forwarding - as thousands of other apps run fine.

$ arduino
Gtk-Message: 12:07:10.935: GtkDialog mapped without a transient parent. This is discouraged.
java.awt.HeadlessException
        at java.awt.SplashScreen.getSplashScreen(SplashScreen.java:117)
        at processing.app.Base.<init>(Base.java:206)
        at processing.app.Base.main(Base.java:135)

I'm running fedora 27 within QubesOS. This issue didn't happen earlier, though I haven't used the arduino IDE within the last year.
Error message:

$ arduino
java.awt.HeadlessException
    at java.awt.SplashScreen.getSplashScreen(SplashScreen.java:117)
    at processing.app.Base.<init>(Base.java:206)
    at processing.app.Base.main(Base.java:135)

dnf info arduino output:

Name         : arduino
Epoch        : 1
Version      : 1.8.5
Release      : 4.fc27
Arch         : noarch
Size         : 3.0 M
Source       : arduino-1.8.5-4.fc27.src.rpm
Repo         : @System
From repo    : updates
[... description, license, ASO redacted for brevity]

@GammaSQ it appears you're using a version of the Arduino IDE installed via a package manager. It has been modified in unknown ways by 3rd parties, which might be the cause of the problem. I recommend removing that thing and trying the official Arduino IDE downloaded from:
https://www.arduino.cc/en/Main/Software

@GammaSQ @CRCinAU
running just arduino will launch the Arduino IDE (the GUI), you need to provide some command to actually do something (complie / verify / upload...)

@ianfixes
which exact command are you running? Please post in another issue with instructions to reproduce.

5578 says it fixed this, however running arduino on raspbian stretch still gives the error.

No X11 DISPLAY variable was set, but this program performed an operation which requires it.
at sun.awt.HeadlessToolkit.getMenuShortcutKeyMask(HeadlessToolkit.java:236)
at processing.core.PApplet.(Unknown Source)
... 3 more

@darrahts which command did you launch?

Arduino 2:1.0.5

arduino --upload ../controllerWithDCmotorsNetsblox/controllerWithDCmotorsNetsblox.ino --port /dev/ttyACM0

also tried the arduino-headless trick but it just hung (although no error messages, but hanging is an error itself)

You're running Arduino 1.0.5, now we are at 1.8.5.

Please remove the package coming from raspbian repositories that is very old, and download the latest from arduino.cc.

@cmagile I'll swear on my life that I saw this problem on 1.8.5 but I just ran the full suite of tests on my CI library in linux, via Travis with the xdpy display manager hack turned off, and it works fine.

Can't repro. Will open a new issue if it ever happens again.

Thanks for following up!

Yes that would make a big difference (sorry for the oversight!), however I'm still having issues. on a fresh sudo apt-get install arduino -y I still received the same error, and obviously couldnt run arduino --version to verify the version. Then, going to arduino.cc and downloading the linux arm tar.bz file, left me with this:

Adding desktop shortcut, menu item and file associations for Arduino IDE...touch: cannot touch '/root/.local/share/applications/mimeapps.list': No such file or directory
/usr/bin/xdg-mime: 803: /usr/bin/xdg-mime: cannot create /root/.local/share/applications/mimeapps.list.new: Directory nonexistent
done!

running it without sudo I get this:

touch: cannot touch '/home/pi/.local/share/icons/hicolor/.xdg-icon-resource-dummy': No such file or directory
touch: cannot touch '/home/pi/.local/share/icons/hicolor/.xdg-icon-resource-dummy': No such file or directory
touch: cannot touch '/home/pi/.local/share/icons/hicolor/.xdg-icon-resource-dummy': No such file or directory
touch: cannot touch '/home/pi/.local/share/icons/hicolor/.xdg-icon-resource-dummy': No such file or directory
touch: cannot touch '/home/pi/.local/share/icons/hicolor/.xdg-icon-resource-dummy': No such file or directory
touch: cannot touch '/home/pi/.local/share/icons/hicolor/.xdg-icon-resource-dummy': No such file or directory
touch: cannot touch '/home/pi/.local/share/icons/hicolor/.xdg-icon-resource-dummy': No such file or directory
touch: cannot touch '/home/pi/.local/share/icons/hicolor/.xdg-icon-resource-dummy': No such file or directory
touch: cannot touch '/home/pi/.local/share/icons/hicolor/.xdg-icon-resource-dummy': No such file or directory
touch: cannot touch '/home/pi/.local/share/icons/hicolor/.xdg-icon-resource-dummy': No such file or directory

I am on a fresh install of raspbian stretch. This looked similar to #6116 but the RESOURCE_NAME is already arduino-arduinoide

sudo apt-get install arduino -y

@darrahts, that will likely get you an 1.0.5 version, which is the "latest" from Debian. Better get the zipfile from arduino.cc directly (there is an ARM/rpi version).

Was this page helpful?
0 / 5 - 0 ratings