Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headless Raspberry Pi support #313

Closed
jpkelly opened this issue Oct 29, 2018 · 102 comments
Closed

Headless Raspberry Pi support #313

jpkelly opened this issue Oct 29, 2018 · 102 comments
Assignees
Labels
area/internal Related to an internal action or function of Companion. Enhancement New feature or request Needs testing Nice to have Would be nice, but not high priority.

Comments

@jpkelly
Copy link

jpkelly commented Oct 29, 2018

Starting Companion on boot of a Raspberry PI without the need for a display connected or logging in to a VNC or SSH session.

Preferably this would be enabled via a systemd service.

Some basic config options exposed to the command line such as setting the network interface

@willosof
Copy link
Member

This is right around the corner, but it will for now require that you clone the repository and follow the developer guide, and not start it via the normal prebuilt packages.

@willosof
Copy link
Member

Did you make this @haakonnessjoen ?

@willosof willosof added Enhancement New feature or request area/internal Related to an internal action or function of Companion. Nice to have Would be nice, but not high priority. labels Nov 25, 2018
@haakonnessjoen
Copy link
Member

There is a alpha version in the source repo: headless.js. But currently it isn't that straightforward to use for the end user, since you would need to install node, and run the update scripts before you can use it. So I think we need to do something clever before we close this, and also more testing.

@depili
Copy link
Contributor

depili commented Feb 4, 2019

What would be the easiest way to import the configuration for the headless mode instance?

@haakonnessjoen
Copy link
Member

On raspberry pi? Try cp ~/.config/companion/db ~/companion/ if I don't remember wrong.

The most user friendly way would be to start it normally, export the full config as file, and then run headless and import it again, using the gui.

@depili
Copy link
Contributor

depili commented Feb 4, 2019

Getting the headless mode to run requires:

  1. installing the dev environment, which has it's own issues on a fresh rasbian: Missing libusb causes few error messages during ./tools/update.sh but exit status is 0 and no final error is given #478 and headless.js corrupts the config files if it dies due to errors during the bootup process #479
  2. running ./tools/build_writefile.sh
  3. copying the configuration to ~/companion/
  4. running ./headless.js wlan0 or ./headless.js eth0

@depili
Copy link
Contributor

depili commented Feb 4, 2019

After all that I got the headless.js running. With osc data updates coming in every 30ms from clock-8001 the update rate on buttons with variables lags 1-4 seconds behind and after about 1,5 minutes something just gives up and the stream deck goes all black.

In the all black state pressing a button on the stream deck causes it to return to the logo display after a small delay.

The companion code continues to run and still prints osc updates and button gfx generation messages into the console but everything is just dead on the stream deck side.

@depili
Copy link
Contributor

depili commented Feb 4, 2019

Deleting all but the depili-clock-8001 module seems to improve the stability considerably. Now at over 6 minutes and counting where as before it never stayed stable for 2 minutes. The updates still lag behind and arrive in clumps with the display often skipping some second display updates.

@haakonnessjoen
Copy link
Member

People have reported that installing the raspian lite image makes usb stable with stream deck using headless.js. Not sure about latency though.

@depili
Copy link
Contributor

depili commented Feb 4, 2019

It seems that the memory needs are really marginal on the pi. After the module deletion and running only one module and 3 pages of buttons, of which 2 are updating from variables, one showing seconds and one minutes, the free memory on the pi hovers at around 70-65M running with rasbian lite.

Edit: the stream deck updating stopped at 20min instead of 2 min, but still not usable

@depili
Copy link
Contributor

depili commented Feb 4, 2019

I don't like that when the updates cease and the stream deck goes black no error what so ever gets reported on the console nor does companion exit (with non-zero exit status preferably), so any kind of stability measurement or restart logic is impossible to implement.

@depili
Copy link
Contributor

depili commented Feb 4, 2019

People have reported that installing the raspian lite image makes usb stable with stream deck using headless.js. Not sure about latency though.

I have been using rasbian lite from the start.

@sphlabs
Copy link

sphlabs commented Feb 6, 2019

I was having problems with the StreamDeck going black/disconnecting. It could be reconnected by rescanning USB from the surfaces tab.

I believe this was due an under-rated power supply to the Pi. The 3 B+ draws more power than previous models, added to the power draw needed by the Streamdeck, it is possible to overload smaller PSUs.

Check /var/log/kern.log for messages like kernel: [ 1612.002574] Under-voltage detected! (0x000d0005)

@depili
Copy link
Contributor

depili commented Feb 6, 2019 via email

@depili
Copy link
Contributor

depili commented Feb 7, 2019 via email

@sphlabs
Copy link

sphlabs commented Feb 7, 2019

I've had good success so far, switching from a 1A to 2A USB power supply. Haven't done any extensive soak testing yet, but it seems to have fixed the problems for me.

@depili
Copy link
Contributor

depili commented Feb 7, 2019 via email

@depili
Copy link
Contributor

depili commented Feb 12, 2019

Continued testing with the latest head 9a404b0 button updates are steady but the stream deck still disconnects from companion after a short while. I have two different stream decks to test with currently and both are showing the same behaviour.

Running with raspberry pi 3b+ and stretch lite. Next up: testing with rpi 3b

@depili
Copy link
Contributor

depili commented Feb 12, 2019

And same results with rpi3b :/

@canoemoose
Copy link

canoemoose commented Feb 15, 2019

Depili - I'm trying this too, albeit using Irisdown Countdown Timer 2, which only provides feedback every second. My circumstances for disconnection are as follows:

  • Running both headless and non-headless, and
  • Displaying a page of buttons with feedback variables in their text - in this case the countdown time remaining

I'm using a Pi 3b (non +)
I get the following when the stream deck goes blank:

  lib/device unloading for 0001:0014:00 +2m
  lib/action adding action bitfocus-companion:instance_control +2m
  lib/action adding action bitfocus-companion:set_page +1ms
  lib/action adding action bitfocus-companion:inc_page +1ms
  lib/action adding action bitfocus-companion:dec_page +0ms
  lib/action adding action bitfocus-companion:button_pressrelease +1ms
  lib/action adding action bitfocus-companion:button_press +0ms
  lib/action adding action bitfocus-companion:button_release +1ms
  lib/action adding action bitfocus-companion:panic +6ms
  lib/usb/elgato elgato.prototype.clearDeck() +2m

Rescanning in control panel finds it again.

Is this what you see?
The same config, running on the same Windows bleeding edge build does not exhibit this bug.

@depili
Copy link
Contributor

depili commented Feb 16, 2019 via email

@canoemoose
Copy link

canoemoose commented Feb 17, 2019 via email

@alatteri
Copy link

I'm having the button blacking out issue too. Raspberry 3B+, fresh install of Lite, latest git head, Official wall wart PSU.

@willosof
Copy link
Member

willosof commented Jun 9, 2019

I've cleaned up the debug stuff a bit now. Headless is default silent now, and when it comes to the normal "npm run start", it is now "yarn dev" (electron launcher + console debug) or "yarn prod" (electron launcher, no debug)

(In the companion 2.0 branch (nopagebuttons))

@horuck
Copy link

horuck commented Jun 13, 2019

I'm running a RPI 3B+ with streamdeck on 1.4.beta since today and experience this disconnection issue you are discussing above.

Where do I need to change your fixing code and recompile then, so I get my Deck stable for now...?
Looking forward for your help.
Thanks.

@jarodwsams
Copy link
Collaborator

jarodwsams commented Jun 14, 2019

The file you're looking for is /home/pi/companion/lib/usb/elgato.js. The draw function starts on line 134. All you need to do is make the code modification and then reboot (sudo reboot now); no need to rebuild or anything like that.

No guarantees this works. You're running 1.4-beta and this is being tested with 1.3-stable. It should work, but we don't even have this as an official fix for 1.3-stable.

Where you see this code block...

elgato.prototype.draw = function(key, buffer) {
	var self = this;

	buffer = self.handleBuffer(buffer);

	try {
		self.streamDeck.fillImage(self.reverseButton(key), buffer);
	} catch (e) {
		self.system.emit('elgatodm_remove_device', self.devicepath);
	}

	return true;
}

...replace it with this block...

elgato.prototype.draw = function(key, buffer) {
	var self = this;
	buffer = self.handleBuffer(buffer);

	try {
		self.streamDeck.fillImage(self.reverseButton(key), buffer);
		return true;
	} catch (e) {
		console.log(e)
		// failed to redraw, try again
		setTimeout(self.redraw.bind(self), 20);
		}
	
	}

elgato.prototype.redraw = function(key, buffer) {
	var self = this;
	buffer = self.handleBuffer(buffer);

	try {
		self.streamDeck.fillImage(self.reverseButton(key), buffer);
		return true;
	} catch (e) {
		self.log('Error drawing:', e);
		self.system.emit('elgatodm_remove_device', self.devicepath);
		return false;
	}
}

@horuck
Copy link

horuck commented Jun 14, 2019

thanks jarodwsams!
just did the change and will report back here later!

@jarodwsams
Copy link
Collaborator

If you still notice drops (I did, but only once when I was making a lot of changes all at once) try replacing my code block with the one from @Towerful. Mine tries it again just once after 20ms. His adds a retry counter (up to twice) after 20ms.

elgato.prototype.draw = function(key, buffer, attempts = 0) {
        var self = this;
        if(!attempts){
                buffer = self.handleBuffer(buffer);
        }
        attempts++;

        try {
                self.streamDeck.fillImage(self.reverseButton(key), buffer);
                return true;
        } catch (e) {
                if(attempts > 2) {
                        self.log('Error drawing:', e);
                        self.system.emit('elgatodm_remove_device', self.devicepath);
                        return false;
                }
               setTimeout(self.draw.bind(self), 20, key, buffer, attempts)
                // alternatively a setImmediate() or nextTick()
        }
}

@horuck
Copy link

horuck commented Jun 14, 2019

With your code replaced (with the redraw sectionI) I got it crashing again quite fast after a few minutes playing around with my hyperdeck mini,
I then put in the code from @Towerful and all good so far... Will test further.

Thanks!

@jarodwsams
Copy link
Collaborator

If you haven't already, you should read the note at the top of the raspberrypi.md document.
https://github.com/bitfocus/companion/blob/master/documentation/raspberrypi.md

Please note: performance on any Raspberry Pi system to date is less than optimal, and can easily break. Running Companion in its current form on a Raspberry Pi is not recommended. However, since the RPi is a popular device these instructions have been provided for you to use at your own risk. If you insist on running Companion on a Raspberry Pi, it is recommended to run Companion headless on the "Lite" version of the Raspbian OS. This will maximize the potential performance on your Raspberry Pi.

@horuck
Copy link

horuck commented Jun 19, 2019

Code from @Towerful runs stable on my pi 3B+ with "regular" streamdeck so far.
@jarodwsams thanks for the not recommendation on pi. Will stick for a small linux pc for further installation and production use to have quicker USB reaction, http requests and emulator via Pi I find quite acceptable... Thanks for this great Software & Support!

@Coachwest2019
Copy link

I keep getting an error with line 54 anyone know what it could be and how to fix it?

@jarodwsams
Copy link
Collaborator

@Coachwest2019, we need some more info, and a screenshot or two.
What device?
What OS?
What OS Version?
What are you attempting to do when you get the error?
Can you share a screenshot of the error?

@Coachwest2019
Copy link

error shot 1
error shot 2
All on windows 10 this is for the companion

@jarodwsams
Copy link
Collaborator

@Coachwest2019 Since your issue is not related to the topic of this post, please create a new issue report. You can do that by clicking this link: https://github.com/bitfocus/companion/issues/new/choose. You'll be given a bug report template to fill out to make sure the community has all the information needed to assist you.

@willosof
Copy link
Member

willosof commented Jul 25, 2019

But, can we close this ticket? I'd say we've had rpi headless support after headless.js was introduced :)

@jarodwsams
Copy link
Collaborator

jarodwsams commented Jul 25, 2019

But, can we close this ticket? I'd say we've had rpi headless support after headless.js was introduced :)

I'd think so. Aside from the lag (known issue with the hardware) it's been working quite swimmingly at church for several weeks now.

@depili
Copy link
Contributor

depili commented Jul 25, 2019 via email

@jarodwsams
Copy link
Collaborator

@depili Honestly I wonder if the issue isn't so much what the software is doing, but the fact that the Ethernet runs over the USB bus on the RPi3. I've seen a lot of reports claiming that the RPi4 runs smooth as butter (at least on the 2GB version, unknown on the 1GB), and aside from an OS update the biggest relevant change is that the Ethernet was pulled off the USB bus.

I'm hoping to get a 4 4GB here soon and will be able to confirm the accuracy of those reports. I'd like to be able to get all 3 versions of the 4 (1GB, 2GB, 4GB RAM) to test side-by-side, but I don't think I'll be able to do that.

@josephdadams
Copy link
Member

Housekeeping on the open issue here. We do have headless support... how is it working for you guys? Stable/recommended on pi4 only?

@alatteri
Copy link

working well on headless RPi4 for me.

@jarodwsams
Copy link
Collaborator

jarodwsams commented Aug 23, 2019

I would call it stable, with the caveat that you should not leave it always-on. Either shut down the Pi when it's not in use, or implement some method to have it automatically reboot on a regular schedule (I'd recommend daily). It is strongly recommended to not run Companion on a Pi 3, even a Pi 3 B+. Performance is terrible and laggy and not suitable for production. My personal recommendation is at minimum a Pi 4 2GB.

All of that said, I'd echo @alatteri. It works quite nicely under proper working conditions.

haakonnessjoen added a commit that referenced this issue Aug 31, 2019
@haakonnessjoen
Copy link
Member

Headless is working. The disconnection problem in RP3 should also be fixed now.

@jimyehoo
Copy link

I setup a pi 4 for pihole, then some other server function and companion. The thing is, I need the pihole running most of the time while I would like to be able to remotely start Companion when I need it and shut it down when I am done. Is there a mechanism to accomplish this? a ssh script or something that I can create on Windows or Mac to remotely control it? Companion is constantly trying the connect to the device instance and that's wasted bandwidth when none of the media activity is going on. But wonderful job on the raspberry repository, loved it!

@josephdadams
Copy link
Member

@jimyehoo there’s a new internal action in Companion to close it out. Assign that action to a button and then you can trigger that a number of ways. The easiest is probably curl/http. As far as opening Companion on schedule/trigger, it’s pretty easy to SSH and start a process.

@jimyehoo
Copy link

I actually have issues with Pi 4 install, the db copying says file is not found, it worked on Pi 2, but not on Pi 4. I installed the Pi 4 several times and on many installs, it just doesn't work. The install process doesn't report error but the db is always not there to be copied. I am not sure if this is the cause, but I saw the compiled yarn is for armv7 and not armv8 which the Pi 4 cpu is on? I have the Pi 4 doing lighting control and mumble chat, and the only thing I need on this Pi 4 is the Companion.

@jarodwsams
Copy link
Collaborator

jarodwsams commented Sep 27, 2019

image

If you're talking about this error, I regularly see that as well. I had it when my production unit was a Pi 3 B+, as well, but I never saw any actual issues caused by it.

This specific bug actually is just a timing issue that shouldn't have any real impact on performance. I reported it back in June: #679

@jimyehoo
Copy link

yes, that warning comes up, too. But I am talking during the installation process where if I just installed the Companion and run it the first time, I enter this command to copy the db...
cp ~/.config/companion/db ~/companion/
and it gives me error saying the file is not found.
cp: cannot stat '/home/pi/.config/companion/db': No such file or directory
but on some installation, companion runs after reboot, but on some installation, companion just not running. I tried to use yarn prod to see if companion is running but it just complaint about can't find display

@jarodwsams
Copy link
Collaborator

@jimyehoo Ok, let's deal with that on an individual issue/bug report. Open a new report, with screenshots or log files if you can, with as much detail as possible, and tag me in it so I see it. I'll take a look at it as soon as I can.

New Issue/Bug Report: https://github.com/bitfocus/companion/issues/new/choose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/internal Related to an internal action or function of Companion. Enhancement New feature or request Needs testing Nice to have Would be nice, but not high priority.
Projects
None yet
Development

No branches or pull requests