Balena Dash Request

Hi team,

I am trying to modify the Balena Dash project so the web page reverts to a home page after a period of inactivity. I’ve tried modifying the scheduler docker, overlaying JavaScript over a webpage, and trying to modify the Unclutter project. None of this has yielded great results, so I was wondering if anyone here had any suggestions?

Thanks,
-CJ-

Can you share what you tried? Why it did not work with JavaScript for example?

Sure. In this case, I’m trying to show a website that allows users to sign a waiver before participating in an event. This waiver is hosted by EZWaiver-- a website that I don’t have control over. I tried making my own webpage with an iFrame pointing to our EZWaiver, but the refresh script didn’t work inside the iFrame.

I’ve also tried replacing the code in the Scheduler container with the following code

//backlight_off.sh

#!/bin/bash
echo -n 1 > curl -X POST --header “Content-Type:application/json”
–data ‘{“appId”: 1501229}’
“$BALENA_SUPERVISOR_ADDRESS/v1/restart?apikey=$BALENA_SUPERVISOR_API_KEY”

I’ve also looked into using the ADMBrowser solution but I kept getting errors stating that the command Python and the file browser.py weren’t found, even though I had added Python to the Dockerfile.template.

I understand that I can use Chron, but I don’t want the website to refresh while a user is filling out info.

Edit: I found another Balena project that is similar to what I’m trying to do, although it refreshes in regimented increments instead of timing how long the device has been idle. I will try to study this project and see if I can modify it to do what I need.

Hey @cpollock, interesting problem you have there. I will try a few things today and I will get back to you then.

Cheers

Hey @cpollock, I tried one solution.

Check this branch https://github.com/balena-io-projects/balena-dash/tree/detect-touch

There is a container called touch that checks for touches on the screen.
The start.py triggers a restart of the wpe container every 600 seconds (you can update the code there).
If someone touches the screen, it restarts the counter, and so on.

Let me know if this helps on your project.

Thanks

Hi @dansku

Thanks for taking the time to write that code. I’m getting this error:

14.08.19 08:45:16 (-0600) Service exited 'touch sha256:87a2780bd37d8f8236c4820179b22c5bcc02469e347a41eb297026cb951d9547'

14.08.19 08:45:13 (-0600) touch Traceback (most recent call last):
14.08.19 08:45:13 (-0600) touch File “start.py”, line 5, in
14.08.19 08:45:13 (-0600) touch ts = Touchscreen()
14.08.19 08:45:13 (-0600) touch File “/usr/local/lib/python3.5/site-packages/ft5406-0.0.2-py3.5.egg/ft5406.py”, line 124, in init
14.08.19 08:45:13 (-0600) touch File “/usr/local/lib/python3.5/site-packages/ft5406-0.0.2-py3.5.egg/ft5406.py”, line 225, in _touch_device
14.08.19 08:45:13 (-0600) touch RuntimeError: Unable to locate touchscreen device: FT5406 memory based driver

Instead of the official 7" Pi touchscreen, I’m connected to a standard HDMI + USB touch screen monitor, so I think that’s the issue.

@cpollock

Yes, then in your case you can modify the touch container and code to do something similar.
I haven’t used an HDMI+USB touch screen so I am not 100% sure how to do that. But see if you can get the touchscreen to trigger the actions then.

Thank you

Already on it-- most touch screens just simulate a mouse cursor jumping to a position. I’m trying to edit your code to listen for mouse or keyboard input now. I will update this thread once I’m able to get it. Thanks again!

Great, keep us posted!

Thank you

Small update on my progress: I looked into using the Pynput library instead of ft5406 because I think it would be more versatile, however I ran into issues with the X11/xorg dependencies. I’m now looking into solutions with PyQt5.

I’m still trying to get this working, but my novice coding skills are holding me back. I’m looking at either trying to run multiple containers with an X11 server or possibly using an entirely different web browser. If anyone in the forums has more experience and thinks this feature would be useful, feel free to contribute. I will be passing this along to a few colleagues to see what they think.

This is the error that is holding me back right now:

Error Log

touch Traceback (most recent call last):
touch File “start.py”, line 1, in
touch from pynput import keyboard
touch File “/usr/local/lib/python3.5/site-packages/pynput/init.py”, line 40, in
touch from . import keyboard
touch File “/usr/local/lib/python3.5/site-packages/pynput/keyboard/init.py”, line 49, in
touch from ._xorg import KeyCode, Key, Controller, Listener
touch File “/usr/local/lib/python3.5/site-packages/pynput/keyboard/_xorg.py”, line 39, in
touch from pynput._util.xorg import (
touch File “/usr/local/lib/python3.5/site-packages/pynput/_util/xorg.py”, line 40, in
touch _check()
touch File “/usr/local/lib/python3.5/site-packages/pynput/_util/xorg.py”, line 38, in _check
touch display = Xlib.display.Display()
touch File “/usr/local/lib/python3.5/site-packages/Xlib/display.py”, line 89, in init
touch self.display = _BaseDisplay(display)
touch File “/usr/local/lib/python3.5/site-packages/Xlib/display.py”, line 71, in init
touch protocol_display.Display.init(self, *args, **keys)
touch File “/usr/local/lib/python3.5/site-packages/Xlib/protocol/display.py”, line 84, in init
touch name, protocol, host, displayno, screenno = connect.get_display(display)
touch File “/usr/local/lib/python3.5/site-packages/Xlib/support/connect.py”, line 73, in get_display
touch return mod.get_display(display)
touch File “/usr/local/lib/python3.5/site-packages/Xlib/support/unix_connect.py”, line 76, in get_display
touch raise error.DisplayNameError(display)
touch Xlib.error.DisplayNameError: Bad display name “”

Hi there, are you exporting/setting beforehand the env variable DISPLAY? So that e.g. DISPLAY=":0" when running your application?

Hi @thundron I have been using Balena Cloud, and the Environment Variable values I input were “DISPLAY” and “:0”. Doing so gives me the following error:

touch Xlib.error.DisplayConnectionError: Can’t connect to display “:0”: [Errno 111] Connection refused

Hi @cpollock,
would you mind providing us with the Dockerfile / Docker-Compose files so we can take a look if all dependencies are met ?
Regards
Thomas

@samothx sure thing. Here is the docker-compose: https://pastebin.com/Thmeueay

And here is the Dockerfile for the Touch container: https://pastebin.com/eBCuGxjF

Thanks so much for taking the time to look into this.

Thanks for that. I have pinged the engineers. We will have to wait for someone familiar with this topic to come online so it might until tomorrow before someone takes a look at your files.

While we check the dependencies, could you try installing xhost and running xhost + before running your application and telling us if it changes anything?

You’ll need to install either x11-utils or, if that fails, x11-server-utils IIRC. Let us know how it goes

@thundron thanks for the suggestion

It looks like the correct package is x11-utils, which I have imported. With Balena, how would I add xhost + privileges? I see that in regular Debian, I can do something like: xhost +si:localuser:root but I don’t that applies to Balena.

Without having xhost + added, it looks like the log errors are the same:

Logs
 touch  Traceback (most recent call last):
 touch    File "start.py", line 1, in <module>
 touch      from pynput import mouse
 touch    File "/usr/local/lib/python2.7/site-packages/pynput/__init__.py", line 40, in <module>
 touch      from . import keyboard
 touch    File "/usr/local/lib/python2.7/site-packages/pynput/keyboard/__init__.py", line 49, in <module>
 touch      from ._xorg import KeyCode, Key, Controller, Listener
 touch    File "/usr/local/lib/python2.7/site-packages/pynput/keyboard/_xorg.py", line 39, in <module>
 touch      from pynput._util.xorg import (
 touch    File "/usr/local/lib/python2.7/site-packages/pynput/_util/xorg.py", line 40, in <module>
 touch      _check()
 touch    File "/usr/local/lib/python2.7/site-packages/pynput/_util/xorg.py", line 38, in _check
 touch      display = Xlib.display.Display()
 touch    File "/usr/local/lib/python2.7/site-packages/Xlib/display.py", line 89, in __init__
 touch      self.display = _BaseDisplay(display)
 touch    File "/usr/local/lib/python2.7/site-packages/Xlib/display.py", line 71, in __init__
 touch      protocol_display.Display.__init__(self, *args, **keys)
 touch    File "/usr/local/lib/python2.7/site-packages/Xlib/protocol/display.py", line 89, in __init__
 touch      self.socket = connect.get_socket(name, protocol, host, displayno)
 touch    File "/usr/local/lib/python2.7/site-packages/Xlib/support/connect.py", line 87, in get_socket
 touch      return mod.get_socket(dname, protocol, host, dno)
 touch    File "/usr/local/lib/python2.7/site-packages/Xlib/support/unix_connect.py", line 127, in get_socket
 touch      raise error.DisplayConnectionError(dname, str(val))
 touch  Xlib.error.DisplayConnectionError: Can't connect to display ":0": [Errno 111] Connection refused

Hey @cpollock,

Tomorrow I will give it a try to detect mouse clicks with the pynput library and a regular mouse and I will get back to you!

Thanks :wink:

1 Like