Pages: [1]   Go Down
Author Topic: Code to read EnOcean telegrams  (Read 1362 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This reads a TCM 120 connected to the serial port, and switches an LED on from the signals received from the wireless, batteryless transmitters.

This is the first part of my WLAN/email to EnOcean bridge I am developing.

Code:
// EnOcean reader
// Simple code to read an EnOcean telegram - does not check ID of transmitter at this stage, so will operate from ANY switch

int ledPin=13;
int packet[14];
int j;

void setup()
{
  Serial.begin(9600);
  pinMode(ledPin,OUTPUT);
  digitalWrite(ledPin,HIGH);
  delay(250);
  digitalWrite(ledPin,LOW);
  Serial.println("EnOcean TCM120 reader");
}
 
void loop()
{  
 
 while (Serial.available())
 {
   packet[j++]=Serial.read();
   j=j % 14;
   if(roly(j)==165 && roly(j+1)==90) //now we have sync bytes for packet
    {
     print_packet();
     if((roly(j+3)==5) && (roly(j+4)==80)) digitalWrite(ledPin,HIGH); //switch is pressed ON
     if((roly(j+3)==5) && (roly(j+4)==0 )) digitalWrite(ledPin,LOW);  //switch released
    }
 }  
}

void print_packet()
{
  int i;
  Serial.print("ORG:");   Serial.print(roly(2),HEX);
  Serial.print(" Data:"); for(i=4;i<=7;i++)  { Serial.print(roly(i),HEX); Serial.print(" "); }
  Serial.print("ID:");    for(i=8;i<=11;i++) { Serial.print(roly(i),HEX); Serial.print(" "); }
  Serial.print("ST:");    Serial.print(roly(12),HEX);
  Serial.print(" Chk:");  Serial.println(roly(13),HEX);
}

int roly(int n)
{
 return packet[n%14];
}

Logged

Pages: [1]   Go Up
Jump to: