Previous posts for this project:
- [AirCare] InTheAir - Project Description
- [AirCare] InTheAir - Week 1: Getting a Launchpad to Blink
- [AirCare] InTheAir - Week 2: Preparing the Beaglebone Black
- [AirCare] InTheAir - Week 3: Fuel Tank Testing
- [AirCare] InTheAir - Week 4: Using the CC3200
- [AirCare] InTheAir - Week 5: openHAB and MQTT
- [AirCare] InTheAir - Week 6: Accessing Fuel Tank's Data
- [AirCare] InTheAir - Week 7: Dust sensor
- [AirCare] InTheAir - Week 8: MSP430FR5969 with Energia14
- [AirCare] InTheAir - Week 11: CC3200, Energia and analogRead()
Introduction
I'm using a Beaglebone Black and BB View as the main user interface. Because the BB View is a touch screen, I want to avoid the need for another input device such as a keyboard.
In this post, I'll set up openHAB and Chromium to start automatically and visualise the openHAB GUI without having to enter an URL or open a browser manually.
openHAB
First, I created a script which will launch the desired application, in this case: openHAB. The script will be put in "/usr/bin".
debian@beaglebone:~$ sudo nano /usr/bin/openhab.sh #!/bin/bash /opt/openhab/start.sh
The script needs to be made executable so it can be launched successfully.
debian@beaglebone:~$ sudo chmod u+x /usr/bin/openhab.sh
Next, create the service. Some prerequisites can be specified, for example the need of having the network up and running first.
debian@beaglebone:/usr/bin$ sudo nano /lib/systemd/openhab.service [Unit] Description=openHAB After=syslog.target network.target [Service] Type=simple ExecStart=/usr/bin/openhab.sh [Install] WantedBy=multi-user.target
Create a symbolic link to let the system know where to find the service:
debian@beaglebone:~$ cd /etc/systemd/system debian@beaglebone:/etc/systemd/system$ sudo ln /lib/systemd/openahb.service openhab.service
Try starting the service to check for mistakes/errors. If all is well, the service can be enabled.
debian@beaglebone:/etc/systemd/system$ sudo systemctl daemon-reload debian@beaglebone:/etc/systemd/system$ sudo systemctl start openhab.service debian@beaglebone:/etc/systemd/system$ sudo systemctl enable openhab.service
As a final check, reboot the Beaglebone Black to confirm it's working as expected.
debian@beaglebone:/etc/systemd/system$ sudo reboot
After reboot, the openHAB start script seems to be running, this is a good sign. Checking the logs, openHAB is started as expected!
debian@beaglebone:~$ ps aux | grep start root 758 0.0 0.0 1336 440 ? S 18:59 0:00 /bin/sh /opt/openhab/start.sh root 996 0.0 0.5 5864 2676 ? Ss 18:59 0:00 /usr/sbin/apache2 -k start www-data 1003 0.0 0.3 5644 1996 ? S 18:59 0:00 /usr/sbin/apache2 -k start www-data 1005 0.0 0.4 227056 2364 ? Sl 18:59 0:00 /usr/sbin/apache2 -k start www-data 1007 0.0 0.4 227048 2356 ? Sl 18:59 0:00 /usr/sbin/apache2 -k start debian 1323 0.0 0.1 1576 592 pts/0 S+ 19:00 0:00 grep start
debian@beaglebone:~$ less /opt/openhab/logs/openhab.log 2015-01-14 19:00:39.422 [INFO ] [.o.core.internal.CoreActivator] - openHAB runtime has been started (v1.6.0). 2015-01-14 19:00:50.451 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - mDNS service has been started 2015-01-14 19:00:51.111 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - Service Discovery initialization completed. 2015-01-14 19:00:51.168 [INFO ] [.io.transport.mqtt.MqttService] - MQTT Service initialization completed. 2015-01-14 19:00:51.180 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'eclipseiot' 2015-01-14 19:00:57.860 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'rrd4j.persist' 2015-01-14 19:00:59.817 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'intheair.items' 2015-01-14 19:01:11.457 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'intheair.sitemap' 2015-01-14 19:01:15.109 [INFO ] [penhab.io.rest.RESTApplication] - Started REST API at /rest 2015-01-14 19:01:21.365 [INFO ] [.o.u.w.i.servlet.WebAppServlet] - Started Classic UI at /openhab.app
Chromium
To automatically start applications when the desktop loads, an "autostart" file can be edited to add the required applications.
At the end of the file, I appended a line to start Chromium automatically and open the openHAB web interface. I've also added the "--kiosk" option, which will load Chromium in full screen mode without the possibility to close it. This will be useful to avoid anyone accidentally closing the application or tampering with the system.
debian@beaglebone:~$ sudo nano /etc/xdg/lxsession/LXDE/autostart @lxpanel --profile LXDE @pcmanfm --desktop --profile LXDE @chromium --kiosk "http://localhost:9090/openhab.app?sitemap=intheair"
The result after having applied the changes and rebooting the system, is the following:
There are two issues with the above screenshot:
- Chromium is started and attempting to open the openHAB GUI before openHAB is fully started
- There is a warning message at the top regarding missing API keys
On the good side: Chromium is started in kiosk mode and trying to open the correct URL, meaning the command works.
To solve the first issue, I chose the quick and dirty solution of adding a delay. Because other "custom" commands might be needed, I moved the delay and startup of Chromium to a separate script and called that script in the "autostart" instead.
I added a 2 minute sleep before starting Chromium, giving openHAB enough time to start properly.
debian@beaglebone:~$ sudo nano delayed-chromium.sh #!/usr/bin/sh sleep 120 && chromium --kiosk "http://localhost:9090/openhab.app?sitemap=intheair"
debian@beaglebone:~$ sudo chmod u+x delayed-chromium.sh
debian@beaglebone:~$ sudo nano /etc/xdg/lxsession/LXDE/autostart @lxpanel --profile LXDE @pcmanfm --desktop --profile LXDE @sh /home/debian/delayed-chromium.sh
After rebooting, Chromium is started 2 minutes later as expected and the openHAB GUI loads properly. Ideally, I should check for openHAB's status until fully started and then launch Chromium.
The get rid of the second issue, the Google API keys warning, some environment variables need to be set:
debian@beaglebone:~$ export GOOGLE_API_KEY="no" debian@beaglebone:~$ export GOOGLE_DEFAULT_CLIENT_ID="no" debian@beaglebone:~$ export GOOGLE_DEFAULT_CLIENT_SECRET="no"
Using "set", it is possible to confirm the variables have been set. Unfortunately, setting them like this is not permanent and a reboot will lose the information.
debian@beaglebone:~$ set ... GOOGLE_API_KEY=no GOOGLE_DEFAULT_CLIENT_ID=no GOOGLE_DEFAULT_CLIENT_SECRET=no ...
This is where the custom script from earlier comes in handy. I added the "export" statements into the script, which results in them being executed at every startup.
debian@beaglebone:~$ sudo nano delayed-chromium.sh #!/usr/bin/sh export GOOGLE_API_KEY=no export GOOGLE_DEFAULT_CLIENT_ID=no export GOOGLE_DEFAULT_CLIENT_SECRET=no sleep 120 && chromium --kiosk "http://localhost:9090/openhab.app?sitemap=intheair"
The annoying warning is finally gone:
Conclusion
After powering on the Beaglebone Black, the openHAB GUI will open automatically on the touch screen without user intervention. Hooray!
Top Comments