Monday, December 30, 2013

Starting a script after the CPU Linino boot

Just add the script to the /etc/rc.local file

The stdout and stderr get redirected to a log file in /tmp (ramdisk)

My rc.local on the Arduino Yun now looks as follows:

touch /tmp/begin
sleep 5s
cd /mnt/sda1/arduino/Yafa
./ 1> /tmp/Yafa.log 2>&1 &
touch /tmp/end
exit 0

Thursday, December 26, 2013

ftp using Linino CPU and Python

I started with ftp-ing directly from the MCU using Curl.
Obviously this isn't very optimal given the Yun architecture.

I changed this so that the Linino gets the Temperature (or other measurements) from the MCU and then the Linino CPU will do the ftp-ing. Using Python this is very straightforward.

The only tricky part is that the ftp expects a file, but I don't want to put the data in a file. Luckily there exists a StringIO class that can take care of that. The code becomes something like:
import StringIO
from ftplib import FTP

myFileIO = StringIO.StringIO()

ftp.storlines("STOR dat.csv",myFileIO)

Use APPE instead of STOR if you want to append to the file.

Monday, December 23, 2013

Bridge Communication - part 5

My part4 was maybe too optimistic. It seems some people still have problems with long strings over the Bridge. A fix was found (

Until an official release do:

  • Using SSH or YunSerialTerminal, connect to the linux side of the yun.
  • Edit file /usr/bin/run-bridge, changing "python" with "python -u" (ie: add a "-u" to the command line)
  • Edit file /usr/bin/kill-bridge, again changing "python" with "python -u" (ie: add a "-u" to the command line)
  • Type kill-bridge and re-run your sketch

Good to knows - 4

Using the watchdog to reset the mcu if something goes wrong:


void setup ()
  Serial.begin (115200);
  Serial.println ("Restarted.");
  wdt_enable (WDTO_1S);  // reset after one second, if no "pat the dog" received
 }  // end of setup

void loop ()
  Serial.println ("Entered loop ...");
  wdt_reset ();  // give me another second to do stuff (pat the dog)
  while (true) ;   // oops, went into a loop
}  // end of loop

This code comes from

Obviously this can be used to trigger a restart when you detect an error (if error --> while(1){})