Playing with Arduino Yun

Yes I ordered it. Now I get an Arduino Yun.

In this post I will describe my first steps playing with Yun

Price: less than $110

yun

 

Needed Hardware.

arduino-yun-en
Arduino Yun : Yeah!!!

Price: less than $90 (snootlab)

sd-microsd-memory-card-4-gb-sdhc
A Micro SD card

Price: less than $13 (snootlab)

How to configure.

As usually Arduino made a perfect tutorial to start with Yun.

But I will describe what I’m doing here:

Connecting to the network managed by Arduino Yun

When you power on the Arduino Yun, A new wifi network becomes available. This network is called ArduinoYun-XXXXXXXXXXXX.

Just connect your computer on this network then go to http://arduino.local/

Wahoo a beautiful webpage – hosted on the Arduino Yun – is displayed:

Capture d’écran 2013-10-01 à 20.32.50

Default password is arduino.

Then you can access to the configuration. Let’s configure it as described on arduino tutorial  to give access to your local network.

The Arduino Yu will now restart:

YunRebooting

Once restarted. You can connect again to your local network. Then open again the url http://arduino.local/ and input your new password.

Here you can access to the IP of your Arduino Yun on your local network:

conf

On my network IP address is 192.168.0.17

SSH the Arduino Yun.

I’m starting to try to SSH :

$ ssh root@192.168.0.17

Capture d’écran 2013-10-01 à 20.43.49

Yeah it works!

Now I’ll try some commands:

root@Arduino:~# uname -a
Linux Arduino 3.8.3 #8 Mon Aug 19 16:22:39 CEST 2013 mips GNU/Linux
root@Arduino:~# df
Filesystem           1K-blocks      Used Available Use% Mounted on
rootfs                    7680       360      7320   5% /
/dev/root                 7168      7168         0 100% /rom
tmpfs                    30568       156     30412   1% /tmp
tmpfs                      512         0       512   0% /dev
/dev/mtdblock3            7680       360      7320   5% /overlay
overlayfs:/overlay        7680       360      7320   5% /
/dev/sda1              3864064        32   3864032   0% /mnt/sda1

/dev/sda1 is my micro sd 🙂

root@Arduino:~# top
Mem: 29048K used, 32084K free, 0K shrd, 4424K buff, 10152K cached
CPU:   0% usr   2% sys   0% nic  95% idle   0% io   0% irq   0% sirq
Load average: 0.02 0.04 0.05 2/48 8136
  PID  PPID USER     STAT   VSZ %VSZ %CPU COMMAND
 7947  7021 root     R     1504   2%   1% top
  779   722 root     S     1504   2%   0% udhcpc -p /var/run/udhcpc-eth1.pid -s
 1554     1 nobody   S     2176   4%   0% avahi-daemon: running [Arduino.local]
 1526     1 root     S     1700   3%   0% /usr/sbin/dbus-daemon --system
 1150     1 root     S     1592   3%   0% wpa_supplicant -B -P /var/run/wifi-wl
 1517     1 root     S     1584   3%   0% /usr/sbin/uhttpd -f -h /www -r Arduin
  572     1 root     S     1552   3%   0% {rcS} /bin/sh /etc/init.d/rcS S boot
  722     1 root     S     1540   3%   0% /sbin/netifd
  693     1 root     S     1512   2%   0% /sbin/syslogd -C16
 1237   722 root     S     1512   2%   0% udhcpc -p /var/run/udhcpc-wlan0.pid -
 1589     1 root     S N   1508   2%   0% {uSDaemon} /bin/sh /sbin/uSDaemon
    1     0 root     S     1508   2%   0% init
 7021  6999 root     S     1508   2%   0% -ash
  573     1 root     S     1508   2%   0% init
 1580     1 root     S     1504   2%   0% /usr/sbin/ntpd -n -p 0.openwrt.pool.n
  836     1 root     S     1504   2%   0% /sbin/watchdog -t 5 /dev/watchdog
  575   572 root     S     1500   2%   0% logger -s -p 6 -t sysinit
  695     1 root     S     1496   2%   0% /sbin/klogd
 8136  1589 root     S N   1492   2%   0% sleep 2
  702     1 root     S     1288   2%   0% /sbin/procd

Cool Linux kernel works just perfectly!

Adding a web service on the Arduino.

Here is the code on the Arduino Yun

#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h> 
// All request on http://192.168.0.17/arduino/
// will be transfered here
YunServer server;
String startString;
 
void setup() {
  Serial.begin(9600);
 
  // Bridge startup
  pinMode(13,OUTPUT);
  digitalWrite(13, LOW);
  Bridge.begin();
  digitalWrite(13, HIGH);
 
  // Listen for incoming connection only from localhost
  // (no one from the external network could connect)
  server.listenOnLocalhost();
  server.begin();
 
  // get the time that this sketch started:
  Process startTime;
  startTime.runShellCommand("date");
  while(startTime.available()) {
    char c = startTime.read();
    startString += c;
  }
}
 
void loop() {
  // Get clients coming from server
  YunClient client = server.accept();
 
  // There is a new client?
  if (client) {
    // read the command
    String command = client.readString();
    command.trim();        //kill whitespace
    Serial.println(command);
    // is "temperature" command?
    if (command == "test") {
 
      // get the time from the server:
      Process time;
      time.runShellCommand("date");
      String timeString = "";
      while(time.available()) {
        char c = time.read();
        if (c !='\n') {
          timeString += c;
        }
      }
      client.print("{time:\"");
      client.print(timeString);
      client.print("\"}");
    }
 
    // Close connection and free resources.
    client.stop();
  }
 
  delay(50); // Poll every 50ms
}

As described in the code. if now I reach http://192.168.0.17/arduino/test current time of the linux kernel should be display by my browser as a JSON String:

Capture d’écran 2013-10-01 à 21.22.00

Yeah it works!

If we take a look to HTML headers :

Capture d’écran 2013-10-01 à 21.23.16#Ouch Content-Type is text/plain, not so good for JSON response but it is not a big deal.

Next: try to understand how to configure uhttpd which is the http server on the linux kernel.

Ok, it’s a good start and then

Arduino Yun is also configured for more web services

  • /arduino: redirected to arduino program
  • /sd: allow to access to static pages (html/images/js – files hosted stored on the SD Card) – You can find a good tutorial here . It works well except the fact that I needed to create manually the sd virtual link under /www
root@Arduino:# cd /www
root@Arduino:/www# ln -s  /mnt/sda1/ sd
  • /data:  is used to access to the internal key/value storage. The available calls are:
    • /put/KEY/VALUE : stores a value inside the storage
    • /get/KEY : obtains the value of the requested key in JSON
    • /get : obtains the entire storage list in JSON.
    • /delete : deletes the internal storage

Next.

Next step is to use it as a real server on my home automation system and store data on the SD card.

Stay tuned!!!

3 Comments

Leave a Comment.