Here is how you would go about setting up Eclipse's M2M development environment on your Windows Computer & Raspberry Pi. This blog post can be considered as a simplified (and a little bit updated) version of "Run Mihini on an Open Hardware platform" specific to RPi/ArchLinux combination:
- Get your Raspberry Pi up and running:
- Get the latest ArchLinux SD card image for Raspberry Pi from here
- Write the image on to an SD card using either dd (if using Linux) or Win32 Disk Imager (if using Windows)
- Boot the Rasberry Pi using the newly created SD card. Make sure it is connected to your LAN (i.e. home WiFi Router) using a straight Ethernet cable. Your Windows PC should also be connected to the same LAN using WiFi or Ethernet.
- Login to your WiFi router's management web page and figure out the IP address that your router has assigned to your Raspberry Pi. In my case the Raspberry Pi's address was 10.10.10.23
Looking up RPi's IP address from the router's admin webpage - Use PuTTY (download putty.exe from here) to connect to Raspberry Pi using the IP address that you got by looking up the WiFi Router's DHCP client's list in the previous step. If PuTTY complains about the host key not being cached, then just press Yes. You will now be able to access Raspberry Pi's console over the network.
- login as: root
password: root - [OPTIONAL] Create extra partition:
- If you your SD card was more than 2GB, then you can use the extra empty space (ArchLinux image uses up only the first 2GB) to create an extra partition for your own use
- Issue the command fdisk /dev/mmcblk0 over the console (PuTTY)
- Create a new partition by pressing "n"
- Select primary partition and leave the starting and ending size to default, fdisk will automatically create a new partition to use up the remaining empty space.
- Press "w" to update the partition table and reboot the Raspberry Pi by issuing the command reboot
- This will cause PuTTY to disconnect from Raspberry Pi. Wait 30 seconds and connect to RPi again.
- Look up "the mmcblk0**" entries under /dev, you will note a new partition there: /dev/mmcblk0p3.
- Format this partition: mkfs.ext4 /dev/mmcblk0p3
- Label the partition: e2label /dev/mmcblk0p3 data
- Edit fstab to automatically mount the partition, issue the command nano /etc/fstab
and add the following line to the end of the file and save the file before exiting:
/dev/mmcblk0p3 /data ext4 defaults 1 2editing /etc/fstab - Issue the following commands in succession to mount the partition for now:
- mkdir /data
- mount /data
- Your partition is now accessible at /data
- Installing basic tools and mihini on RPi
All commands must be issued via the console accessed using PuTTY. Make sure that Raspberry Pi has access to the internet via the LAN to which it and the computer you are using are connected. - Update pacman's package lists:
pacman -Syy - Update pacman itself:
pacman -S pacman - Install essential development tools (compiler etc.):
pacman -Syu base-devel - Change directory to /data or to your home directory - where ever you want to download the mihini package from AUR
- Get the mihini tarball from ArchLinux User Repository:
wget http://aur.archlinux.org/packages/mi/mihini-git/mihini-git.tar.gz - Extract it:
tar -xvzf mihini-git.tar.gz - Enter the extracted folder: cd mihini
- Edit PKGBUILD to include the gpio module to be built along with the rest of the modules included in the mihini package: nano PKGBUILD
- Change the line make lua luac modbus_serial
to
make lua luac modbus_serial gpio
and save the file. - Build mihini (dependencies will also be downloaded):
makepkg -s --asrootCompletion of mihini build - Finalizing mihini installation:
Mihini is now installed at /opt/mihini. There are a few more steps required to complete the installation. - Edit the file ./etc/systemd/system/mihini.service by using the nano editor:
nano /etc/systemd/system/mihini.service - Change the line ExecStart=/opt/mihini/bin/appmon_daemon -a /opt/mihini/bin/agent -w /opt/mihini -u mihini -g mihini -n 5
to
ExecStart=/opt/mihini/bin/appmon_daemon -a /opt/mihini/bin/agent -w /opt/mihini -u root -g root -n 5
and save the file. - Enable mihini to start at boot up: systemctl enable mihini
- Create symbolic link to lua binary: ln -s /opt/mihini/bin/lua /usr/bin/lua
- Link the libraries, execute the following three commands in succession:
- cd /etc/ld.so.conf.d/
- /bin/sh -c 'echo "/opt/mihini/lib/" > 01-mihini.conf'
- ldconfig
- Reboot Raspberry Pi by issuing the command: reboot
- Install Eclipse & Lua Development Tools on your Windows PC:
- Download the 32-bit Windows version (org.eclipse.koneki.ldt.product-win32.win32.x86.zip) from here
- Extract it to a folder on your Windows PC and execute LuaDevelopmentTools.exe
- Select an appropriate workspace location and click OK
- From the Help menu, select "Install New Software"
- Select "http://download.eclipse.org/koneki/releases/stable" from the "Work with" dropdown menu
- Tick the checkbox against the last of the four entries: "Lua Development Tools - Koneki" and click Next
- This will install remote development support. You will be asked to restart Eclipse.
- Create connection to RPi using Eclipse:
- From the Window Menu select Open Perspective > Remote System Explorer
- Right click anywhere in the empty white region of "Remote Systems" pane on the left side and select "New Connection"
- Select "Lua SSH System" and click next.
- Enter your RPi's IP address in your Hostname field.
- Enter some name (eg "Bosco's RPi") in the name field and click Next
- Click Finish
- A new entry will be create in the "Systems Explorer" pane. Right click on it and select "connect"
- You will be asked for User ID and password. Enter "root" for both and tick the checkboxes to save them and press OK.
- For the 3 dialog boxes that pop up:
- Click Yes to add the new host to the hosts list
- Click Yes when it objects about not being able to verify the authenticity of the host.
- You can click No when it asks you to enter the master
- Switch back to Lua perspective (button on top right corner "Lua" or select from Windows>Open Perspective> Other)
Remote System Explorer View - Hello World:
- Create a new Lua Project in Eclipse: File>New>Lua Project
- Enter the project name as "MyHelloWorld" and click finish
- A new entry called "MyHelloWorld" will be created under Scripts Explorer. Expand it and open main.lua inside the src folder
- Delete the contents of main.lua and type the following in it:
package.path = '/opt/mihini/lua/?.lua;/opt/mihini/lua/?/init.lua;' .. package.path package.cpath = '/opt/mihini/lua/?.so;' .. package.cpath 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()
- Save the file (Ctrl+S)
- Now we need to run the file on RPi. To do this, bring down the Run menu and select "Run As > Lua Remote Application"
- The lua script will be uploaded to Raspberry Pi and run remotely. The results will be displayed in the console.
- Press the stop button to stop the script.
Running HelloWorld remotely on RPi
Instead of whole paragraph 3 & 4, you can:
ReplyDelete$ pacman -Syu yaourt
$ yaourt -S mihini-git
and the systemd daemon should be running ;)
(http://wiki.eclipse.org/Mihini/Install_Mihini )
There is also a way to improve the connection from LDT, but it stills a nightly build:
http://wiki.eclipse.org/Mihini/Run_Mihini_on_an_Open_Hardware_platform#Step_4_-_Setup_Koneki_environment
Thanks for your work !
I tried using yaourt, but it didnt work for me so I had to switch to AUR. Also I referred to the eclipse wiki link that you have mentioned to write up this post. I was thinking of editing the wiki to simplify, edit out and add in some parts, but being a beginner, I decided against it and wrote up my blog. I mentioned the wiki link upfront to avoid confusion.
ReplyDeleteit's sad that yaourt didnt work for you, I will try it a little more, but I understand your point :)
ReplyDeleteThanks for your feedback !
Thanks a lot for the detailed instructions. I spent 4 days with Raspbian & Mihini to make GPIO work, finally installed Arch Linux on another card and followed your instructions. Able to work with GPIO in one hr.
ReplyDeleteThanks a lot.
hi ,
ReplyDeletewhen i am trying to perform step 10.Build mihini. i am getting
makepkg: command not found
can anyone please help me out to solve this...............
Thanks for any kind of help
@Avinash These steps are for ArchLinux. Are you using ArchLinux or Raspbian? Provide some more info regarding your setup...
ReplyDeletethanks Anurag for your quick response, Actually i was using UBUNTU 13.04 version............................does mihini server has support for this ?
ReplyDeleteThese steps are only for ArchLinux... will not work for other distros. I like ArchLinux so I made it run on only that distro..
ReplyDeleteok thank you will install ARCHLINUX and follow your steps..............
ReplyDeletehi
ReplyDeletei have installed arch linux on sd card by following steps 1,2,3. when i am trying to check ip address in router i could not find it. can you please suggest some solution ?
Avinash, what router do you have? you can also connect Raspberry Pi to a TV or HDMI monitor and plugin a keyboard in it and use ifconfig command to check its ip address
ReplyDeleteHello Anurag, i did all the steps and things installed fine.. till, while running the Lua on the RPI, i get the error "Launching MyHelloWorld_main_RPI" has encountered a problem. On details , i get
ReplyDelete"An internal error occurred during: "Launching MyHelloWorld_main_RPI".
org/eclipse/koneki/ldt/core/IProjectSourceVisitor2"
Can u help pl ?
ganeshs3681@gmail.com
I'm running version 1.1 downloaded from http://www.eclipse.org/koneki/ldt/
ReplyDeletehello anurag sir,
ReplyDeletei had started mihini demon & agent successfully on ubuntu, i had also checked remote execution on koneki, with printing various path variables, remote execution working properly. Also i had copied libraries (*.lua) on desired path, but i am getting error
/usr/bin/lua: ./main.lua:7: attempt to index local 'sched' (a boolean value)
stack traceback:
./main.lua:7: in main chunk
[C]: in ?
and i am using modbus library, with one end of virtual serial port on vmware and another end on host application(modbus simulator) i am getting error
/usr/bin/lua: ./test.lua:6: attempt to index upvalue 'modbus' (a boolean value)
stack traceback:
./test.lua:6: in function 'main'
./test.lua:12: in main chunk
[C]: in ?
will be very thankful for getting some help.
Hey Samrat, sorry for the late reply. You seem to be an awesome Power User and an insightful Developer. You have a good handle on Linux and have already setup VMware with virtual serial port - have already gotten stuff to work. As with regards to Lua, I myself am a beginner and have very little experience with the language and the dev environment. From you post, if we assume that the modbus library itself doesn't have bugs, then only thing that occurs to me is the path mismatch. Look at the "package.path" in the hellow world lua program above. Maybe you need to do something similar in your modbus program?
ReplyDeleteI am sorry I couldn't be more helpful
If you manage to get it to work, do let us know the solution too.