Arduino Extended Database Library using an SD Card

The Arduino Playground Site of the Extended Database Library states that : „With these changes, it is now possible to use this library in conjunction with the standard Arduino EEPROM library, an external EEPROM such as the AT24C1024, providing 128 – 512 kilobytes of non-volatile storage, or any other platform that supports byte level reading and writing such as an SD card.“

But unfortunately I didn’t find any example in the internet that shows how to use the library with an SD Card. In the following is my version of the supplied EDB_Simple using an SD Card instead of the build-in EEPROM. For learning how to connect an SD Card Writer/Reader to an Arduino there are a lot of examples around. My Example is for an Arduino UNO with a cheap SD module hardwired to PIN 10 (Those modules do not work on the newer Arduinos). Important are the reader and writer functions and that you have to create a file and use the seek() method.

PLEASE NOTE! BEGINNING WITH ARDUINO 1.0 YOU HAVE TO CHANGE CODE IN EDB.CPP (THE LIBRARY): #include „WProgram.h“ has to be changed to #include „Arduino.h“.

#include "Arduino.h"
#include <EDB.h>
#include <SD.h>

File dbFile;

#define TABLE_SIZE 512
#define RECORDS_TO_CREATE 10

struct LogEvent {
  int id;
  int temperature;
}
logEvent;

void writer(unsigned long address, byte data)
{
  dbFile.seek(address);
  dbFile.write(data);
  dbFile.flush();
}

byte reader(unsigned long address)
{
  dbFile.seek(address);
  return dbFile.read();
}

EDB db(&writer, &reader);

void setup()
{
  Serial.begin(9600);

  Serial.print("Initializing SD card...");

  pinMode(10, OUTPUT);

  if (!SD.begin()) {
    Serial.println("initialization failed!");
    return;
  }

  Serial.println("initialization done.");

  Serial.println("Opening example.db ...");
  dbFile = SD.open("example.db", FILE_WRITE);

  db.create(0, TABLE_SIZE, sizeof(logEvent));

  Serial.print("Record Count: "); Serial.println(db.count());

  Serial.println("Creating Records...");
  int recno;
  for (recno = 1; recno <= RECORDS_TO_CREATE; recno++)
  {
    logEvent.id = recno;
    logEvent.temperature = recno * 2;
    db.appendRec(EDB_REC logEvent);
  }

  Serial.print("Record Count: "); Serial.println(db.count());
  for (recno = 1; recno < RECORDS_TO_CREATE; recno++)
  {
    db.readRec(recno, EDB_REC logEvent);
    Serial.print("ID: "); Serial.println(logEvent.id);
    Serial.print("Temp: "); Serial.println(logEvent.temperature);
  }
}

void loop()
{

}

Enable Memcached in Typo3 6.x

After the upgrade of Typo3 from version 4.7.x to 6.x a lot of things changed. I managed to make the transition quite smoothly but the memcache configuration gave me quite a headache because nothing was directly explained in the net – I had to pick through a lot of pieces to make it work, so maybe I can spare You the time.

To enable Memcached in Typo3 6.x for backend and frontend pages create a File named AdditionalConfiguration.php in the the folder typo3conf with the following content:

<?php
$GLOBALS['TYPO3_CONF_VARS']['SYS']['useCachingFramework'] = '1';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_pages']['backend'] = 'TYPO3\CMS\Core\Cache\Backend\MemcachedBackend';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_pages']['options'] = array('servers' => array('localhost:11211'),);
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_pagesection']['backend'] = 'TYPO3\CMS\Core\Cache\Backend\MemcachedBackend';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_pagesection']['options'] = array('servers' => array('localhost:11211'),);
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_hash']['backend'] = 'TYPO3\CMS\Core\Cache\Backend\MemcachedBackend';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_hash']['options'] = array('servers' => array('localhost:11211'),);
?>

Obviously change the memcached server address and port if needed.

Windows 8: Winmail and TLS

I was just configuring my Windows 8 Test-Installation on my Laptop for my e-mail account -the Standard Winmail App on the Surface. I noticed there is only a configuration option for legacy ssl and not tls – my account being setup as standard IMAP TLS and SMTP TLS, so I was wondering. Short googling revealed that just entering your server and login credentials without activation the „this server uses ssl“ hooks should result in Winmail using TLS if offered by the server.

„Lucky“ as I am hosting my e-mail and my webpages myself I can confirm this behaviour: My IMAP and SMTP services offer TLS and as I can see in the log files Winmail connects and starts the TLS session correctly and supplies the credentials after the encrypted connection is established.

Show caller id and pause MythTV on call

As of Version 0.25 MythTV has a very handy Services API (see documentation here), my first go around with the API was to use it to pause my Frontend Machine when a phone call is incoming and display the caller id on screen.

This how I have done it: I own a Snom VoIP Phone so i use the Action URL (incoming call) setting to execute a php script running on the MythTV Backend http://mythtvbackend/caller.php?caller=$caller, $caller is replaced with the caller id by the snom phone. The php script looks like this:

<?php
$caller = $_GET["caller"];

$fd = fopen( "http://192.168.100.30:6547/Frontend/SendAction?Action=PAUSE", "r" );
if (!$fd) {
    echo "Cannot open URL";
} else {
    while(!feof($fd)) {
        $buffer = fgets($fd, 4096);
        echo $buffer;
    }
    fclose( $fd );
}

$message = urlencode("Anruf von $caller");
$fd = fopen( "http://192.168.100.30:6547/Frontend/SendMessage?Message=$message", "r" );
if (!$fd) {
    echo "Cannot open URL";
} else {
    while(!feof($fd)) {
        $buffer = fgets($fd, 4096);
        echo $buffer;
    }
    fclose( $fd );
}
?>

Note that it echoes also the return of the API calls, I did that so that it is possible to debug a bit by calling the script by browser. It should be easy to cook something similar up to use as a asterisk AGI script if you don’t own a snom phone.

Creating image files from a video file in matlab

The question came up from two colleagues separately how to create  single image files from a video using matlab – either every frame or every 2nd, 5th and so on. Background is we have some cameras in the lab that produce only videos and the PIV (Particle Image Velocimetry) Software only accepts picture files.  Unfortunately there are different ways to try that in Matlab (command in opening the video file etc). This turned out to be the only reliable code snippet:

vidfile = "yourvideo.avi";
BaseName='frame_';
vid = mmreader(vidfile);

for k = 1:10:vid.NumberOfFrames
    image = read(vid,k);
    FileName=[BaseName,num2str(k),'.jpg'];
    imwrite (image,FileName);
end

If You take a look at the for loop, You will see we save every 10th picture in this example. And the pictures are saved as frame_10.jpg, frame_20.jpg …