Tag Archives: Ubuntu

MTConnect FANUC Adapter on Ubuntu Linux


The FANUC FOCAS shared library from the FANUC FOCAS CD A02B-0207-K737 version 4.1 or higher  must first be installed and registered in Ubuntu 14.04 LTS.

$ sudo cp libfwlib32.so.1.0.0 /usr/local/lib/libfwlib32.so.1.0.0
$ sudo ldconfig
$ sudo ln -s /usr/local/lib/libfwlib32.so.1.0.0 /usr/local/lib/libfwlib32.so

Next up we need to get the MTConnect adapter from GitHub.

$ cd ~ 
$ git clone https://github.com/mtconnect/adapter.git

We only actually need a limited subset of files from the adapter downloaded from GitHub.  For convenience in building the binary we will copy all the needed files to the same directory. (Note, so wildcards can be used more than the needed files are copied.)

$ mkdir fanuc
$ cp ~/adapter/fanuc/adapter.ini ~/fanuc/adapter.ini
$ cp ~/adapter/fanuc/fanuc.xml ~/fanuc/fanuc.xml
$ cp ~/adapter/fanuc/*.cpp ~/fanuc/
$ cp ~/adapter/fanuc/*.hpp ~/fanuc/
$ cp ~/adapter/src/*.cpp ~/fanuc/
$ cp ~/adapter/src/*.hpp ~/fanuc/
$ cp ~/adapter/minIni_07/*.c ~/fanuc/
$ cp ~/adapter/minIni_07/*.h ~/fanuc/

Once the files are in the ~/fanuc/ directory, we need to modify the source code.  The GitHub adapter was meant for Windows, and their are several functions that need to be modified.

$ sudo nano ~/fanuc/fanuc_adapter.cpp
    Remove: #include <excpt.h>
    Change: __try and __exception to try/catch(...)

    Change: Sleep(5000) to sleep(5)

    Change: _strnicmp() to strncasecmp()

    Add Before : short ret = :: cnc_allclibhndl3...

    long level = 3;
    std::string filename = "focas.log";
    const char * c =  filename.c_str();
    short log = ::cnc_startupprocess(level, c);

    Add After: cnc_freelibhndl....


Finally the header file for Linux from the FOCAS cd is copied to the directory.  Note the name change required as the source files refer to to Fwlib32.h.

$ sudo cp fwlib32.h ~/fanuc/Fwlib32.h

With the source code modified, its time to compile the binary.  Sorry for the sloppy g++ command, this could be cleaned up with a nice CMakeLists.txt.

$ cd ~/fanuc/
$ g++ minIni.c device_datum.cpp fanuc_axis.cpp fanuc_path.cpp service.cpp condition.cpp cutting_tool.cpp string_buffer.cpp logger.cpp client.cpp server.cpp adapter.cpp fanuc_adapter.cpp FanucAdapter.cpp -lfwlib32 -lpthread -o adapter

Finally setup the adapter.ini file with the appropriate settings for your machine and run the binary.

$ ./adapter debug adapter.ini

Conclusion I’m certain one day the source code for the Linux FANUC adapter will be available from GitHub as the code is just a slight adaptation from the Windows version.  Until then, I hope you enjoyed this tutorial!

MTConnect Agent on Ubuntu Linux


Before MTConnect can be installed some prerequisites must be in place.  A clean install of Ubuntu 14.04 LTS will not have many of the packages required.  Install these packages using the apt-get command.

$ sudo apt-get install libxml2 libxml2-dev cmake git libcppunit-dev build-essential screen ruby

After all the required packages are in place, the MTConnect source code needs to be downloaded from GutHub.  The source code should compile without any modifcation using cmake and make.

$ cd ~
$ git clone https://github.com/mtconnect/cppagent.git
$ cd cppagent
$ cmake .
$ make

MTConnect Agent Installation

Now that binaries are compiled from the MTConnect source, they just need to be put into appropriate directories.   The agent binary and the configuration file are first.

$ sudo mkdir /etc/mtconnect
$ sudo cp ~/cppagent/agent/agent.cfg /etc/mtconnect/
$ sudo cp ~/cppagent/agent/agent /bin/agent

The source from GitHub contains a script to run MTConnect as a daemon.  I instead opted to write a BASH script that suited my needs a little better.  The script is available at the end of blog.  The blog downloads it from this server.  After it is downloaded it is given permission to execute and added to the startup scripts.

$ cd ~
$ wget http://www.ellisware.com/downloads/agent.sh
$ sudo mv ~/agent.sh /etc/init.d/agent
$ sudo chmod +x /etc/init.d/agent
$ sudo update-rc.d agent defaults

The script requires the user ‘mtconnect’.  So we need to add that user.  Pick a password that is appropriate for you.  For security reasons, you probably should pick a different username and change it in the script, however, this blog uses the default.

$ sudo adduser mtconnect

MTConnect Simulator Installation

The default configuration file that was downloaded with the source code defines a simulator.  For the MTConnect agent to start, it needs to connect to all devices listed in its configuration file.  So now we setup the simulator device.

$ sudo mkdir /etc/mtconnect/simulator
$ sudo rsync -avr ~/cppagent/simulator/ /etc/mtconnect/simulator/

The default configuration file expects the simulator adapter to be one directory above where we placed it.  To correct this, edit the agent.cfg file and point to the correct path for the simulator.

$ sudo nano /etc/mtconnect/agent.cfg

Original Path::  “Devices = ../simulator/VMC-3Axis.xml”

New Path:: “Devices = ./simulator/VMC-3Axis.xml”

Finally, the simulator is started up in a fresh screen.  The simulator blocks the process so just detach the screen using control A, D, after it is up and running.

$ screen -S simulator
$ cd /etc/mtconnect/simulator
$ ruby -v run_scenario.rb -l VMC-3Axis-Log.txt

<cntrl><a> followed by <d>


Testing the MTConnect agent is very simple.  First the agent is started using the script we created, if the script completes successfully we can make sure it is listening for incoming connections.

$ sudo service agent start
$ netstat - tcp -l

Active Internet connections (only servers)
tcp 0 0 *:7878 *:* LISTEN
tcp 0 0 *:5000 *:* LISTEN

With the default configuration the agent is listening on port 5000 and the simulator is listening on port 7878.  If these are listed in the netstat, then everything is good.   For the final confirmation, any browser can be used as client.

agent.ellisware.com:5000/ or agent.ellisware.com:5000/probe






Please let me know any mistakes, omissions or improvements in the code.  It took a great deal of patience to get this up and running, so feel free to ask any questions in the comments.


###### agent.sh #######

 # /etc/init.d/agent
 # version 0.0.1 2014-05-09 (YYYY-MM-DD)
 # Provides: agent
 # Required-Start: $local_fs $remote_fs
 # Required-Stop: $local_fs $remote_fs
 # Should-Start: $network
 # Should-Stop: $network
 # Default-Start: 2 3 4 5
 # Default-Stop: 0 1 6
 # Short-Description: MtConnect server
 # Description: Starts the MTConnect Agent server

as_user() {
if [ "$USERNAME" != "$ME" ]; then
  su - $USERNAME -c "$1"
  bash -c "$1"

mc_start() {
if netstat - tcp -l | grep -q 5000
  echo "$SERVICE is already running!"
  echo "Starting $SERVICE..."
  as_user "cd $CONFIGPATH && screen -dmS agent $INVOCATION"
  sleep 10
  if netstat - tcp -l | grep -q 5000
    echo "$SERVICE is now running."
    echo "Error! Could not start $SERVICE!"

mc_stop() {
if netstat - tcp -l | grep -q 5000
  echo "Stopping $SERVICE"
  as_user "screen -p 0 -S agent -X stuff \"^C\""
  sleep 10
  echo "$SERVICE was not running."
if netstat - tcp -l | grep -q 5000
  echo "Error! $SERVICE could not be stopped."
  echo "$SERVICE is stopped."

#Start-Stop here
case "$1" in
if netstat - tcp -l | grep -q 5000
  echo "$SERVICE is running."
  echo "$SERVICE is not running."
echo "Usage: $0 {start|stop|status|restart}"
exit 1
exit 0


Installing WordPress in Ubuntu 14.04 LTS

Installing WordPress

Assuming your LAMP is up and running we start with downloading WordPress to the home directory.  It is unzipped, modified before being moved to our /www/html/ site.

$ cd ~$ wget http://wordpress.org/latest.tar.gz
$ tar -xzvf latest.tar.gz

From the mysql shell we will create a structure WordPress can use.

$ mysql -u root –p
> CREATE DATABASE wordpress;> CREATE USER wordpress@localhost;

> SET PASSWORD FOR wordpress@localhost= PASSWORD(“password”);

> GRANT ALL PRIVILEGES ONwordpress.* TOwordpress@localhost IDENTIFIED BY 'password';


> exit;

Now that the MySQL database is ready for the WordPress installer, a few items need to be set so WordPress knows how to reach the database.  This is done in the wp-config.php file.  Make sure to set the username, password, database and security salts.

$ cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php 
$ sudo nano ~/wordpress/wp-config.php

Lets copy all the WordPress files so they are served by Apache.

$ sudo rsync –avP ~/wordpress /var/www/html/
$ cd /var/www/html$ sudo chown www-data:www-data * -R 
$ sudo usermod -a -G www-datausername

Finally, open your browser and setup WordPress!



How To Install WordPress on Debian 7



Setting up an Ubuntu 14.04 LTS Server

This blog is a reference for my current Ubuntu 14.04 setup.  I struggled to find correct information on-line especially with mysql setup.  This ensures its available in the future.  Digital Ocean servered as a great resource for the setup.


Setup a User

Add a user account for yourself. This is easy with the adduser command. Just follow the prompts to update set a password and any other information.

# adduser someuser

Since this is your account, you need to give all sudo privileges to the new account. Open up the list of sudoers with the visudo command and add your username below root with all privileges.

# visudo
   # User privilege specification
   root  ALL=(ALL:ALL) ALL
   someuser ALL=(ALL:ALL) ALL

Final switch from the root user to the sudo account you’ve created.

# su someuser


Updating packages

Several packages will be out of date and need to be updated. This is done with two commands. The update command retrieves a list of all packages and dependencies for updating purposes. Finally the

$ sudo apt-get update
$ sudo apt-get dist-upgrade


Add a Swapfile

How about adding a swapfile to decrease any chance of a memory overflow error. Use the fallocate command. The 2G is the size, 2 gigabytes. Finally check its OK using ls to confirm the size is 2GB.

$ sudo fallocate –l 2G /swapfile
$ ls –lh /swapfile

Enable the swapfile

$ sudo chmod 600 /swapfile
$ sudo mkswap /swapfile
$ sudo swapon /swapfile

The swapfile is now up and running, however, to have it permanently on the fstab file has to be edited. The swapfile is put at the bottom of the file.

$ sudo nano /etc/fstab
     /swapfile   none   swap   defaults   0   0


Install Apache Web Server

Next up the webserver apache2 is installed. After the server is installed the ServerName will need to be set to eliminate the “Could not reliably determine the server’s fully qualified domain name” nag. Finally restart apache2 to confirm the setting is correct.

$ sudo apt-get install apache2
$ sudo nano /etc/apache2/apache2.conf
      # Default ServerName
      ServerName www.mysite.com
$ sudo service apache2 restart


Install MYSQL Server

Time to setup MYSQL. Install the package and then secure it by running my_sql_install_db

$ sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql php5-gd
$ sudo mysql_install_db


Install PHP5 for Apache

Finally we need PHP in our LAMP. Once the packages are downloaded and installed, the extension .php has to be moved up the default order of extensions apache will search for when an extension is omitted. This is done by editing the dir.conf file.

$ sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
$ sudo nano /etc/apache2/mods-enabled/dir.conf
$ sudo service apache2 restart

How To Install Linux, Apache, MySQL, PHP (LAMP)stack on Ubuntu

How To Add Swap on Ubuntu 14.04