Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Mihini/Run Mihini on an Open Hardware platform

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