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.
Difference between revisions of "Mihini/Run Mihini on an Open Hardware platform"
(→Manually) |
(→As a service) |
||
(48 intermediate revisions by 4 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 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. |
+ | |||
+ | Please bear in mind that <strong>Mihini is still under development</strong>.<br/> | ||
== Step 1 - Build Mihini == | == Step 1 - 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>. Connect to you device using <code>ssh</code> and follow the steps. | + | 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. |
+ | <source lang="bash"> | ||
+ | $ ssh pi@raspberry.local | ||
+ | </source> | ||
=== Compilation prerequisites === | === Compilation prerequisites === | ||
Line 11: | Line 16: | ||
First of all, you will need some compilation tools:<br/> | First of all, you will need some compilation tools:<br/> | ||
<source lang="bash"> | <source lang="bash"> | ||
− | $ sudo apt-get install | + | $ sudo apt-get install build-essential cmake git telnet |
</source> | </source> | ||
Line 18: | Line 23: | ||
Get the sources | Get the sources | ||
<source lang="bash"> | <source lang="bash"> | ||
− | $ cd | + | $ cd |
− | $ git clone | + | $ git clone git://git.eclipse.org/gitroot/mihini/org.eclipse.mihini.git mihini-repo |
</source> | </source> | ||
=== Run the compilation === | === Run the compilation === | ||
− | 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>. | + | 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-repo/</code>. |
<source lang="bash"> | <source lang="bash"> | ||
# Compile Mihini | # Compile Mihini | ||
− | $ cd mihini | + | $ cd mihini-repo |
− | $ ./build.sh | + | $ ./bin/build.sh |
− | # Compile Lua | + | # Compile a Lua interpreter |
$ cd build.default/ | $ cd build.default/ | ||
$ make lua | $ 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 | ||
+ | $ mv runtime ~/mihini | ||
</source> | </source> | ||
=== Configure Mihini === | === Configure Mihini === | ||
− | + | Now there are some configuration items in <code>~/mihini/lua/agent/defaultconfig.lua</code> that you may optionally want to modify. | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
'''OPTIONAL (but useful :))''' | '''OPTIONAL (but useful :))''' | ||
*Enable Lua shell on all network interfaces by <em>adding</em> | *Enable Lua shell on all network interfaces by <em>adding</em> | ||
** <source lang="lua">shell.address = "*"</source> | ** <source lang="lua">shell.address = "*"</source> | ||
− | * Disable colors while logging | + | * Disable colors while logging , in order to not clutter your syslog. |
**<source lang="lua">log.enablecolors = false</source> | **<source lang="lua">log.enablecolors = false</source> | ||
Line 55: | Line 62: | ||
* How to cross compile Mihini from your Desktop machine | * How to cross compile Mihini from your Desktop machine | ||
* A <code>defaultconfig.lua</code> with the right default settings | * A <code>defaultconfig.lua</code> with the right default settings | ||
− | * A Linux package, to avoid any kind of compilation or configuration | + | * A Linux package, to avoid any kind of compilation or configuration |
+ | <!-- | ||
== Step 2 - Configure network connection == | == Step 2 - Configure network connection == | ||
Line 67: | Line 75: | ||
* <source lang="bash">$ apt-get install ppp</source> | * <source lang="bash">$ apt-get install ppp</source> | ||
* [http://mycusthelp.net/SIERRAWIRELESS/_cs/AnswerDetail.aspx?sSessionID=&aid=5#Connecting_using_PPPD Connecting using PPPD] | * [http://mycusthelp.net/SIERRAWIRELESS/_cs/AnswerDetail.aspx?sSessionID=&aid=5#Connecting_using_PPPD Connecting using PPPD] | ||
+ | --> | ||
− | == Step | + | == 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. | 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. | ||
Line 77: | Line 86: | ||
<source lang="bash"> | <source lang="bash"> | ||
− | $ cd mihini | + | $ cd ~/mihini |
− | $ sudo ./appmon_daemon -a /home/pi/mihini/start.sh -w | + | $ 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> with user <code>pi</code> | + | '''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 ==== | ||
+ | |||
+ | <source lang="bash"> | ||
+ | $ sudo killall agent | ||
+ | $ sudo killall appmon_daemon | ||
+ | </source> | ||
=== As a service === | === As a service === | ||
Soon :) | Soon :) | ||
+ | WIP lbarthelemy | ||
− | == Step | + | == Step 3 - Setup Koneki environment == |
* Download Lua Development Tools | * Download Lua Development Tools | ||
− | * Install | + | * Install [http://wiki.eclipse.org/Koneki/LDT/Developer_Area/User_Guides/User_Guide_0.9#Remote_session Remote Development Support for LDT] |
− | * Define your device and configure its <em>"SSH Lua"</em> paths like this [[Image:SshLuaConfiguration.png|center]] | + | * Configure the remote target in the Koneki environment |
− | ** If you want the text version | + | ** Define your device and configure its <em>"SSH Lua"</em> paths like this [[Image:SshLuaConfiguration.png|center]] |
+ | *** If you want the text version | ||
<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 | <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 | ||
LUA_CPATH: /home/pi/mihini/lib/?.so;/home/pi/mihini/lua/?.so | LUA_CPATH: /home/pi/mihini/lib/?.so;/home/pi/mihini/lua/?.so | ||
LD_LIBRARY_PATH: $LD_LIBRARY_PATH:/home/pi/mihini/lib</pre></code> | LD_LIBRARY_PATH: $LD_LIBRARY_PATH:/home/pi/mihini/lib</pre></code> | ||
− | * Configure the <em>"Mihini execution environment"</em> | + | * Configure the <em>"Mihini execution environment"</em> |
+ | ** Download the latest Mihini execution environment [http://download.eclipse.org/mihini/mihini-0.8.zip here] | ||
+ | ** Setup this Execution Environment in your LDT environment (Preferences > Lua > Execution Environments)) | ||
+ | * Create a launch/debug configuration and test your script. | ||
− | == Step | + | == Step 4 - 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 :). The file is <code>main.lua</code>. | ||
<source lang="lua"> | <source lang="lua"> | ||
− | + | local log = require "log" | |
− | local log = require | + | local sched = require "sched" |
− | local sched = require | + | |
local function main() | local function main() | ||
− | log( | + | log("GENERAL", "INFO", "My first Mihini app is alive :)") |
end | end | ||
Line 114: | Line 134: | ||
</source> | </source> | ||
− | + | = Step 5 - Install your application = | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
== Manually == | == Manually == | ||
Line 155: | Line 168: | ||
=== Install application === | === Install application === | ||
− | First of all, I presume you already have an [[#Step_3_-_Start_Mihini_on_your_device|Appmon Daemon running]]. We are about to install an app | + | 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 ). |
<source lang="bash">$ telnet localhost 2000 | <source lang="bash">$ telnet localhost 2000 | ||
Trying 127.0.0.1... | Trying 127.0.0.1... | ||
Line 162: | Line 175: | ||
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 | ||
</source> | </source> | ||
Line 170: | Line 184: | ||
+ print( app ) | + print( app ) | ||
+ for field, data in pairs(t) do | + for field, data in pairs(t) do | ||
− | + print( | + | + print("\t", field, data) |
+ end | + end | ||
+ end | + end | ||
Line 177: | Line 191: | ||
runnable true | runnable true | ||
</source> | </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 == | == Over the air == | ||
− | + | One day, it will be possible to install application to your remote system Mihini just from its IP, and even more: | |
* Use the Koneki tools to create an application package | * Use the Koneki tools to create an application package | ||
Line 194: | Line 215: | ||
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/ | ||
− | * | + | * Remove Lua comments to save some flash on very tiny devices (could probably be part of the build process btw) |
− | <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> |
Revision as of 14:09, 13 March 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 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.
Please bear in mind that Mihini is still under development.
Contents
Step 1 - Build Mihini
So far, all the work is being done directly on your remote system. For the following sample, pi user is being used on a RaspberryPi running Raspbian Wheezy. Connect to you device using ssh
and follow the steps.
$ ssh pi@raspberry.local
Compilation prerequisites
First of all, you will need some compilation tools:
$ sudo apt-get install build-essential cmake git telnet
Sources to compile
Get the sources
$ cd $ git clone git://git.eclipse.org/gitroot/mihini/org.eclipse.mihini.git mihini-repo
Run the compilation
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 mihini-repo/
.
# Compile Mihini $ cd mihini-repo $ ./bin/build.sh # Compile a Lua interpreter $ 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 $ mv runtime ~/mihini
Configure Mihini
Now there are some configuration items in ~/mihini/lua/agent/defaultconfig.lua
that you may optionally want to modify.
OPTIONAL (but useful :))
- Enable Lua shell on all network interfaces by adding
-
shell.address = "*"
-
- Disable colors while logging , in order to not clutter your syslog.
log.enablecolors = false
It should be easier
What is explained above is just a beginning. We are about to provide material which will speed up previous steps, such as:
- How to cross compile Mihini from your Desktop machine
- A
defaultconfig.lua
with the right default settings - A Linux package, to avoid any kind of compilation or configuration
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 Appmon
. We need to start it.
Manually
On your device, here a RaspberryPi with user pi
.
$ 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 $ sudo killall appmon_daemon
As a service
Soon :) WIP lbarthelemy
Step 3 - Setup Koneki environment
- Download Lua Development Tools
- Install Remote Development Support for LDT
- Configure the remote target in the Koneki environment
- Define your device and configure its "SSH Lua" paths like this
- If you want the text version
- Define your device and configure its "SSH Lua" paths like this
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
LUA_CPATH: /home/pi/mihini/lib/?.so;/home/pi/mihini/lua/?.so
LD_LIBRARY_PATH: $LD_LIBRARY_PATH:/home/pi/mihini/lib
- Configure the "Mihini execution environment"
- Download the latest Mihini execution environment here
- Setup this Execution Environment in your LDT environment (Preferences > Lua > Execution Environments))
- Create a launch/debug configuration and test your script.
Step 4 - 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 main.lua
.
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()
Step 5 - Install your application
Manually
All you a have to do in order to enable Mihini to handle you application is:
- Create a launcher
- Provide sources
Create a launcher
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 executable file called run
. Here is its content:
#!/bin/sh # 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
Now the my application folder looks like
$ find raspapp/ raspapp/ raspapp/run raspapp/main.lua
Install application
First of all, I presume you already have an Appmon Daemon running. You may wonder which way you can interact with Mihini. While starting, Mihini opens a Telnet
server on port 2000
, it enables you communicate with its runtime. We are about to use it 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
> for app, t in pairs(appcon.list()) do + print( app ) + for field, data in pairs(t) do + print("\t", field, data) + end + end sample autostart true runnable true
Notice: CTRL-D
to quit.
We can even check logs:
$ cat /var/log/syslog | grep Mihini
Over the air
One day, it will be possible to install application to your remote system Mihini just from its IP, and even more:
- Use the Koneki tools to create an application package
- Deploy the package on a publically available web server
- Connect to the Mihini console and for a connection to the testing server
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 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"
- 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)
-
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
-