Jump to: navigation, search

Difference between revisions of "Mihini/Run Mihini on an Open Hardware platform"

(It should be easier)
m (Install application)
 
(46 intermediate revisions by 10 users not shown)
Line 1: Line 1:
 
This page describes a scenario for illustrating the use of Mihini on an Open Hardware Linux-based platform such as <em>BeagleBoard</em> or <em>RaspberryPi</em>.
 
This page describes a scenario for illustrating the use of Mihini on an Open Hardware Linux-based platform such as <em>BeagleBoard</em> or <em>RaspberryPi</em>.
  
The goal would be for someone to be able to be only one hour away from taking a bare development board and have it configured to collect data out of the GPIO sensors.
+
The goal is to allow someone to take a bare development board and configured it to collect data from the GPIO sensors. All this within an hour!
  
 
Please bear in mind that <strong>Mihini is still under development</strong>.<br/>
 
Please bear in mind that <strong>Mihini is still under development</strong>.<br/>
  
== Step 1 - Build Mihini ==
+
== Step 1 - Get and/or build Mihini ==
  
So far, all the work is being done directly on your remote system. For the following sample, <em>pi</em> user is being used on a <em>RaspberryPi</em> running <em>Raspbian Wheezy</em>. Connect to you device using <code>ssh</code> and follow the steps.
+
Mihini sources are available from their [http://git.eclipse.org/c/mihini/org.eclipse.mihini.git Git repository], as well as [[Mihini/Install_Mihini | packaged for the most common Linux distributions]].
<source lang="bash">
+
$ ssh pi@raspberry.local
+
</source>
+
  
=== Compilation prerequisites ===
+
To build Mihini, you have 4 options :
 +
*[[Mihini/Mihini_Agent_Linux_build_instructions | Build Mihini for your local system ]]
 +
*[[Mihini/Build Mihini|Build Mihini on a remote system ]]
 +
*[[Mihini/Cross Compilation|Cross Compilation: build Mihini on your local system for a remote system ]]
 +
*[[Mihini/Install_Mihini|Install Mihini using existing Linux distribution packages]]
  
First of all, you will need some compilation tools:<br/>
+
== Step 2 - Configure Mihini ==
<source lang="bash">
+
If you have installed Mihini from a .deb or a .rpm, you can skip this section.
$ sudo apt-get install build-essential cmake git telnet
+
</source>
+
  
=== Sources to compile ===
+
You may want to use directly this [https://github.com/nim65s/mihini-repo/blob/CPack/porting/raspberrypi-linaro/agent/defaultconfig.lua defaultconfig.lua] in <code>mihini/lua/agent/</code> ; but you can also read the comments in this file to get your own configuration.
  
Get the sources
+
The agent.deviceId can be generated from your device with the platform.lua corresponding to your platform:
<source lang="bash">
+
$ cd
+
$ git clone git://git.eclipse.org/gitroot/mihini/org.eclipse.mihini.git mihini-repo
+
</source>
+
  
=== Run the compilation ===
+
* [https://github.com/nim65s/mihini-repo/blob/CPack/porting/raspberrypi-linaro/agent/platform.lua Raspberry Pi]
 +
* [https://github.com/nim65s/mihini-repo/blob/CPack/porting/beaglebone/agent/platform.lua BeagleBone]
  
Lets move into the repository you just cloned. Make sure you have all prerequisites mentioned above installed. Now, simply run the following in the repository you just cloned, here called <code>mihini/</code>.
+
== Step 3 - Start Mihini on your device ==
  
<source lang="bash">
+
One of the features of Mihini is to manage the life cycle of your application. In order to do so, applications are run from another program: the <code>Appmon</code>. We need to start it.
# Compile Mihini
+
$ cd mihini-repo
+
$ ./bin/build.sh
+
  
# Compile a Lua interpreter
+
=== As a service ===
$ cd build.default/
+
$ make lua
+
# Optional, if you want to use Modbus over serial (e.g. to run the Greenhouse sample)
+
$ make modbus_serial
+
  
# Move the result of the build in your HOME
+
If you have installed Mihini from a <code>.deb</code>, you have an init script to just do what you want to: <code>/etc/init.d/mihini {start|stop|restart|status|purge}</code>
$ mv runtime ~/mihini
+
</source>
+
  
=== Configure Mihini ===
+
Or if you have installed Mihini from a <code>.rpm</code> or the AUR (ArchLinux User Repository), you can use <code>systemctl {start|stop|restart|enable|disable} mihini</code>
  
Now there are some configuration items in <code>~/mihini/lua/agent/defaultconfig.lua</code> that you may optionally want to modify.
+
=== Manually ===
  
'''OPTIONAL (but useful :))'''
+
On your device, if you have built mihini on a <em>RaspberryPi</em> with user <code>pi</code>:
*Enable Lua shell on all network interfaces by <em>adding</em>
+
** <source lang="lua">shell.address = "*"</source>
+
* Disable colors while logging , in order to not clutter your syslog.
+
**<source lang="lua">log.enablecolors = false</source>
+
  
=== It should be easier  ===
+
Firstly, you should link the librairies:
  
What is explained above is just a beginning. We are about to provide material which will speed up previous steps, such as:
+
<source lang="bash">
 +
cd /etc/ld.so.conf.d/
 +
sudo /bin/sh -c 'echo "/home/pi/mihini/lib/" > 01-mihini.conf'
 +
sudo ldconfig
 +
</source>
  
* How to cross compile Mihini from your Desktop machine
+
Then, you can start it:
* A <code>defaultconfig.lua</code> with the right default settings
+
* A Linux package, to avoid any kind of compilation or configuration
+
 
+
<!--
+
== Step 2 - Configure network connection ==
+
 
+
=== Ethernet connection ===
+
 
+
* Configure/verifiy that there is Ethernet connection as a fall-back
+
 
+
=== 3G connection ===
+
 
+
* <source lang="bash">$ apt-get install ppp</source>
+
* [http://mycusthelp.net/SIERRAWIRELESS/_cs/AnswerDetail.aspx?sSessionID=&aid=5#Connecting_using_PPPD Connecting using PPPD]
+
-->
+
 
+
== Step 2 - Start Mihini on your device ==
+
 
+
One of the features of Mihini is to manage the life cycle of your application. In order to do so, applications are run from another program: the <code>Appmon</code>. We need to start it.
+
 
+
=== Manually ===
+
 
+
On your device, here a <em>RaspberryPi</em> with user <code>pi</code>.
+
  
 
<source lang="bash">
 
<source lang="bash">
 
$ cd  ~/mihini
 
$ cd  ~/mihini
$ sudo ./bin/appmon_daemon -a /home/pi/mihini/start.sh -w /home/pi/mihini -u pi -g pi -n 5 2>&1 | logger -t Mihini
+
$ sudo ./bin/appmon_daemon -a /home/pi/mihini/start.sh -w /home/pi/mihini -u pi -g pi -n 5 2>&1 | logger -t Mihini &
 
</source>
 
</source>
  
 
'''Notice''':  we launched <code>appmon_daemon</code> and <code>mihini</code> with <code>root</code> user rights, and applications managed by <code>appmon_daemon</code> will be launched using user <code>pi</code> that should give sufficient user rights for most of needs.
 
'''Notice''':  we launched <code>appmon_daemon</code> and <code>mihini</code> with <code>root</code> user rights, and applications managed by <code>appmon_daemon</code> will be launched using user <code>pi</code> that should give sufficient user rights for most of needs.
 +
  
 
==== Stop Mihini manually ====
 
==== Stop Mihini manually ====
  
 
<source lang="bash">
 
<source lang="bash">
$ sudo killall agent
+
$ sudo killall agent appmon_daemon
$ sudo killall appmon_daemon
+
 
</source>
 
</source>
  
=== As a service ===
+
== Step 4 - Setup Koneki environment ==
 
+
Soon :)
+
 
+
== Step 3 - Setup Koneki environment ==
+
  
* Download Lua Development Tools
+
* Download and launch [http://www.eclipse.org/koneki/ldt/#installation Lua Development Tools]
* Install [http://wiki.eclipse.org/Koneki/LDT/Developer_Area/User_Guides/User_Guide_0.9#Remote_session Remote Development Support for LDT]  
+
* Install the Mihini Development Tools
* Configure the remote target in the Koneki environment
+
** Help -> Install new software
** Define your device and configure its <em>"SSH Lua"</em> paths like this [[Image:SshLuaConfiguration.png|center]]
+
** Work with: <code>http://download.eclipse.org/koneki/updates-nightly</code> '''NB:''' This stills a nightly build.
*** If you want the text version
+
** Select the "Mihini Development Tools for Lua"
<code><pre>LUA_PATH: /home/pi/mihini/lib/?.lua;/home/pi/mihini/lib/?/init.lua;/home/pi/mihini/lua/?.lua;/home/pi/mihini/lua/?/init.lua;./?.lua
+
* Configure the connection to your Raspberry Pi
LUA_CPATH: /home/pi/mihini/lib/?.so;/home/pi/mihini/lua/?.so
+
** Open the perspective "Remote System explorer"
LD_LIBRARY_PATH: $LD_LIBRARY_PATH:/home/pi/mihini/lib</pre></code>
+
** "Define a connection to remote system" -> "Mihini Device"
* Configure the <em>"Mihini execution environment"</em> (coming soon, will provide nice autocompletion...)
+
** Fill the "Host name" with your Raspberry Pi's IP address, and "Finish"
* Create a launch/debug configuration and test your script.
+
** Right clic on "Applications", then "Connect…", and fill your credential
  
== Step 4 - Create your first application ==
+
== Step 5 - Create your first application ==
  
You could blink a LED, use a touch sensor, measure the temperature and available RAM of the board... I decided to keep it simple in this tutorial, my application will simply log :). The file is <code>main.lua</code>.
+
You could blink a LED, use a touch sensor, measure the temperature and available RAM of the board... I decided to keep it simple in this tutorial, my application will simply log&nbsp;:). The file is the <code>main.lua</code> from a new LUA Project.  
  
 
<source lang="lua">
 
<source lang="lua">
Line 129: Line 89:
 
sched.run(main)
 
sched.run(main)
 
sched.loop()
 
sched.loop()
</source>
+
</source>  
  
= Step 5 - Install your application =
+
=== Automatically ===
  
== Manually ==
+
To run the above example, right click on your LUA Project > Export > Mihini > Lua Application Package.
  
All you a have to do in order to enable Mihini to handle you application is:
+
Then, you will be able to start, stop, delete and enable or disable the autostart of your application directly from LDT.
# Create a launcher
+
# Provide sources
+
  
=== Create a launcher ===
+
=== Manually ===
  
Mihini ''Application container'' runs executables. To run a Lua application, we need to set some variables beforehand and then lauch your application. In order to do so lets create the proper launcher. In the Mihini world, it is an <em>executable file called <code>run</code></em>. Here is its content:
+
==== Create a launcher ====
 +
 
 +
Mihini ''Application container'' runs executables. To run a Lua application, we need to create a launcher. In the Mihini world, it is an <em>executable file called <code>run</code></em>. Here is its content:
  
 
<source lang="bash">
 
<source lang="bash">
 
#!/bin/sh
 
#!/bin/sh
 
+
lua main.lua
# Setting up paths
+
export LUA_PATH="/home/pi/mihini/lib/?.lua;/home/pi/mihini/lib/?/init.lua;/home/pi/mihini/lua/?.lua;/home/pi/mihini/lua/?/init.lua;./?.lua"
+
export LUA_CPATH="/home/pi/mihini/lib/?.so;/home/pi/mihini/lua/?.so"
+
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/pi/mihini/lib"
+
 
+
# Running app
+
/home/pi/mihini/bin/lua main.lua
+
 
</source>
 
</source>
  
Now the my application folder looks like
+
Now my application folder looks like
 
<source lang="bash">
 
<source lang="bash">
 
$ find raspapp/
 
$ find raspapp/
Line 163: Line 116:
 
</source>
 
</source>
  
=== Install application ===
+
==== Install application ====
  
First of all, I presume you already have an [[#Step_3_-_Start_Mihini_on_your_device|Appmon Daemon running]]. You may wonder which way you can interact with Mihini. While starting, Mihini opens a <code>Telnet</code> server on port <code>2000</code>, it enables you communicate with its runtime. We are about to use it to install an app available at <em>'/tmp/raspapp'</em>, which will be named <em>'sample'</em>, this application will benefit from <em>autostart</em> ( the last <code>true</code> parameter ).
+
First of all, you should be sure that the [http://download.eclipse.org/mihini/doc/agent/Appmon_Daemon.html AppMon Daemon] is running on your device. Secondly, be sure that the appcon is activated. While starting, Mihini opens a <code>Telnet</code> server on port <code>2000</code>, it enables you communicate with its runtime. We are about to use it for activating the appcon and then install an application.
<source lang="bash">$ telnet localhost 2000
+
 
 +
<source lang="bash">
 +
$ telnet localhost 2000
 +
> agent.config.appcon.activate = true
 +
</source>
 +
 
 +
Then restart your agent. <source lang="bash">
 +
> os.exit(1)
 +
## if appmon_deamon is monitoring the agent, it will restart it automatically within seconds
 +
## if not, then launch the agent manually
 +
$ ./runtime/start.sh
 +
</source>
 +
 
 +
Now, We are about to install an app available at '''/tmp/raspapp''', which will be named '''sample''', this application will benefit from ''autostart'' ( the last <code>true</code> parameter ). <source lang="bash">$ telnet localhost 2000
 
Trying 127.0.0.1...
 
Trying 127.0.0.1...
 
Connected to localhost.
 
Connected to localhost.
Line 172: Line 138:
 
Lua interactive shell
 
Lua interactive shell
 
> appcon = require 'agent.appcon'
 
> appcon = require 'agent.appcon'
> = appcon.install('sample', '/tmp/raspapp', true)
+
> appcon.install('sample', '/tmp/raspapp', true)
 
2013-01-22 13:33:45 APPCON-INFO: Installing application "sample"
 
2013-01-22 13:33:45 APPCON-INFO: Installing application "sample"
 
= ok
 
= ok
</source>
+
</source> We can check that the application is properly installed <source lang="lua">
We can check that the application is properly installed
+
> :appcon.list()
<source lang="lua">
+
= { sample = { autostart = true, runnable = true } }
> for app, t in pairs(appcon.list()) do
+
</source>  
+    print( app )
+
+    for field, data in pairs(t) do
+
+        print("\t", field, data)
+
+    end
+
+ end
+
sample
+
                autostart       true
+
                runnable       true
+
</source>
+
'''Notice''': <code>CTRL-D</code> to quit.
+
 
+
We can even check logs:
+
<source lang="bash">
+
$ cat /var/log/syslog | grep Mihini
+
</source>
+
<!-- We may show log output. -->
+
 
+
== Over the air ==
+
  
One day, it will be possible to install application to your remote system Mihini just from its IP, and even more:
+
'''Notice''': <code>CTRL-D</code> to quit.
  
* Use the Koneki tools to create an application package
+
We can even check logs: <source lang="bash">
* Deploy the package on a publically available web server
+
$ tail -f /var/log/syslog | grep Mihini
* Connect to the Mihini console and for a connection to the testing server
+
</source> <!-- We may show log output. -->
  
 
= MISC. TIP & TRICKS =
 
= MISC. TIP & TRICKS =
  
 
* You may want to have udev rules so as your USB devices (typically the 3G stick) does not end up having an always changing /dev/ttyUSB<something> file descriptor...
 
* You may want to have udev rules so as your USB devices (typically the 3G stick) does not end up having an always changing /dev/ttyUSB<something> file descriptor...
** For a Sierra 3G stick, create a 99-aircard.rules in /etc/udev/rules.d, with the following rules (your ID_VENDOR_ID and ID_MODEL_ID may be different):
+
** For a Sierra Wireless 3G stick, create a 99-aircard.rules in /etc/udev/rules.d, with the following rules (your ID_VENDOR_ID and ID_MODEL_ID may be different):
 
<code>
 
<code>
 
SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ENV{ID_VENDOR_ID}=="1199", ENV{ID_MODEL_ID}=="68a3", ENV{ID_USB_INTERFACE_NUM}=="03", SYMLINK+="ttyATConsole0"
 
SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ENV{ID_VENDOR_ID}=="1199", ENV{ID_MODEL_ID}=="68a3", ENV{ID_USB_INTERFACE_NUM}=="03", SYMLINK+="ttyATConsole0"
Line 214: Line 162:
  
 
** For a serial-USB adapter: http://hintshop.ludvig.co.nz/show/persistent-names-usb-serial-devices/
 
** For a serial-USB adapter: http://hintshop.ludvig.co.nz/show/persistent-names-usb-serial-devices/
* Remove Lua comments to save some flash on very tiny devices (could probably be part of the build process btw)
+
* Remove Lua comments to save some flash on very tiny devices (could probably be part of the build process by the way)
 
** <source lang="bash">
 
** <source lang="bash">
 
find . -type f -name '*.lua' -print0 | xargs -0 sed -i '/^[ \t]*--/d'
 
find . -type f -name '*.lua' -print0 | xargs -0 sed -i '/^[ \t]*--/d'

Latest revision as of 07:46, 18 September 2013

This page describes a scenario for illustrating the use of Mihini on an Open Hardware Linux-based platform such as BeagleBoard or RaspberryPi.

The goal is to allow someone to take a bare development board and configured it to collect data from the GPIO sensors. All this within an hour!

Please bear in mind that Mihini is still under development.

Step 1 - Get and/or build Mihini

Mihini sources are available from their Git repository, as well as packaged for the most common Linux distributions.

To build Mihini, you have 4 options :

Step 2 - Configure Mihini

If you have installed Mihini from a .deb or a .rpm, you can skip this section.

You may want to use directly this defaultconfig.lua in mihini/lua/agent/ ; but you can also read the comments in this file to get your own configuration.

The agent.deviceId can be generated from your device with the platform.lua corresponding to your platform:

Step 3 - Start Mihini on your device

One of the features of Mihini is to manage the life cycle of your application. In order to do so, applications are run from another program: the Appmon. We need to start it.

As a service

If you have installed Mihini from a .deb, you have an init script to just do what you want to: /etc/init.d/mihini {start|stop|restart|status|purge}

Or if you have installed Mihini from a .rpm or the AUR (ArchLinux User Repository), you can use systemctl {start|stop|restart|enable|disable} mihini

Manually

On your device, if you have built mihini on a RaspberryPi with user pi:

Firstly, you should link the librairies:

cd /etc/ld.so.conf.d/
sudo /bin/sh -c 'echo "/home/pi/mihini/lib/" > 01-mihini.conf'
sudo ldconfig

Then, you can start it:

$ cd  ~/mihini
$ sudo ./bin/appmon_daemon -a /home/pi/mihini/start.sh -w /home/pi/mihini -u pi -g pi -n 5 2>&1 | logger -t Mihini &

Notice: we launched appmon_daemon and mihini with root user rights, and applications managed by appmon_daemon will be launched using user pi that should give sufficient user rights for most of needs.


Stop Mihini manually

$ sudo killall agent appmon_daemon

Step 4 - Setup Koneki environment

  • Download and launch Lua Development Tools
  • Install the Mihini Development Tools
  • Configure the connection to your Raspberry Pi
    • Open the perspective "Remote System explorer"
    • "Define a connection to remote system" -> "Mihini Device"
    • Fill the "Host name" with your Raspberry Pi's IP address, and "Finish"
    • Right clic on "Applications", then "Connect…", and fill your credential

Step 5 - Create your first application

You could blink a LED, use a touch sensor, measure the temperature and available RAM of the board... I decided to keep it simple in this tutorial, my application will simply log :). The file is the main.lua from a new LUA Project.

local log   = require "log"
local sched = require "sched"
local function main()
    log("GENERAL", "INFO", "My first Mihini app is alive :)")
end
 
sched.run(main)
sched.loop()

Automatically

To run the above example, right click on your LUA Project > Export > Mihini > Lua Application Package.

Then, you will be able to start, stop, delete and enable or disable the autostart of your application directly from LDT.

Manually

Create a launcher

Mihini Application container runs executables. To run a Lua application, we need to create a launcher. In the Mihini world, it is an executable file called run. Here is its content:

#!/bin/sh
lua main.lua

Now my application folder looks like

$ find raspapp/
raspapp/
raspapp/run
raspapp/main.lua

Install application

First of all, you should be sure that the AppMon Daemon is running on your device. Secondly, be sure that the appcon is activated. While starting, Mihini opens a Telnet server on port 2000, it enables you communicate with its runtime. We are about to use it for activating the appcon and then install an application.

$ telnet localhost 2000
> agent.config.appcon.activate = true
Then restart your agent.
> os.exit(1)
## if appmon_deamon is monitoring the agent, it will restart it automatically within seconds
## if not, then launch the agent manually
$ ./runtime/start.sh
Now, We are about to install an app available at /tmp/raspapp, which will be named sample, this application will benefit from autostart ( the last true parameter ).
$ telnet localhost 2000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Lua interactive shell
> appcon = require 'agent.appcon'
> appcon.install('sample', '/tmp/raspapp', true)
2013-01-22 13:33:45 APPCON-INFO: Installing application "sample"
= ok
We can check that the application is properly installed
> :appcon.list()
= { sample = { autostart = true, runnable = true } }

Notice: CTRL-D to quit.

We can even check logs:
$ tail -f /var/log/syslog | grep Mihini

MISC. TIP & TRICKS

  • You may want to have udev rules so as your USB devices (typically the 3G stick) does not end up having an always changing /dev/ttyUSB<something> file descriptor...
    • For a Sierra Wireless 3G stick, create a 99-aircard.rules in /etc/udev/rules.d, with the following rules (your ID_VENDOR_ID and ID_MODEL_ID may be different):

SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ENV{ID_VENDOR_ID}=="1199", ENV{ID_MODEL_ID}=="68a3", ENV{ID_USB_INTERFACE_NUM}=="03", SYMLINK+="ttyATConsole0" SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ENV{ID_VENDOR_ID}=="1199", ENV{ID_MODEL_ID}=="68a3", ENV{ID_USB_INTERFACE_NUM}=="04", SYMLINK+="ttyATConsole1"

  • Remove Lua comments to save some flash on very tiny devices (could probably be part of the build process by the way)
    • find . -type f -name '*.lua' -print0 | xargs -0 sed -i '/^[ \t]*--/d'
  • Strip binary code, to save flash too
    •  find . -type f -name '*.so' -print0 | xargs -0 $STRIP_EXECUTABLE_PATH