Friday, February 6, 2015

Stoker Web on NUC PC running Yocto Linux-Updated

Stoker controller with NUC on top
Stoker and NUC setup beside smoker
Update: January 2016
I had the need to setup my Stoker-web server again recently and found I needed to further document how I got the Yoctoproject.org linux setup.  So I added some steps before step 1 below.



Below are the steps needed to build a headless server that runs the Stoker-web server application.  This application provides the communication between the Rock's BBQ Stoker grill and smoker controller and web browsers and Android applications to monitor and control a cooking session.   The server keeps and plots all the temperatures and history of a cooking session so it can be viewed in real time or retrieved later from any PC, phone, or tablet.  The Stoker-web server software can be found at stoker-web, or github.com/gbak/stoker-web/.  To control and monitor StokerWeb server you can use the Stoker-web Android app from Google Play, or just us a browser on any device.


The hardware used is an Intel Celeron NUC PC with minimal DRAM (2GB), mSATA SSD, and an Intel PCIe N-6235 WiFi adapter.  I connect the NUC LAN port directly to the Stoker LAN port with a short Ethernet cable.  The WiFi is uses to put the Stoker-Web server on the local network. Start with the NUC BIOS at default settings and time set to UTC time.

I used Yoctoproject.org Linux.  I started with Yocto Dizzy 1.7.3, which was the latest Dizzy version in January 2016.  I only documented the changes to a standard build using a clone of the Dizzy branch. First 5 steps are on an Ubuntu 14.04.3 LTS workstation.

1.  First setup the Yocto environment:
 git clone –b dizzy git://git.yoctoproject.org/poky.git     
 cd poky                                                     
 git clone git://git.yoctoproject.org/meta-intel.git –b dizzy
 git clone git://git.yoctoproject.org/meta-oracle-java.git   
 source oe-init-build-env /home/jim/Yocto-workdir/              

2.  Changes to conf/local.conf

MACHINE ?= "nuc"
IMAGE_INSTALL_append = " oracle-jse-jre dropbear resolvconf"
LICENSE_FLAGS_WHITELIST += "oracle_java"
DL_DIR ?= "/work/downloads"
PACKAGE_CLASSES ?= "package_deb"

3.  Changes to conf/bblayers.conf

/home/jim/poky/meta-intel \
/home/jim/poky/meta-intel/meta-nuc \
/home/jim/poky/meta-oracle-java\

4.  Build with 'bitbake core-image-base'
5.  Copy hddimg image file to USB key.
cd /home/jim/Yocto-workdir/tmp/deploy/images/nuc
#make sure USB key is not mounted and figure out what it’s dev name is
sudo dd if=core-image-base-nuc.hddimg of=/dev/sdx   (make sure you have the right dev# for USB key)
sync

sudo eject /dev/sdx
5.1  Boot USB key on NUC using install option to create boot image on NUC SSD.
6.  Configure /etc/network/interfaces

auto lo
iface lo inet loopback

# The primary network interface

auto eth0
iface eth0 inet static
address 192.168.10.2
netmask 255.255.255.0
network 192.168.10.0
broadcast 192.168.10.255

# Wireless

auto wlan0
iface wlan0 inet static
wireless_mode managed
wireless_essid any
wpa-driver wext
wpa-conf /etc/wpa_supplicant.conf
address 192.168.0.210
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameserver 208.67.222.222 208.67.220.220

7.  Configure /etc/wpa_supplicant.conf  #Note that the data between network = {___} you get by executing:

# wpa_passphass “YOUR PASSPHASE” “YOUR_ESSID” > wpa.conf  and adding wpa.conf to the end of /etc/wpa_supplicant.conf

ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
update_config=1
network={ssid="YOUR_ESSID"
#psk="YOU PASSPHRASE"
psk=e6d38a3a6479d00ea8e5b2adcd39b2c8f14444f35555f2f327edf4f9f33d1cb5
}

8.  Change root password to 'password' or whatever you want.
9.  Set link to fix library bug:

ln -s /lib /lib64

10. Set timezone in /etc/profile

export TZ="EST5EDT”

11. Create  /etc/acpi/powerbtn.sh

#!/bin/sh
# /etc/acpi/powerbtn.sh
# Initiates a shutdown when the power button has been pressed.
/sbin/shutdown -h now "Power button pressed"

12. Create /etc/acpi/events/powerbtn

event=button[ /]power
action=/etc/acpi/powerbtn.sh

13. Change /boot/EFI/BOOT/grub.cfg boot time from 10 seconds to 1.
14. Install stoker-web and tomcat per: code.google.com/p/stoker-web/, which is basically as follows.
15.  In /home/root/StokerWebDir unpack stokerweb files and create user with:

java -jar runStokerweb.jar

16.  Localize some changes:
  • stokerweb.properties: Edit the IP address for your stoker(192.168.10.1), email settings and local zip code.  
  • Edit /etc/profile to add export STOKERWEB_DIR=”/home/root/StokerWebDir”


17.  Put apache-tomcat-7.0.27.tar.gz in /var/local
18.  Change directory to /var/local and extract tar file and create symbolic link called tomcat.

sudo tar zxvf apache-tomcat-7.0.27.tar.gz  
sudo ln –s apache-tomcat-7.0.27 tomcat 

19.  Change directory to the tomcat/conf directory.
20.  Edit the tomcat-users.xml file and add the lines below. Careful to avoid the commented areas:

<role rolename=”manager-gui”/>
<user username=”admin” password=”YOURPASSWORD” roles=”manager-gui”/>

21.  Change maximum size of .war file allowed by editing /var/local/tomcat/webapps/manager/WEB-INF/web.xml as follows:

<!-- 60MB max -->                                                          
<max-file-size>62914560</max-file-size>
<max-request-size>62914560</max-request-size> 

22.  Change to the /etc/init.d directory
23.  Create a file called tomcat and add the contents below. The paths to JAVA_HOME and STOKERWEB_DIR are specific to my example.

export JAVA_HOME=/usr/share/jre1.7.0_67
case $1 in
   start)
      sh /var/local/tomcat/bin/startup.sh
      ;;
   stop)
      sh /var/local/tomcat/bin/shutdown.sh
      ;;
    restart)
      sh /var/local/tomcat/bin/shutdown.sh
      sh /var/local/tomcat/bin/startup.sh
       ;;
esac
exit 0

24.  Change the permissions on the tomcat file and add the necessary aliases in the rc directories:

sudo chmod 755 /etc/init.d/tomcat
sudo ln –s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
sudo ln –s /etc/init.d/tomcat /etc/rc5.d/S99tomcat

25. Rebooting will start tomcat. Then take the file /home/root/StokerWebDir/stokerweb.war to whatever computer you will be running a browser for StokerWeb.
26.  Using browser go to http://192.168.0.210:8080/manager/. This will ask for a login that was set in step 20.
27.  Once into the tomcat manager function, select deploy via .war file and select the stokerweb.war you copied from the NUC.
28.  Once that deployment is finished, you work with the stoker-web app to configure and use.
29.  I recommend getting the Android app from Google Play for your Smartphone.  It will work with your Stoker directly if it has WiFi. Or work with the Stoker-web server you just setup.
30.  If you want to use you smartphone or a browser to talk to stoker-web server away from your home network, just setup your AP/router/Cable modem to do port forwarding and open up port 8080 on your home network and forward traffic to 192.168.0.210 in this example.

P.S.  For the record, my Stoker is an original “white box” version with no WiFi so the NUC is directly connected to the Stoker with a short Cat-5 cable and the Stoker IP is set static at 192.168.10.1.