Beim Herumexperimentieren mit der RCSwitch-Library hier um die Definition für FHEM zu finden.

image

NanoCUL mit CC1101, Blog, FHEMduino, CUL-Emulator, FHEM-Übersicht

image

 

ist mir bei der  Empfags-Demo aufgefallen, dass die Zeile

  if (mySwitch.available()) 

nie True wurde.

Ursache war , dass in den Beispielen immer ein Arduino UNO benutzt wurde.

Bei mir kam ein Arduino Leonardo zum Einsatz!

  mySwitch.enableReceive(1);  // Receiver on interrupt 1 on leonardo(!) (not 0 as on UNO)  => that is pin #2#

Und siehe da:

http://www.arduino.cc/en/Reference/attachInterrupt

    https://code.google.com/p/arduino/issues/detail?id=714

This is valid for Leonardo :
    Int0 on D3,
    Int1 on D2,
    Int2 on D0,
    Int3 on D1
    http://arduino.cc/en/Reference/attachInterrupt shows pin 7 as interrupt 4 for the Leonardo (one of 5 hardware interrupts).  But    http://www.atmel.com/Images/7766s.pdf shows int.6. for port-pin E-6.  And the above shows just 4 interrupts...
    Documentations needs clarifying as to what hardware interrupts the Leonardo has, on what interrupt numbers. 
   
   See  Raw-Data:
    http://test.sui.li/oszi/

 

image

Insgesamt 32 Takte mit 12 Daten.

9448,272,940,280,940,276,940,276,940,276,944,276,940,276,944,272,940,276,944,272,944,276,940,276,940,276,940,888,332,276,944,884,336,272,944,884,336,276,940,888,332,276,940,276,944,272,944,884,336,

image

Hauscode: “11111”  , scheint bei den Pollin Steckdosen invertiert zu sein, also “00000” (siehe auch  hier)

DeviceId:      01111

Hier ein Beispiel-Output. (die Raw-Data-Werte in obige Webseite pasten.)

Setup done....
Received 1361 / 24bit Protocol: 1
Decimal: 1361 (24Bit) Binary: 000000000000010101010001 Tri-State: 000000FFFF0F ¨ C
Ä ¨ PulseLength: 304 microseconds Protocol: 1
Raw data: 9448,276,944,276,940,276,940,276,940,280,936,280,936,280,940,276,940,276,944,272,940,276,944,276,936,280,940,884,336,276,936,888,332,280,940,884,332,280,940,888,328,280,940,276,940,276,940,888,332,

Here is my code for Leonardo:

 

/*
  Simple example for receiving, here as Leonardo Version
  See Interrupt for D3,D2 !
  
  http://code.google.com/p/rc-switch/

    https://code.google.com/p/arduino/issues/detail?id=714
    Int0 on D3, 
    Int1 on D2, 
    Int2 on D0, 
    Int3 on D1
    http://arduino.cc/en/Reference/attachInterrupt shows pin 7 as interrupt 4 for the Leonardo (one of 5 hardware interrupts).  
But http://www.atmel.com/Images/7766s.pdf shows int.6. for port-pin E-6.  And the above shows just 4 interrupts...
    Documentations needs clarifying as to what hardware interrupts the Leonardo has, on what interrupt numbers.  
    
    Raw-Data:
    http://test.sui.li/oszi/

*/

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();


int ledPin = 9;                 // LED connected to digital pin 13
int onboard_led = 13;
//------------------------------------------------------------
void blink()
{   digitalWrite(ledPin, HIGH);   // sets the LED on   delay(50); // waits for a second   digitalWrite(ledPin, LOW);    // sets the LED off   delay(50);  // waits for a second
}
//------------------------------------------------------------
void blink_system()
{   digitalWrite(onboard_led, HIGH);   // sets the LED on   delay(50); // waits for a second   digitalWrite(onboard_led, LOW);    // sets the LED off   delay(50); // waits for a second
}
//------------------------------------------------------------
static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength)
{   static char bin[64];   unsigned int i=0;   while (Dec > 0)   {     bin[32+i++] = (Dec & 1 > 0) ? '1' : '0';     Dec = Dec >> 1;   }   for (unsigned int j = 0; j< bitLength; j++)   {     if (j >= bitLength - i)     {       bin[j] = bin[ 31 + i - (j - (bitLength - i)) ];     }     else     {       bin[j] = '0';     }   }   bin[bitLength] = '\0';      return bin;
}
//------------------------------------------------------------
void output(unsigned long decimal, unsigned int length, unsigned int delay, unsigned int* raw, unsigned int protocol) 
{   if (decimal == 0)   {     Serial.print("Unknown encoding.");   } else {     char* b = dec2binWzerofill(decimal, length);     Serial.print("Decimal: ");     Serial.print(decimal);     Serial.print(" (");     Serial.print( length );     Serial.print("Bit) Binary: ");     Serial.print( b );     Serial.print(" Tri-State: ");     Serial.print( bin2tristate( b) );     Serial.print(" PulseLength: ");     Serial.print(delay);     Serial.print(" microseconds");     Serial.print(" Protocol: ");     Serial.println(protocol);   }      Serial.print("Raw data: ");   for (int i=0; i<= length*2; i++) {     Serial.print(raw[i]);     Serial.print(",");   }   Serial.println();   Serial.println();
}

//------------------------------------------------------------
static char* bin2tristate(char* bin) {   char returnValue[50];   int pos = 0;   int pos2 = 0;   while (bin[pos]!='\0' && bin[pos+1]!='\0') {     if (bin[pos]=='0' && bin[pos+1]=='0') {       returnValue[pos2] = '0';     } else if (bin[pos]=='1' && bin[pos+1]=='1') {       returnValue[pos2] = '1';     } else if (bin[pos]=='0' && bin[pos+1]=='1') {       returnValue[pos2] = 'F';     } else {       return "not applicable";     }     pos = pos+2;     pos2++;   }   returnValue[pos2] = '\0';   return returnValue;
}
//------------------------------------------------------------
void setup() 
{   pinMode(ledPin, OUTPUT);  // sets the digital pin as output   pinMode(onboard_led, OUTPUT);   Serial.begin(9600);      while (!Serial)   {     ; // wait for serial port to connect. Needed for Leonardo only   }   Serial.println("Setup done....");      //mySwitch.setProtocol(1);   mySwitch.enableReceive(1);  // Receiver on inerrupt 1 on leonardo(!) (not 0 on UNO)  => that is pin #2#     }
//------------------------------------------------------------
void loop() 
{   digitalWrite(ledPin, LOW);   digitalWrite(onboard_led, HIGH);   if (mySwitch.available())   {  int value = mySwitch.getReceivedValue(); if (value == 0) {  Serial.print("Unknown encoding");     }      else     {       Serial.print("Received ");       Serial.print( mySwitch.getReceivedValue() );       Serial.print(" / ");       Serial.print( mySwitch.getReceivedBitlength() );       Serial.print("bit ");       Serial.print("Protocol: ");       Serial.println( mySwitch.getReceivedProtocol() );     }         output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());         mySwitch.resetAvailable();   }   else   {     int val=0;      val = digitalRead(2);      digitalWrite(ledPin, val);     //blink_system();     }
}

//------------------------------------------------------------