perltutorial
ait
<h1>Warnings and disclaimers</h1>
<b>This tutorial is a work in progress.</b>There are probably omissions and/or mistakes which may ruin your hardware so I take no responsibility for any bricked Arduino boards, if your IoT Robot kills your cat and/or your house catches on fire. You have been warned.
</p>
<h1>Motivation</h1>
<p>
Wanting to promote Perl in the Embedded space where Python, MicroPython, Node.js seem to be gaining more ground every day. I decided to create my new product's Web interface with Mojolicious.</p>
<h2>Alternatives</h2>
<p>
Node.js and Python are natively supported and I could have also hacked LuCI which seems to have a pretty decent and lightweight Web MVC framework but I could not find any effective documentation on it.
</p>
<h1>Prerequisites</h1>
<p>
You will need to expand you Yśn or Yśn Shield with a few GB of space using and SD card or a pen drive (in the Yśn Shield case). I actually used a Yśn Shield on top of an Uno (the hardest path). Here is my hardware and software:
<ul>
<li> Yśn Shield running OpenWrtYun ChaosCalmer 1.6.2 r48749 (you will probably need to upgrade and flash it to get 1.6.2).</li>
<li> Arduino Uno</li>
<li>Expanded Flash: I used 8GB and this post as reference. There are some gotchas and I bricked an Uno in the process: [href:/https://forum.arduino.cc/index.php?topic=279406.0]</li>
</ul>
<p>
Feel free to post questions about getting your Arduino HW prepared for this on the comments section. Everything is easier on the Yśn board (not the shield like I used). So if you don't have your hardware yet pls. do yourself a favour and get a Yśn board, not a shield. If you already have the AVR and just want to add the Yśn shield then know that it works but expanding the memory won't be as easy, I actually bricked an Uno in the process and I have decent experience with Arduino. Everything else is mostly the same for the Yśn and the Yśn Shield.
</p>
<h1>General Procedure</h1>
<h2>Native Packages</h2>
<p>OpenWRT broke up Perl into tiny little packages so you will need to install the following list. Seems like a lot but it's mostly core Perl with a few standard modules:
<ul>
<li>perlbase-cpan</li>
<li>perlbase-unicore</li>
<li>perlbase-dynaloader</li>
<li>perlbase-term</li>
<li>perlbase-perlio</li>
<li>perlbase-if</li>
<li>perlbase-universal</li>
<li>perlbase-getopt</li>
<li>perlbase-json-pp</li>
<li>perlbase-io</li>
<li>perlbase-module</li>
<li>perlbase-data</li>
<li>perlbase-devel</li>
<li>perlbase-xsloader</li>
<li>perlbase-storable</li>
<li>perlbase-essential</li>
<li>perlbase-experimental</li>
<li>perlbase-digest</li>
<li>perlbase-encode</li>
<li>perlbase-pod</li>
<li>perlbase-unicode</li>
<li>perlbase-compress</li>
<li>perlbase-findbin</li>
<li>perlbase-test</li>
<li>gcc <-- this one is 21MB ! you can remnove after finish</li>
<li>grep</li>
</ul>
</p>
<h2>Non native Perl Modules</h2>
<p>
Only a few packages were not available but these are a pain because they require CPAN, XS, etc. <br/> BTW, gnu make is not available and the whole process requires more RAM than your device has, so you will need some swap.
</p>
<h3>Swap</h3>
<p>
I used 1GB of swap and was more than enough. <b>NOTE AND WARNING:</b> Swap on a pen drive will most likely reduce it's lifetime and probably thrash it. Use a new and/or good quality one.
</p>
<pre>
dd if=/dev/zero of=/swapfile bs=1M count=1024
chmod 0600 /swapfile
mkswap /swapfile
swapon /swapfile
</pre>
<p>
Swap will disappear if you reboot the Yśn so your need swapon again after reboot.
</p>
<h3>Upgrade Tar</h3>
<pre>
opkg upgrade tar
</pre>
<h3>Build and Install GNU Make</h3>
<p>
Yep, believe it or not, gcc is available as a native package but no make to be found which I found pretty bizarre...
</p>
<pre>
wget http://ftp.gnu.org/gnu/make/make-4.2.tar.gz
gunzip -d make-4.2.tar.gz
tar -xf make-4.2.tar
cd make-4.2
./configure
./build.sh
./make install
</pre>
<p>
You will need to add /usr/local/bin to your path for the next steps.
</p>
<pre>
export PATH=$PATH:/usr/local/bin
</pre>
<h3>Finally! Install the Non Native Packages</h3>
<pre>
curl -L https://cpanmin.us | perl - -M https://cpan.metacpan.org -n Test::Harness
curl -L https://cpanmin.us | perl - -M https://cpan.metacpan.org -n IO::Socket::IP
curl -L https://cpanmin.us | perl - -M https://cpan.metacpan.org -n Mojolicious
</pre>
<p>
That's it! It sounds like a lot but honestly if it wasn't for IO::Socket::IP which requires Test::More and the latter Storable it would have been pretty easy. I am hoping to collaborate with the OpenWRT crowd to provide some of the missing packages and make Mojolicious readily available on the Yśn platform.
</p>
<p>
In the mean time: Have fun with this humble tutorial!
</p>