arduino / Arduino

Arduino IDE 1.x
https://www.arduino.cc/en/software
Other
14.14k stars 7.01k forks source link

Command line requires X11 #1981

Closed franky47 closed 7 years ago

franky47 commented 10 years ago

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
matthijskooijman commented 10 years ago

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

matthijskooijman commented 10 years ago

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.

nkiest commented 10 years ago

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).

AleChelli commented 9 years ago

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

kashfshah commented 9 years ago

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

raquelalegre commented 9 years ago

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

ffissore commented 9 years ago

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

raquelalegre commented 9 years ago

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

raquelalegre commented 9 years ago

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.

ffissore commented 9 years ago

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

raquelalegre commented 9 years ago

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

ffissore commented 9 years ago

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

raquelalegre commented 9 years ago

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

ffissore commented 9 years ago

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

fake-name commented 8 years ago

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

wollew commented 8 years ago

Try PlaformIO, it works perfectly for me.

fake-name commented 8 years ago

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

matthijskooijman commented 8 years ago

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.

matthijskooijman commented 8 years ago

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.

agdl commented 8 years ago

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

lmihalkovic commented 8 years ago

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.

q2dg commented 8 years ago

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

wtgee commented 8 years ago

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?

szafran81 commented 7 years ago

Still not fixed... unfortunatelly.

mxxxc commented 7 years ago

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. 😄

franky47 commented 7 years ago

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.

q2dg commented 7 years ago

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

cmaglie commented 7 years ago

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.

njh commented 7 years ago

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.

q2dg commented 7 years ago

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.

NicSil commented 7 years ago

"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?

cmaglie commented 7 years ago

"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.

merwok commented 7 years ago

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.

ianfixes commented 6 years ago

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?

CRCinAU commented 6 years ago

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)
GammaSQ commented 6 years ago

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]
per1234 commented 6 years ago

@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

cmaglie commented 6 years ago

@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.

darrahts commented 6 years ago

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

cmaglie commented 6 years ago

@darrahts which command did you launch?

darrahts commented 6 years ago

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)

cmaglie commented 6 years ago

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.

ianfixes commented 6 years ago

@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!

darrahts commented 6 years ago

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 couldn't 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

matthijskooijman commented 5 years ago

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).

PetrKosvanec commented 2 years ago

Uploading sketches in the (RHEL) user account is blocked. So in user account in shell/terminal I typed "su -" followed by root password, to get root privileges (temporarily) for the time I will be in arduino IDE, as recommended by Red Hat due to security. Then, from the terminal I've fired the Arduino IDE up, getting this same issue:

[root@localhost ~]# arduino
Picked up JAVA_TOOL_OPTIONS: 
Set log4j store directory /root/.arduino15
java.awt.HeadlessException: 
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
    at java.awt.SplashScreen.getSplashScreen(SplashScreen.java:117)
    at processing.app.Base.<init>(Base.java:246)
    at processing.app.Base.main(Base.java:150)

dnf info arduino output is:

Available Packages
Name         : arduino
Epoch        : 1
Version      : 1.8.5
Release      : 3.fc28
Architecture : noarch
Size         : 2.1 M
Source       : arduino-1.8.5-3.fc28.src.rpm
Repository   : dl.fedoraproject.org_pub_archive_fedora_linux_releases_28_Everything_x86_64_os
...

The only workaround I am aware of is to switch RHEL from user to root (discouraged by Red Hat as insecure). Fire up the IDE from there, and use it.

"Headless mode is a system configuration in which the display device, keyboard, or mouse is lacking." - that is not how I use this notebook. But I program bits and pieces on this machine, using various openjdk and java_sdk vers. I would be grateful if you can point me to other workaround(s); I doubt Xvnc si possible solution for me to look at (I've just read DESCRIPTION of 'man Xvnc'). "Virtual Network Computing is a graphical desktop-sharing system that uses the Remote Frame Buffer protocol to remotely control another computer. It transmits the keyboard and mouse input from one computer to another, relaying the graphical-screen updates, over a network." - does not look like what I need.

Obviously I can live with the current situation and fully understand that I fall into a very small userbase set. No answer from you is fine, too, and would affirm my understanding the solution would require too extensive a work given our small specific userbase.

BaNavyBlue commented 1 month ago

How is this still an issue. Heaven forbid you write code that can run independently of a GUI.

Exception in thread "main" java.lang.ExceptionInInitializerError at processing.app.Preferences.save(Preferences.java:735) at processing.app.Preferences.init(Preferences.java:249) at processing.app.Base.main(Base.java:117) Caused by: java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it. at java.desktop/sun.awt.HeadlessToolkit.getMenuShortcutKeyMask(HeadlessToolkit.java:135) at processing.core.PApplet.<clinit>(Unknown Source)

matthijskooijman commented 1 month ago

This is unlikely to be resolved, since development mostly moved to the Arduino 2.x version. Also, if you want to do something on the cli, there is now also the arduino-cli tool that is a way more streamlined and complete CLI experience than the Arduino IDE 1.x CLI that was more of a bolted-on approach.