Blinkenlight

Unverhoffterweise ist mir ein Blinkenlight Shield in die Hände gefallen und ich muss schon sagen, dass das ein ganz nettes Spielzeug ist.
Ich hab’ gleich einen kleinen Webservice geschrieben (hier), mit dem man Graphiken (am besten eignen sich kleine, kontrastreiche Icons und Logos) in das POV-Format umwandeln kann und hier ist das Ergebnis:

Codesnippet: php / Raspberry Pi => Fritzbox => Telefonanruf

Jaaaa, ich hab’ endlich auch einen Raspberry Pi und bin total begeistert – obwohl ich nach wie vor keine Ahnung habe was ich damit jetzt konkret anstellen soll :)
Beim rumspielen ist jetzt ein Snippet entstanden, das sich per telnet an der Fritzbox anmeldet und per AT-Befehl kurz eine Nummer anruft.

!#/usr/bin/php5
<?php

$fritzIP  = '192.168.178.1';
$pass     = 'xxxxxxxxxx';
$number   = '0173xxxxxx';
$sleep    = 10;


if ($fp = fsockopen($fritzIP, 23)) {
  $buffer = '';
  while (!feof($fp) && !preg_match('/password/', $buffer)) {
    $buffer .= fread($fp, 1);
  }
  
  fputs($fp, $pass . "\r\n");
  sleep(1);
  fputs($fp, 'echo "ATDT' . $number . '" | nc 127.0.0.1 1011' . "\r\n");
  sleep($sleep);
  fputs($fp, 'echo "ATH" | nc 127.0.0.1 1011' . "\r\n");
  sleep(1);
  
  
} else {
  echo 'Telnet connection failed ' . $fritzIP;
}

Samsung Smart Remote Control + Arduino

Props to pjnewman who has reverse engineered the Samsung remote control tcp protocol. I’ve written a Arduino function based on the perl/php scripts and it works fine with my STB-E7500. Guess it should also work with any other Samsung Smart TV or receiver.

This sketch reads a command from serial and sends it to your TV/receiver. You can try KEY_CHUP or KEY_CHDOWN for example, more commands are documented here.

/**
 * Based on:
 * http://forum.samygo.tv/viewtopic.php?f=12&t=1792
 *
 * You need the arduino base64 library:
 * https://github.com/adamvr/arduino-base64
 */

#include <SPI.h>
#include <Ethernet.h>
#include <Base64.h>

char inbuf[100];
int inbufC = 0;

byte mac[] = {  0x0E, 0x0C, 0x29, 0x3E, 0xB1, 0x4F };
IPAddress server(192,168,178,22);
EthernetClient client;

void setup() {
  Serial.begin(9600);
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    while (true) {}
  }
  Serial.println("Ready");
}

void loop() {
  if (Serial.available() > 0) {
    int inByte = Serial.read();
    if (inByte == 13) {
      inbuf[inbufC] = inByte;
      inbuf[inbufC+1] = '\0';
      inbufC = 0;
      sendCmd(inbuf);
    } else if (inbufC > 100) {
      inbufC = 0;
    } else {
      inbuf[inbufC++] = inByte;
    }
  }
}

void sendCmd(char* cmd) {
  if (client.connect(server, 55000)) {
    uint8_t part1[] = {0,1,0,102,56,0,100,0,12,0,77,84,73,51,76,106,65,117,77,67,52,120,24,0,77,71,85,116,77,71,77,116,77,106,107,116,77,50,85,116,89,106,69,116,78,71,89,61,12,0,81,88,74,107,100,87,49,118,100,71,85,61,0,1,0,102,2,0,200,0,0,1,0,102,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    char text[100];
    base64_encode(text,cmd,strlen(cmd)-1);
    part1[74+0] = 5+strlen(text);
    part1[74+5] = strlen(text);
    for (int i = 0; i<strlen(text); i++) {
      part1[74+7+i] = text[i];
    }
    client.write(part1,74+7+strlen(text));
    client.stop();
  }
}

Calunium: Atmega1284 Arduino clone

A lot of us know this issue. The Atmega328 as used by Arduino Uno has too less SRAM, the Atmega2560 as used by Aruino Mega is not availabe as a DIP package and thus not really handy for do it yourself soldering. This is where the Atmega1284 comes into play. It is available as a DIP-40 package has twice as much RAM as the 2560 and costs only about 7 EUR.

Steve Marple has developed the Arduino compatible Calunium board and shared the PCB layout as open source. Cool stuff, thank you Steve :)

I’ve ordered a couple of these boards manufactured by iteadstudio three weeks ago and they arrived yesterday. As I don’t need all of them you can have one for 5 EUR (including shipping), just drop me a message.
mailto: s{at}sui{dot}li

Introducing CRON, SUNRISE and SUNSET

This new feature allows you to trigger events at certain times. The syntax for crons is
[CRON:year,month,day,hour,minute,dayofweek:trigger], you can use an asterisk as wildcard and for example if you want to trigger an event every day at 13:15 you need to write [CRON:*,*,*,13,15,*:trigger] into the IF section of that event.

With SUNRISE and SUNSET you can trigger events at… well… sunrise and sunset :)
As sunrise and sunset times are depending on your location you need to pass your geo coordinates. For example Hamburg is located at 53.55N, 9.99E and the sunrise/sunset triggers are like [SUNRISE:53.55,9.99:trigger] and [SUNSET:53.55,9.99:trigger]

Ardumote progress

It’s been over half a year since making the first announcement of ardumote. Now I’m actually using it myself at home to open doors and switching lights :)

Here you can see my arduino which is mounted to the wall next to the door in the corridor. As you can see there are two servomotors stucked to the door opener with double-faced adhesive tape. They mechanically push the buttons. I know I could have connect them directly with optocouplers but since I live in a rented flat and didn’t want to mess things up this seemed to be the best solution.

Now let’s have a look in detail. There is also a 433MHz transmitter and receiver connected, which allows me to use a simple remote as input device and operate low cost RC power sockets. I use a arduino mega cause the RCSwitch didn’t run together with the ardumote arduino library due to memory limitations and unfortunately I don’t have much hope by now to get it working on a arduino uno ever. Nevertheless there is a example sketch without RCSwitch for uno/duemilanove provided in the lib. I’ve also connected a LM35 temperature sensor cause I had one to spare.

All the input, output and communication devices are straightforward added in the sketch:

/*

http://www.ardumote.com

    Copyright (c) 2012 Suat Özgür

http://opensource.org/licenses/MIT

    Ardumote example sketch for Mega boards

    Pin   Device
    2     433Mhz AM Receiver
    4     Servo Motor
    5     Servo Motor
    42    Status LED (Recieve)
    44    Status LED (Transmit)
    46    Status LED (IRC Connection)
    A1    433Mhz AM Transmitter
    A10   Analog temperature sensor
*/
// ==== Basic configuration =====================================

#define ARDUMOTE_CONTROLLER_ID 123
#define ARDUMOTE_SHARED_SECRET "01234567890abcdef01234567890abcd"

#define STATUS_LED_RX  42
#define STATUS_LED_TX  44
#define STATUS_LED_IRC 46

byte mac[]     = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// ==== General Includes ========================================
[Snipped... a lot of includes. Find them in the lib examples]
// ==============================================================

void setup() {

  // Init ethernet
  Ethernet.begin(mac);
  delay(1000);

  // Init ardumote itself
  ArdumoteMD5 myArdumote;
  myArdumote.setup(ARDUMOTE_CONTROLLER_ID, 
                   ARDUMOTE_SHARED_SECRET, 
                   STATUS_LED_TX, 
                   STATUS_LED_RX);

  // Init maintenance modules (Do not remove)
  SensorMaintenance s0;
  s0.setup();
  myArdumote.addSensorModule( &s0 );

  ActorMaintenance  a0;
  a0.setup();
  myArdumote.addActorModule( &a0 );

  // Init ComModules
  ComEthernetIRC c2;
  c2.setup(STATUS_LED_IRC);
  myArdumote.addComModule(&c2);

  // Init sensors
  SensorRCSwitch s1;
  s1.setup("433Mhz RX", 0); // 433Mhz AM Receiver at Pin 2
  myArdumote.addSensorModule( &s1 );

  SensorAnalog s2;
  s2.setup("Temperature", A10, 60); // LM35 Sensor Pin A10
  myArdumote.addSensorModule( &s2 );

  // Init actors
  ActorRCSwitch a1;
  a1.setup("433Mhz TX", A1); // 433Mhz AM Transmitter at Pin A1
  myArdumote.addActorModule( &a1 );

  ActorServo a2;
  a2.setup("Servo 1", 5); // Servo motor at Pin 5
  myArdumote.addActorModule( &a2 );

  ActorServo a3;
  a3.setup("Servo 2", 4); // Servo motor at Pin 4
  myArdumote.addActorModule( &a3 );

  // run
  while (true) {
    myArdumote.loop();
  }

}

void loop() {
}

There is no business logic implemented in the arduino. It’s just about receiving and sending data to a webservice (aka “the cloud™”). There is a very simple ardumote protocol on top of IRC. I’ve chosen IRC because it’s also very simple, scalable and there are lots of ready to run stable IRC daemons around to use. XMPP would have been a cooler choice but as it deals with comparatively complex XML data, the atmega chips don’t have much resources at all and dealing with string operations in C++ is really pain in the a**… maybe somewhen in future :)

Of course good old HTTP would also be an alternative but as it’s stateless you need to deal with DynDNS and router configuration stuff to allow the webservice to connect back to the arduino. With IRC the arduino connects to the webservice and keeps being connected and beside that in this way the latency is shorter and the data volume without tons of headers is much smaller.

Let’s come to the ardumote webservice.

Beside your arduino with all that sensors and actors you can also add other controller types with input and output devices. For now that is a “virtual remote panel” with “virtual button” input devices to use as a browser or smartphone interface. There is already a android app to use these virtual remote panels in a convenient way.

A “webservices controller” controls onlineservices like Twitter, E-Mail or else and I’m already planing a android phone type controller so it would be possible to use the smartphone inputs (accelerometer, GPS, compass) and outputs (action bar notification, vibration), too. Ninjablocks might also be interesting in future.

Based on your input devices you can define events and actions with your output devices to be executed when the event occurs.
In this example I have my arduino controller in the corridor, a virtual remote panel with a “Haustür” (thats german for “front door”) button and a webservices controller with my Twitter account linked to it. Whenever I push the button on my phone, the front door opens, the light in the corridor is switched on and a tweet is sent to my Twitter account.

That’s all folks… well, for now. Next steps will be some bugfixing, pimping up the virtual remote panels and enhancing the android app.

Feel free to sign up, download and play around with ardumote and share your thoughts in the forum. But keep in mind it’s still alpha and not stable yet.

JeeNodes… beautiful piece of DIY hardware.

image

Ardumote: Handy als Gamecontroller und andere Spielereien

Ihr erinnert euch an Ardumote? Auch wenn das ganze noch nicht das Beta-Stadium erreicht hat geht es doch langsam voran. Zuhause nutze ich es inzwischen sogar schon produktiv zum Licht schalten und Türen öffnen. Ursprünglich wollte ich ja nur eine Fernbedienungs-App auf dem Handy haben, inzwischen kristalisiert sich aus der Grundidee die ultimative virtuelle Schaltzentrale heraus: An dem Webinterface auf dev.ardumote.com kann man verschiedenste Arten von Geräten anmelden und je nach Zustand der Eingabegeräte (z.B. Temperatursensor oder Button auf der Handy-App) Befehle an andere (Ausgabe-)Geräte (z.B. Servomotor der den Knopf am Türsummer drückt) senden. Das ganze ist nicht mal an physikalische Geräte gebunden, man könnte auch genauso gut über einen virtuellen Ardumote-Controller einen Tweet auf Twitter absetzen (was übrigens auch schon geht).

Interessant wird das ganze dann auch mit einem Smartphone, welches ja schon von Haus aus mit einer Netzwerkverbindung ausgestattet und über und über mit Sensoren vollgestopft ist. Man könnte z.B. automatisch Schlaglöcher Twittern, die Tür abschließen wenn die Geokoordinaten der Schwiegermutter näher kommen, eine Highscore für einen Autobahnabschnitt implementieren oder ganz schnöde die Heizung aufdrehen wenn die Temperatur unter 18° sinkt…

Hier als Nebenprodukt und Proof of Concept eine Spielsteuerung mit den Bewegungssensoren eines Android Smartphones. Nicht hübsch und es fehlt jeglicher Feinschliff, aber vom Grundsatz her eine ziemlich coole Sache wie ich finde.

http://dev.ardumote.com/suat_test/JavaSocketBridge/demo3/

Hinweise:

  •  Java-Sicherheitswarnung: Das Spiel selbst läuft mit JavaScript (mit bestem Dank an gamequeryjs.com wo es aus dem Tutorial stammt), weshalb keine persistente Datenverbindung möglich wäre. Hierfür verwende ich ein Java Applet (mit bestem Dank an Stephen Ware) als Brücke zwischen JavaScript und dem IRC-Server, über den App und Spiel letzendlich miteinander kommunizieren. Die Sicherheitswarnung liegt daran, dass das Applet nicht signiert ist.
  • QR-Code oben rechts: Zum runterladen der notwendigen Android-App
  • QR-Code unten rechts: Muss mit der gerade installierten App eingescannt werden, um App und Spiel zu verbinden.

 

Request for testing / RCSwitch Release Candidate 1.3

Hi there,

I’ve refactored the RCSwitch library regarding the use of String types. All String type variables are changed to char arrays and in this way the compiled sketch (and hopefully also the memory usage) is much smaller than before. I’ve tested it with my DIP switch configured outlets and it worked fine while having a compiled size of only 5296 bytes instead of 7524 before. Also now it works more or less with Ardumote on a Duemilanove.

You can do me a favour and test it and post your result in the forum :) Especially if you are using this library with TypeC_Intertechno or TypeA_TypeB_WithRotaryOrSlidingSwitches outlets.

Download here

Thanks a lot

Suat

Ardumote

I’m proud to present what I’m currently working on: a Arduino home automation framework and a corresponding webservice. I call it Ardumote, because when I started working on this, all I wanted to have is a simple remote control app for my mobile phone.

the idea

The basic idea is to use a arduino only for operating actors, requesting sensor values and communicate all this stuff to another device. To make things flexible we have ActorModule-, SensorModule- and CommunicationModule classes with a common interface and thus said you simply attach actor objects, sensor objects and communication objects to your Ardumote instance which handles everything in this manner:

//pseudocode
loop {
  if (command available from any communication module) {
    process command / operate specified actor;
  }
  if (value available from any sensor module) {
      send value to all attached communication modules;
  }
}

The communication protocol is kept human readable and very simple. You can find more details at wiki.ardumote.com

The “other device” could be a application on your computer/smartphone using the (bluetooth) serial communication module, a webapplication on your home or remote webserver or – what I personally focus on – a webservice at dev.ardumote.com using the ethernet IRC module.

What is ready for now:

  • The basic ardumote library using plaintext (recommended for Duemilanove/Uno) or md5 (recommended for Mega) authentification
  • A analog and a digital sensor module -> just read a analog/digital pin in a defined interval, useful for LDR or LM35 temperature sensors for example
  • A analog (PWM) and digital actor module -> just write a analog/digital pin, useful for switching LEDs for example
  • A RCSwitch actor module -> just a wrapper for the RCSwitch library to operate RC power sockets, only works on Arduino Mega
  • A serial communication module -> test & debug in serial monitor, useful for eventually processing or android apps via bluetooth
  • A ethernet IRC communication module -> connects to dev.ardumote.com
  • A ugly basic web interface at dev.ardumote.com giving the ability to register a Ardumote controller, operate actors and log sensor values.
    This is what it looks like:

What I want to have in near future is:

  • Refactoring to minimize the RAM consumption (hope to get the RCSwitch module running on a Duemilanove/Uno)
  • A RCSwitch sensor module -> use a simple remote control
  • Set event based actions at the webservice -> if (LDR < threshold) { switch on lights; }
  • A fancy web interface with the possibility to compose customized fancy remote control interfaces
  • A Android app to use the fancy remote control interfaces :)

Quickstart if you want to try the pre alpha (ethernet shield needed):

  • Get yourself the RCSwitch and Time libraries
  • Sign up at dev.ardumote.com, login and add a new Ardumote controller.
  • Get the library
  • Take the example sketch which comes along with the library, change the following lines according to the Ardumote controller you’ve created in step 1 and your local network settings:
    #define ARDUMOTE_CONTROLLER_ID 11
    #define ARDUMOTE_SHARED_SECRET "2d520b8f5ea2cf6113a578f57b45201c"
    
    byte mac[]     = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    byte ip[]      = { 192,168,0,11 };
    

    Btw: As the arduino connects via IRC and keeps being connected, there is no need to setup anything on your router :)

  • Plug in a ethernet shield, a LED to pin #5 and pin #6, plug in a analog sensor to analog pin #0
  • Upload and wait until the LED at pin #13 switchs on (which indicates that the Arduino is connected to the IRC server)
  • Now you should be able to control the LEDs at the dev.ardumote.com webinterface

Feel free to share your toughts in the project forum (no registration required)