Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

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

(Step 7 - Install your application over the air)
m (Install application)
 
(114 intermediate revisions by 12 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 BeagleBoard or RaspberryPi.
+
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 and send this data on a remote server. The application should be updatable over-the-air.
+
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!
  
== Step 1 - Build Mihini ==
+
Please bear in mind that <strong>Mihini is still under development</strong>.<br/>
  
* Download the sources
+
== Step 1 - Get and/or build Mihini ==
* Cross-compile (or compile directly on the target) the Mihini runtime
+
* '''TODO''' at that stage, can we try to create a dpkg? That'd be very useful...
+
  
== Step 1 (alternative) - Get a ready-to-use "Mihini for XXX" SD card binary image ==
+
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]].
  
* Download a ready-to-use .img file and put it on the SD card used on the development board
+
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]]
  
== Step 2 - Configure network connection ==
+
== Step 2 - Configure Mihini ==
 +
If you have installed Mihini from a .deb or a .rpm, you can skip this section.
  
=== 3G connection ===
+
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.
  
* apt-get install ppp
+
The agent.deviceId can be generated from your device with the platform.lua corresponding to your platform:
* http://mycusthelp.net/SIERRAWIRELESS/_cs/AnswerDetail.aspx?sSessionID=&aid=5#Connecting_using_PPPD
+
  
=== Ethernet connection ===
+
* [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]
  
* Configure/verifiy that there is Ethernet connection as a fall-back
+
== Step 3 - Start Mihini on your device ==
  
== Step 3 - Configure Mihini ==
+
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 ===
+
=== As a service ===
  
First of all you will need prerequisites
+
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>
<code>sudo apt-get install git build-essential cmake</code>
+
Now get the sources
+
<code><pre>cd /tmp/
+
git clone ssh://host/mihini.git</pre></code>
+
  
Then there will be some configuration on <em>agent/agent/defaultconfig.lua</em>.
+
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>
* Enable the application container
+
** <code>appcon.activate = true</code> in defaultconfig.lua
+
* Enable the update manager
+
** <code>update.activate = true</code> in defaultconfig.lua
+
* OPTIONAL (but useful :)), enable Lua shell on all network interfaces by <em>adding</em>
+
** <code>shell.address = '*'</code>
+
  
Now you can choose to compile directly on your device or cross compile it then send in to your device of choice. For the following sample a RaspberryPi has been used.
+
=== Manually ===
  
==== Compiling on device ====
+
On your device, if you have built mihini on a <em>RaspberryPi</em> with user <code>pi</code>:
  
Move the repository you just cloned to your device ( in my case using ''scp'' ). Installed the prerequisites mentioned above on your device and simply run the following in the repository you just copied.
+
Firstly, you should link the librairies:
<code>
+
<pre>
+
#
+
# On raspberrypi itself
+
#
+
cd mihini/bin
+
./build.sh
+
#
+
# Compiling Lua
+
#
+
cd build.default/
+
make lua
+
</pre>
+
</code>
+
  
==== Cross compiling ====
+
<source lang="bash">
<code>
+
cd /etc/ld.so.conf.d/
<pre>
+
sudo /bin/sh -c 'echo "/home/pi/mihini/lib/" > 01-mihini.conf'
#
+
sudo ldconfig
# Cross compiling
+
</source>
#
+
  
# Get linaro toolchain
+
Then, you can start it:
cd /where/you/want/it
+
git clone https://github.com/raspberrypi/tools.git
+
  
# Define path to the arm toolchain you just downloaded
+
<source lang="bash">
cd /tmp/mihini
+
$ cd ~/mihini
vim cmake/toolchain.raspberrypi-linaro.cmake
+
$ 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 &
cd bin/
+
</source>
./build.sh -t raspberrypi-linaro
+
  
#
+
'''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.
# Compiling Lua
+
#
+
cd build.raspberrypi-linaro/
+
make lua
+
  
# Send all this on raspberrypi
 
scp -r runtime pi@yourPiIp:mihini
 
</pre>
 
</code>
 
  
 +
==== Stop Mihini manually ====
  
=== Start Mihini daemon on your device ===
+
<source lang="bash">
 
+
$ sudo killall agent appmon_daemon
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. We need to start it.
+
</source>
 
+
====Manually====
+
 
+
On your device ( here a Raspberry Pi)
+
<code><pre>$ cd mihini/bin/
+
$ sudo ./appmon_daemon -u pi -g pi && cd .. && ./start.sh
+
</pre></code>
+
'''Notice''':  we launched <code>appmon_daemon</code> with user <code>pi</code> in order to benefit from valid user rights.
+
 
+
====As a service====
+
  
 
== Step 4 - Setup Koneki environment ==
 
== Step 4 - Setup Koneki environment ==
  
* Download Lua Development Tools
+
* Download and launch [http://www.eclipse.org/koneki/ldt/#installation Lua Development Tools]
* Install "Mihini target management"
+
* Install the Mihini Development Tools
* Define your device and configure its "SSH Lua" paths like this [[Image:SshLuaConfiguration.png|center]]
+
** Help -> Install new software
** If you want the text version
+
** Work with: <code>http://download.eclipse.org/koneki/updates-nightly</code> '''NB:''' This stills a nightly build.
<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
+
** Select the "Mihini Development Tools for Lua"
LUA_CPATH: /home/pi/mihini/lib/?.so;/home/pi/mihini/lua/?.so
+
* Configure the connection to your Raspberry Pi
LD_LIBRARY_PATH: $LD_LIBRARY_PATH:/home/pi/mihini/lib</pre></code>
+
** Open the perspective "Remote System explorer"
* Configure the "Mihini execution environment" (provides nice autocompletion...)
+
** "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 ==
+
== Step 5 - Create your first application ==
  
* TODO (blink a LED, use a touch sensor, measure the temperature and available RAM of the board...)
+
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.
  
== Step 6 - Test the application ==
+
<source lang="lua">
 +
local log  = require "log"
 +
local sched = require "sched"
 +
local function main()
 +
    log("GENERAL", "INFO", "My first Mihini app is alive :)")
 +
end
  
* Configure the remote target in the Koneki environment
+
sched.run(main)
** You will need to know the IP address of the target, but you likely know it already :-)
+
sched.loop()
* Create a launch/debug configuration and test your script
+
</source>
  
= Step 7 - Install your application =
+
=== Automatically ===
  
== Over the air ==
+
To run the above example, right click on your LUA Project > Export > Mihini > Lua Application Package.
  
* Use the Koneki tools to create an application package
+
Then, you will be able to start, stop, delete and enable or disable the autostart of your application directly from LDT.
* Deploy the package on a publically available web server
+
* Connect to the Mihini console and for a connection to the testing server
+
  
== Manually ==
+
=== Manually ===
  
All you a have to do in order to enable Mihini to handle you application is:
+
==== Create a launcher ====
# Create a launcher
+
# Provide sources
+
  
=== 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:
  
Mihini ''Application container'' runs executables. To run a Lua application, we need to set some variables beforehand and then lauch ou 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:
+
<source lang="bash">
<code><pre>#!/bin/sh
+
#!/bin/sh
 +
lua main.lua
 +
</source>
  
# Setting up paths
+
Now my application folder looks like
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"
+
<source lang="bash">
export LUA_CPATH="/home/pi/mihini/lib/?.so;/home/pi/mihini/lua/?.so"
+
$ find raspapp/
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/pi/mihini/lib"
+
 
+
# Running app
+
/home/pi/mihini/bin/lua main.lua
+
</pre></code>
+
 
+
Now the my application folder looks like
+
<code><pre>$ find raspapp/
+
 
raspapp/
 
raspapp/
 
raspapp/run
 
raspapp/run
 
raspapp/main.lua
 
raspapp/main.lua
</pre></code>
+
</source>
  
=== Install application ===
+
==== Install application ====
  
It is now time to install our application. Copy you app folder on your device.
+
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.  
  
<code>scp -r raspapp/ pi@raspberry.local:/tmp</code>
+
<source lang="bash">
 +
$ telnet localhost 2000
 +
> agent.config.appcon.activate = true
 +
</source>  
  
Now that your application is available on your device, lets install it. I suppose you already an Appmon Daemon running. We are about to install an app which will be named <em>'sample'</em>, available at <em>'/tmp/raspapp'</em>, this application will benefit from <em>autostart</em> ( the last <code>true</code> parameter ).
+
Then restart your agent. <source lang="bash">
<code><pre>$ telnet localhost 2000
+
> 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 174: 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"
 
= ok
 
= ok
</pre></code>
+
</source> We can check that the application is properly installed <source lang="lua">
We can check that the application is properly installed
+
> :appcon.list()
<code><pre>
+
= { sample = { autostart = true, runnable = true } }
> for app, t in pairs(appcon.list()) do
+
</source>  
+    print( app )
+
 
+    for field, data in pairs(t) do
+
'''Notice''': <code>CTRL-D</code> to quit.
+        print('\t', field, data)
+
 
+    end
+
We can even check logs: <source lang="bash">
+ end
+
$ tail -f /var/log/syslog | grep Mihini
sample
+
</source> <!-- We may show log output. -->
                autostart       true
+
                runnable       true
+
</pre></code>
+
  
 
= 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"
 
SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ENV{ID_VENDOR_ID}=="1199", ENV{ID_MODEL_ID}=="68a3", ENV{ID_USB_INTERFACE_NUM}=="04", SYMLINK+="ttyATConsole1"
 
SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ENV{ID_VENDOR_ID}=="1199", ENV{ID_MODEL_ID}=="68a3", ENV{ID_USB_INTERFACE_NUM}=="04", SYMLINK+="ttyATConsole1"
 
</code>
 
</code>
 +
 
** 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/
* Below is a template of the defaultconfig.lua that you should use to have most of the important features (appmon, updatemanager, ...) of Mihini enabled
+
* Remove Lua comments to save some flash on very tiny devices (could probably be part of the build process by the way)
<code>TODO</code>
+
** <source lang="bash">
 +
find . -type f -name '*.lua' -print0 | xargs -0 sed -i '/^[ \t]*--/d'
 +
</source>
 +
* Strip binary code, to save flash too
 +
** <source lang="bash">
 +
find . -type f -name '*.so' -print0 | xargs -0 $STRIP_EXECUTABLE_PATH
 +
</source>

Latest revision as of 08: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

Back to the top