Hallo Gemeinde,
möchte die Raw-Daten der Wetterstation und des Funkmessgerät(Pollin) mit Ethersex & RFM12 empfangen + weiterverarbeiten
WH1080    868,3MHZ Baude 17,24 kps
EMR7370  868,3MHZ Baude   9,60 kps
Wie bekomme ich dies in Ethersex am effektivsten rein ?
Gruß
Peter
*****Test mit decoder arduino Atmeg328 auf PollinEvalutionsboard *********************** //frame |0 |1 |2 |3 |4 |5 |6|7 |8 |9 |10 |11 |12|13|14|15|16|17|18|19| // Hex |25 6A|54 BD|40 0 |0 0 |CC |41 3D |D6 |F1 DF|FF FF|FF FF|FF EF|
//                  |CA  D8   |0 1     |C8
//                  |2776 W   |1 mA    |220 V
//      Gerät|  ID  | Leistung|Strom   |Spannung |Energie|Prüfsumme|
void DECEMR7370(unsigned int *data)
{
unsigned int frame[20];
int device_id;
int Spannung_raw;
float Spannung;
int Leistung_raw;
float Leistung;
int Strom_raw;
float Strom;
int Energie_raw;
float Energie;

//frameTabelle füllen
 for (int i=0; i<20; i++) { //20
     frame[i]= data[i];}

//Adresse constant byte
device_id =((frame[2] << 4) | (frame[3] >> 4));
//Power
Leistung_raw   = (frame[4] & 0x3F) << 8 | frame[5];
//Strom
Strom_raw = frame[6] << 8 | frame[7];
//Voltage
Spannung_raw = (frame[8]);
Spannung = Spannung_raw + 20;
//Energy
Energie_raw  = (frame[9] & 0x3F) << 8 | frame[10];
Energie = (float) Energie_raw/100;
        Serial.print("Id: ");
 Serial.println(device_id);
        Serial.print("Leistung: ");
        Serial.print(Leistung_raw);
        Serial.println(" W");

        Serial.print("Strom : ");
        Serial.print(Strom_raw);
        Serial.println(" mA");

        Serial.print("Spannung: ");
 Serial.print(Spannung);
        Serial.println(" V");

        Serial.print("Energie: ");
        Serial.print(Energie);
        Serial.println(" Kwh");
}
************************************************
//*****************************Hauptprogramm************************
//RFM12B OKK sections taken from the original Jeenode OKK Raw example
//Tested with Arduino 0021
//Tested with arduino 1.0
// polling RFM12/RFM12B to decode FSK iT+ with a Jeenode from Jeelabs.
// device  : iT+ TX29IT 04/2010 v36 D1 LA Crosse Technology (c)
// info    : http://forum.jeelabs.net/node/110
// http://fredboboss.free.fr/tx29/tx29_sw.php
// http://www.f6fbb.org/domo/sensors/
//           benedikt.k http://www.mikrocontroller.net/topic/67273
//           rinie,marf,joop 1 nov 2011
// *****************************************************
// * Resouces used:-
// *http://www.susa.net/wordpress/2012/08/raspberry-pi-reading-wh1081-weather-sensors-using-an-rfm01-and-rfm12b/
// * jeenode_lacross_rx by Rufik
// *****************************************************
// 09/01/2013 V 0.01 Initial WH1080 fine offset Arduino decoder
// Baude 17.24 kps     by Steve Pyle
// *****************************************************
// 09/01/2013 V 0.01 Initial DCF77/WH1080 fine offset Arduino decoder
// Baude 17.24 kps     by Peter Weiß
//******************************************************
// 20/07/2013 V      Initial Pollin EMR7370 Arduino decoder
// Baude 9.6 kps       by Peter Weiß
//******************************************************
//************     To Do / Change log   ****************
//
//
// *****************************************************

#include <util/delay.h>
#include "Arduino.h"
#define clrb(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define setb(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#define RF_PORT PORTB
#define RF_DDR DDRB
#define RF_PIN PINB
#define SDI 3
#define SCK 5
#define CS 2
#define SDO 4
#define LED_PIN 05
#define CRC_POLY 0x31 // CRC-8 = 0x31 is for: x8 + x5 + x4 + 1
#define DEBUG 1 // set to 1 to see debug messages ; no see 0
#define LOGWeather  1//0-nein 1 -ja 17.24  nein 9600 ERM7370
// Time
#include <JeeLib.h>
#include <Time.h>
// Decoder laden
#include "DECWH1080.h"
#include "DECEMR7370.h"
#include "DCF77.h"
//LED
static void activityLed (byte on) {
    pinMode(LED_PIN, OUTPUT);
    digitalWrite(LED_PIN, !on);
}
//Receive message, data[]
void receive(unsigned int *data)
{  unsigned char mesage[20];
   if (DEBUG) { Serial.println("Listening...."); }
  rf12_rxdata(mesage,20);
  if (DEBUG) {
    Serial.print("Received HEX raw data: ");
    for (int i=0; i<20; i++) {
//     for(uint8_t i = 0; i<20; i++)
      Serial.print(mesage[i], HEX);
      Serial.print(" ");
    }
    Serial.println();
  }

 //Write message into table
// for(uint8_t i = 0; i<20; i++)
  for (int i=0; i<20; i++) { //20
    data[i] = (unsigned int) mesage[i];
  }
}
// Calculate CRC
static uint8_t compute_crc(uint8_t b) {
  uint8_t do_xor;
  uint8_t reg;
  reg = 0;
  do_xor = (reg & 0x80);
  reg <<=1;
  reg |= b;
  if (do_xor) {
    reg ^= CRC_POLY;
  }
  return reg;
}

//check if CRC is OK
boolean is_crc_valid(unsigned int crcByte) {
  boolean result = false;

  uint8_t crc_computed = compute_crc((uint8_t) crcByte);
  if ((unsigned int) crc_computed == crcByte) {
    result = true;
if (DEBUG) { Serial.print("CRC OK: "); Serial.println(crc_computed, HEX); }
  } else {
    if (DEBUG) {
Serial.print("CRC Error... Calculated is "); Serial.print(crc_computed, HEX);
      Serial.print(" Received is "); Serial.println(crcByte, HEX);
    }
  }
 delay(100); // waits for a second
  return result;
}
//Decoderstart
//Check if msg starts with A (WH1080) or with 2 (EMR7370)
boolean is_msg_valid(unsigned int msgFirstByte) {
  boolean result = false;
 unsigned int msgFlag = (msgFirstByte & 240) >> 4;
//Schalter nach größe aufsteigend anordnen
switch (msgFlag) {

  case 2:   //2 = EMR7037
    result = true;
    Serial.println("OK - Decoderung mit Decoder EMR7370 msgFLag -2-");
    break;

  case 10:  //A = WH1080
    result = true;
    Serial.println("OK - Decoderung mit Decoder WH1080 msgFlag -A-");
    break;

  case 11:  //B = WH1080 0xB
    result = true;
    Serial.println("OK - Decoderung mit Decoder DCF77 msgFlag -B-");
    break;

 default:
if (DEBUG) { Serial.print("Msg does start with A/B or 2, it's HEX: "); Serial.print(msgFlag, HEX); Serial.print(" Dezimal: "); Serial.println(msgFlag, DEC);}

}
delay(100); // waits for a second
return result;
}
///Decoderende
void rf12_rxdata(unsigned char *data, unsigned char number)
{ uint8_t  i;
        activityLed(1);

 rf12_xfer(0x82C8);   // receiver on
 rf12_xfer(0xCA81);   // set FIFO mode
 rf12_xfer(0xCA83);   // enable FIFO
 for (i=0; i<number; i++)
 { rf12_ready();
  *data++=rf12_xfer(0xB000);
 }
 rf12_xfer(0x8208);   // Receiver off
        activityLed(0);
}
// ******** SPI + RFM 12B functies ************************************************************************
unsigned short rf12_xfer(unsigned short value)
{ uint8_t i;
 clrb(RF_PORT, CS);
 for (i=0; i<16; i++)
 { if (value&32768)
   setb(RF_PORT, SDI);
  else
   clrb(RF_PORT, SDI);
  value<<=1;
  if (RF_PIN&(1<<SDO))
   value|=1;
  setb(RF_PORT, SCK);
  asm("nop");
  asm("nop");
  clrb(RF_PORT, SCK);
 }
 setb(RF_PORT, CS);
 return value;
}

void rf12_ready(void)
{
clrb(RF_PORT, CS);
asm("nop");
asm("nop");
while (!(RF_PIN&(1<<SDO))); // wait until FIFO ready
setb(RF_PORT, CS);
}

static void rf12_la_init()
{
RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS);
RF_PORT=(1<<CS);
for (uint8_t  i=0; i<10; i++) _delay_ms(10); // wait until POR done
rf12_xfer(0x80E8); // 80e8 CONFIGURATION EL,EF,868 band,12.5pF // iT+ 915 80f8 rf12_xfer(0xA67c); // a67c FREQUENCY SETTING 868.300 // a67c = 915.450 MHz
if (LOGWeather)
{rf12_xfer(0xC613);} // c613 DATA RATE c613  17.241 kbps WH1080
else
{rf12_xfer(0xC623);} // c613 DATA RATE c623  9600 kbps EMR 7300

rf12_xfer(0xC26a); // c26a DATA FILTER COMMAND
rf12_xfer(0xCA12); // ca12 FIFO AND RESET  8,SYNC,!ff,DR
rf12_xfer(0xCEd4); // ced4 SYNCHRON PATTERN  0x2dd4
rf12_xfer(0xC49f); // c49f AFC during VDI HIGH +15 -15 AFC_control_commAND
rf12_xfer(0x94a0); // 94a0 RECEIVER CONTROL VDI Medium 134khz LNA max DRRSI 103 dbm
rf12_xfer(0xCC77); // cc77 not in RFM01
rf12_xfer(0x9872); // 9872 transmitter not checked
rf12_xfer(0xE000); // e000 NOT USE
rf12_xfer(0xC800); // c800 NOT USE
rf12_xfer(0xC040); // c040 1.66MHz,2.2V
}

void setup () {
  //Serial.begin(57600);
  Serial.begin(9600);
  if (DEBUG) {
    Serial.println("Station Wireless Receiver ");}
    activityLed(1);
    delay(250);
  rf12_la_init();
   delay(250);
  if (DEBUG) {
    Serial.println("RF Module setup complete");}
    activityLed(0);
}

void loop ()
{
  unsigned int frame[20];
  //get message
 //farme(0):187

 timestamp();
delay(100); // waits for a second

  receive(frame);
delay(100); // waits for a second

if (DEBUG){
 Serial.print("frame[0]: ");
 Serial.println(frame[0],DEC);}

 if (is_msg_valid(frame[0])){



     //Schalter nach größe aufsteigend anordnen
     switch (frame[0]) {

     //check if valid for NEXT (EMR7370)
      case 37:
     // check CRC
     if (is_crc_valid(frame[11]))  {
      //DEC z.B.DECEMR7370.h
      DECEMR7370(frame);
      delay(100); // waits for a second
      break;
     }


     //check if valid for Fineoffset (WH1080)
     case 171:
     // check CRC
    if (is_crc_valid(frame[9]))  {
      //DEC z.B.DECWH1080.h
      DECWH1080(frame);
      delay(100); // waits for a second
      break;
      }


    //check if valid for Fineoffset (WH1080/DCF77)
     case 187:
     // check CRC
    if (is_crc_valid(frame[9]))  {
      //DEC z.B.DCF77.h
      update_time(/*msgformat,*/ packet);
      delay(100); // waits for a second
      break;
      }



     }
   }

}
//Zeitstempel ohne Synconisierung  DCF77
void printDigits(int digits){
  // utility function for digital clock display: leading 0
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}
void timestamp()
{
  Serial.print(year());
  Serial.print("-");
  printDigits(month());
  Serial.print("-");
  printDigits(day());
  Serial.print(" ");
  printDigits(hour());
  Serial.print(":");
  printDigits(minute());
  Serial.print(":");
  printDigits(second());
  Serial.print(" ");
}
_______________________________________________
Ethersex-devel mailing list
Ethersex-devel@list.zerties.org
https://list.zerties.org/cgi-bin/mailman/listinfo/ethersex-devel

Antwort per Email an