AskSin++ Library

Begonnen von papa, 08 September 2016, 11:11:25

Vorheriges Thema - Nächstes Thema

papa

BananaPi + CUL868 + CUL433 + HM-UART + 1Wire

0xFFFF

Oh man...danke, das wars. Ich dachte eigentlich ich hätte an der Schaltung nichts mehr geändert, aber offensichtlich doch.
Naja wie auch immer, danke nochmal für eure Hilfe!

papa

Das kann auch einfach im Code geändert werden. Einfach den zweiten Templateparameter in der Typedefinition vom Radio in 3 ändern.


typedef Radio<SPIType,2> RadioType;


Aber bitte beachten, im Master-Branch bin ich gerade kräftig am umbauen. Da können sich APIs nochmal ändern. Stabil sollte es halbwegs sein.
BananaPi + CUL868 + CUL433 + HM-UART + 1Wire

east

#288
So hab den XML-Code in der CCU2 geändert. Das MixDevice wird erkannt und auch verarbeitet. Allerdings funktionieren nur die Kanäle 1-3. Der Kanal 4 wird nicht geschaltet und führt zur Kommunikationsstörung mit Fehlermeldung in der CCU2.

Weiter ist mir aufgefallen, das die Kanäle 3 und 4 vom Switch beim anlernen direkt eingschaltet sind.

//- -----------------------------------------------------------------------------------------------------------------------
// AskSin++
// 2017-05-10 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
//- -----------------------------------------------------------------------------------------------------------------------

// define this to read the device id, serial and device type from bootloader section
// #define USE_OTA_BOOTLOADER

// number of relays - possible values 1,2,4
// will map to HM-LC-SW1-SM, HM-LC-SW2-SM, HM-LC-SW4-SM
#define RELAY_COUNT 2

// define all device properties
#define DEVICE_ID HMID(0x90,0x78,0x90)
#define DEVICE_SERIAL "xms1234567"
#define DEVICE_MODEL  0x00,0xdf
#define DEVICE_FIRMWARE 0x10
#define DEVICE_TYPE DeviceType::Switch
#define DEVICE_INFO 0x04,0x01,0x00

#include <EnableInterrupt.h>
#include <AskSinPP.h>
#include <TimerOne.h>
#include <LowPower.h>

#include <MultiChannelDevice.h>
#include <Remote.h>
#include <SwitchChannel.h>



// we use a Pro Mini
// Arduino pin for the LED
// D4 == PIN 4 on Pro Mini
#define LED_PIN 4
#define LED_PIN2 6

// Arduino pin for the config button
// B0 == PIN 8 on Pro Mini
#define CONFIG_BUTTON_PIN 8

// relay output pins compatible to the HM_Relay project
#define RELAY1_PIN 7
#define RELAY2_PIN 9

#define BUTTON1_PIN 3
#define BUTTON2_PIN 5

// number of available peers per channel
#define PEERS_PER_SWCHANNEL 2
#define PEERS_PER_BTNCHANNEL 10

// all library classes are placed in the namespace 'as'
using namespace as;

/**
* Configure the used hardware
*/
typedef AvrSPI<10,11,12,13> SPIType;
typedef Radio<SPIType,2> RadioType;
typedef DualStatusLed<6,4> LedType;
typedef AskSin<LedType,NoBattery,RadioType> Hal;
Hal hal;

typedef RemoteChannel<Hal,PEERS_PER_BTNCHANNEL> BtnChannel;
typedef SwitchChannel<Hal,PEERS_PER_SWCHANNEL> SwChannel;

class MixDevice : public ChannelDevice<Hal,VirtBaseChannel<Hal>,4> {
public:
  VirtChannel<Hal,BtnChannel> c1,c2;
  VirtChannel<Hal,SwChannel> c3,c4;
public:
  typedef ChannelDevice<Hal,VirtBaseChannel<Hal>,4> DeviceType;
  MixDevice (uint16_t addr) : DeviceType(addr) {
    DeviceType::registerChannel(c1,1);
    DeviceType::registerChannel(c2,2);
    DeviceType::registerChannel(c3,3);
    DeviceType::registerChannel(c4,4);
  }
  virtual ~MixDevice () {}

  BtnChannel& btn1Channel () { return c1; }
  BtnChannel& btn2Channel () { return c2; }
  SwChannel&  Sw3Channel  () { return c3; }
  SwChannel&  Sw4Channel  () { return c4; }
};
MixDevice sdev(0x20);

ConfigButton<MixDevice> cfgBtn(sdev);

// map number of channel to pin
// this will be called by the SwitchChannel class
uint8_t SwitchPin (uint8_t number) {
  switch( number ) {
   
    case 3: return RELAY1_PIN;
    case 4: return RELAY2_PIN;
   
   
  }
}

void setup () {
  DINIT(57600,ASKSIN_PLUS_PLUS_IDENTIFIER);
  sdev.init(hal);
 
  buttonISR(cfgBtn,CONFIG_BUTTON_PIN);
  remoteChannelISR(sdev.btn1Channel(),BUTTON1_PIN);
  remoteChannelISR(sdev.btn2Channel(),BUTTON2_PIN);
 
}

void loop() {
  bool pinchanged = sdev.btn1Channel().checkpin();
  pinchanged |= sdev.btn2Channel().checkpin();

  bool worked = hal.runready();
  bool poll = sdev.pollRadio();
  if( pinchanged == false && worked == false && poll == false ) {
    // deep discharge protection
    // if we drop below critical battery level - switch off all and sleep forever
    if( hal.battery.critical() ) {
      // this call will never return
      hal.activity.sleepForever(hal);
    }
    // if nothing to do - go sleep
    hal.activity.savePower<Sleep< > >(hal);
  }
}


Aber trotzdem schon mal ein kleiner Erfolg, beim manipulieren der XML-Files..... :D

Anbei der geänderte XML File.

east

#289
JUHUUUU.....

Jetzt funzt es!!!!!

Musste Savepower auf Idle setzen, stand vorher auf sleep.

//- -----------------------------------------------------------------------------------------------------------------------
// AskSin++
// 2017-05-10 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
//- -----------------------------------------------------------------------------------------------------------------------

// define this to read the device id, serial and device type from bootloader section
// #define USE_OTA_BOOTLOADER

// number of relays - possible values 1,2,4
// will map to HM-LC-SW1-SM, HM-LC-SW2-SM, HM-LC-SW4-SM
#define RELAY_COUNT 2

// define all device properties
#define DEVICE_ID HMID(0x90,0x78,0x90)
#define DEVICE_SERIAL "xms1234567"
#define DEVICE_MODEL  0x00,0xdf
#define DEVICE_FIRMWARE 0x10
#define DEVICE_TYPE DeviceType::Switch
#define DEVICE_INFO 0x04,0x01,0x00

#include <EnableInterrupt.h>
#include <AskSinPP.h>
#include <TimerOne.h>
#include <LowPower.h>

#include <MultiChannelDevice.h>
#include <Remote.h>
#include <SwitchChannel.h>



// we use a Pro Mini
// Arduino pin for the LED
// D4 == PIN 4 on Pro Mini
#define LED_PIN 4
#define LED_PIN2 6

// Arduino pin for the config button
// B0 == PIN 8 on Pro Mini
#define CONFIG_BUTTON_PIN 8

// relay output pins compatible to the HM_Relay project
#define RELAY1_PIN 7
#define RELAY2_PIN 9

#define BUTTON1_PIN 3
#define BUTTON2_PIN 5

// number of available peers per channel
#define PEERS_PER_SWCHANNEL 2
#define PEERS_PER_BTNCHANNEL 10

// all library classes are placed in the namespace 'as'
using namespace as;

/**
* Configure the used hardware
*/
typedef AvrSPI<10,11,12,13> SPIType;
typedef Radio<SPIType,2> RadioType;
typedef DualStatusLed<6,4> LedType;
typedef AskSin<LedType,NoBattery,RadioType> Hal;
Hal hal;

typedef RemoteChannel<Hal,PEERS_PER_BTNCHANNEL> BtnChannel;
typedef SwitchChannel<Hal,PEERS_PER_SWCHANNEL> SwChannel;

class MixDevice : public ChannelDevice<Hal,VirtBaseChannel<Hal>,4> {
public:
  VirtChannel<Hal,BtnChannel> c1,c2;
  VirtChannel<Hal,SwChannel> c3,c4;
public:
  typedef ChannelDevice<Hal,VirtBaseChannel<Hal>,4> DeviceType;
  MixDevice (uint16_t addr) : DeviceType(addr) {
    DeviceType::registerChannel(c1,1);
    DeviceType::registerChannel(c2,2);
    DeviceType::registerChannel(c3,3);
    DeviceType::registerChannel(c4,4);
  }
  virtual ~MixDevice () {}

  BtnChannel& btn1Channel () { return c1; }
  BtnChannel& btn2Channel () { return c2; }
  SwChannel&  Sw3Channel  () { return c3; }
  SwChannel&  Sw4Channel  () { return c4; }
};
MixDevice sdev(0x20);

ConfigButton<MixDevice> cfgBtn(sdev);

// map number of channel to pin
// this will be called by the SwitchChannel class
uint8_t SwitchPin (uint8_t number) {
  switch( number ) {
   
    case 3: return RELAY1_PIN;
    case 4: return RELAY2_PIN;
   
   
  }
}

void setup () {
  DINIT(57600,ASKSIN_PLUS_PLUS_IDENTIFIER);
  sdev.init(hal);
 
  buttonISR(cfgBtn,CONFIG_BUTTON_PIN);
  remoteChannelISR(sdev.btn1Channel(),BUTTON1_PIN);
  remoteChannelISR(sdev.btn2Channel(),BUTTON2_PIN);
 
}

void loop() {
  bool pinchanged = sdev.btn1Channel().checkpin();
  pinchanged |= sdev.btn2Channel().checkpin();

  bool worked = hal.runready();
  bool poll = sdev.pollRadio();
  if( pinchanged == false && worked == false && poll == false ) {
    // deep discharge protection
    // if we drop below critical battery level - switch off all and sleep forever
    if( hal.battery.critical() ) {
      // this call will never return
      hal.activity.sleepForever(hal);
    }

  if( worked == false && poll == false ) {
    hal.activity.savePower<Idle<> >(hal);
  }
  }
}


Brauch jetzt nur noch hilfe, um die Kanäle 3 und 4 standardweise auf "aus" zu setzen. Die sind sonst beim neustart auf "ein".


Hier noch meine Änderungen im vorhandenen XML in der CCU2......


papa

Cooool

Die Switch-Channels müssen noch im setup() initialisiert werden:


void setup () {
  DINIT(57600,ASKSIN_PLUS_PLUS_IDENTIFIER);
  sdev.init(hal);
  sdev.Sw3Channel().lowactive(false);
  sdev.Sw4Channel().lowactive(false);
  buttonISR(cfgBtn,CONFIG_BUTTON_PIN);
  remoteChannelISR(sdev.btn1Channel(),BUTTON1_PIN);
  remoteChannelISR(sdev.btn2Channel(),BUTTON2_PIN);

}


Dabei wird dann die Switch-Statemachine initialisiert und die Switches schicken auch den aktuellen Zustand an die Zentrale. Und beachten die powerOn Einstellung.
BananaPi + CUL868 + CUL433 + HM-UART + 1Wire

papa

Ach so - noch vergessen. 0x00df als Devicetype finde ich etwas gefährlich. Keine Ahnung, ob es das nicht schon mal gibt. Mach mal lieber einen größeren Wert in das erste Byte.
BananaPi + CUL868 + CUL433 + HM-UART + 1Wire

east

#292
Ok. Mache ich .....

Aber im ersten Byte steht bei keinem Device etwas. Also nur 0x00.

Habe nochmal meine Änderungen im XML verdeutlicht. Hoffe es hilft ein wenig.


Nochmal vielen Dank für die super Hilfe!!!

papa

Zitat von: east am 17 Mai 2017, 11:05:28
Ok. Mache ich .....

Aber im ersten Byte steht bei keinem Device etwas. Also nur 0x00.

Genau - soweit ich bisher gesehen habe, ist das immer 0x00. Damit sollte ein anderer Wert eine Kollision mit existierenden oder zukünftigen Geräten vermeiden. Der Universal-Wetter-Sensor von Dirk hat zum Beispiel 0xF1 gesetzt.

Zitat von: east am 17 Mai 2017, 11:05:28
Habe nochmal meine Änderungen im XML verdeutlicht. Hoffe es hilft ein wenig.

Hm - Du hast zweimal Channel mit index=1. Ist das so richtig? Die Switch-Channels müssten doch 3 & 4 sein bzw. index=3 count=2. Aber meine Kenntnisse der XML-Files beruhen hauptsächlich auf Vermutungen.
BananaPi + CUL868 + CUL433 + HM-UART + 1Wire

Dietmar63

#294
Ich kenne den FHEM-Code des Universalsensors. Dort sind die Codes F101 (innen) und F102 (außen) hinterlegt. Ich meine mal gelesen zu haben, dass DIY Geräte größer 0100 oder so beginnen sollen. Vielleicht war es auch > F100.

https://wiki.fhem.de/wiki/Universalsensor
Unter Firmware findet man den FHEM-Code und XML-Code der CCU.

Ich weiß nicht ob es noch weitere Geräte gibt.
Man müsste auf dem FHEM-Code vielleicht mal ein grep nach  HMConfig::culHmModel durchführen. Ich habe im Moment keinen Zugriff.
Gruß Dietmar
FB7390, CUL, 2 FHT, FS20
modules: 98_WOL.pm, 98_Heating_Control.pm,   98_WeekdayTimer.pm, 98_RandomTimer.pm, 59_Twilight.pm

east

Hab nochmal nachgesehen. Hast recht mit dem Index....

Muss ich wohl korrigieren.

east

So hab jetzt nochmal getestet mit dem Index. Komischerweise funktioniert das nicht, wenn ich den Switch auf Index 2 oder 3 stelle.
Wenn ich das mache, geht die CCU2 in Störung und zeigt mir 4 anstatt 2 Switch Kanäle an. Und dann funktioniert auch nix.

Habe das jetzt komischerweise so realisieren müssen..... :o

/- -----------------------------------------------------------------------------------------------------------------------
// AskSin++
// 2017-05-10 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
//- -----------------------------------------------------------------------------------------------------------------------

// define this to read the device id, serial and device type from bootloader section
// #define USE_OTA_BOOTLOADER

// number of relays - possible values 1,2,4
// will map to HM-LC-SW1-SM, HM-LC-SW2-SM, HM-LC-SW4-SM
#define RELAY_COUNT 2

// define all device properties
#define DEVICE_ID HMID(0x90,0x78,0x90)
#define DEVICE_SERIAL "xms1234567"
#define DEVICE_MODEL  0xF1,0xDF
#define DEVICE_FIRMWARE 0x10
#define DEVICE_TYPE DeviceType::Switch
#define DEVICE_INFO 0x04,0x01,0x00

#include <EnableInterrupt.h>
#include <AskSinPP.h>
#include <TimerOne.h>
#include <LowPower.h>

#include <MultiChannelDevice.h>
#include <Remote.h>
#include <SwitchChannel.h>



// we use a Pro Mini
// Arduino pin for the LED
// D4 == PIN 4 on Pro Mini
#define LED_PIN 4
#define LED_PIN2 6

// Arduino pin for the config button
// B0 == PIN 8 on Pro Mini
#define CONFIG_BUTTON_PIN 8

// relay output pins compatible to the HM_Relay project
#define RELAY1_PIN 7
#define RELAY2_PIN 9

#define BUTTON1_PIN 3
#define BUTTON2_PIN 5

// number of available peers per channel
#define PEERS_PER_SWCHANNEL 2
#define PEERS_PER_BTNCHANNEL 10

// all library classes are placed in the namespace 'as'
using namespace as;

/**
* Configure the used hardware
*/
typedef AvrSPI<10,11,12,13> SPIType;
typedef Radio<SPIType,2> RadioType;
typedef DualStatusLed<6,4> LedType;
typedef AskSin<LedType,NoBattery,RadioType> Hal;
Hal hal;

typedef RemoteChannel<Hal,PEERS_PER_BTNCHANNEL> BtnChannel;
typedef SwitchChannel<Hal,PEERS_PER_SWCHANNEL> SwChannel;

class MixDevice : public ChannelDevice<Hal,VirtBaseChannel<Hal>,4> {
public:
  VirtChannel<Hal,BtnChannel> c1,c2;
  VirtChannel<Hal,SwChannel> c3,c4;
public:
  typedef ChannelDevice<Hal,VirtBaseChannel<Hal>,4> DeviceType;
  MixDevice (uint16_t addr) : DeviceType(addr) {
    DeviceType::registerChannel(c1,1);
    DeviceType::registerChannel(c2,2);
    DeviceType::registerChannel(c3,3);
    DeviceType::registerChannel(c4,4);
  }
  virtual ~MixDevice () {}

  BtnChannel& btn1Channel () { return c1; }
  BtnChannel& btn2Channel () { return c2; }
  SwChannel&  Sw3Channel  () { return c3; }
  SwChannel&  Sw4Channel  () { return c4; }
};
MixDevice sdev(0x20);

ConfigButton<MixDevice> cfgBtn(sdev);

// map number of channel to pin
// this will be called by the SwitchChannel class
uint8_t SwitchPin (uint8_t number) {
  switch( number ) {
   
    case 3: return RELAY1_PIN;
    case 4: return RELAY2_PIN;
   
   
  }
}

void setup () {
  DINIT(57600,ASKSIN_PLUS_PLUS_IDENTIFIER);
  sdev.init(hal);
  sdev.Sw3Channel().lowactive(false);
  sdev.Sw4Channel().lowactive(false);
  buttonISR(cfgBtn,CONFIG_BUTTON_PIN);
  remoteChannelISR(sdev.btn1Channel(),BUTTON1_PIN);
  remoteChannelISR(sdev.btn2Channel(),BUTTON2_PIN);
 
}

void loop() {
  bool pinchanged = sdev.btn1Channel().checkpin();
  pinchanged |= sdev.btn2Channel().checkpin();

  bool worked = hal.runready();
  bool poll = sdev.pollRadio();
  if( pinchanged == false && worked == false && poll == false ) {
    // deep discharge protection
    // if we drop below critical battery level - switch off all and sleep forever
    if( hal.battery.critical() ) {
      // this call will never return
      hal.activity.sleepForever(hal);
    }

  if( worked == false && poll == false ) {
    hal.activity.savePower<Idle<> >(hal);
  }
  }
}

papa

Ich habe da eine Vermutung. Du hast bei dem SwitchChannel ja das Attribute count_from_sysinfo="23.0:1.0" drin. Das wird sicherlich bedeuten, dass die CCU die Anzahl der Kanäle aus der während des Pairen bereitgestellten SysInfo-Struktur bezieht. Kannst Du mal mit dem ersten Byte im DEVICE_INFO experimentieren. Da steht ja jetzt 4 - also insgesamt 4 Kanäle.

Nur mal um zu Lernen - kannst Du da mal 3 eintragen. Würde mich echt interessieren, was dann passiert.

Vermutung: Es werden dann 2 RemoteChannels und 1 SwitchChannel. Es werden also 3 SwitchChannels (1-3) angelegt und dann mit den 2 Remotes (1-2) überschrieben.

Im XML muss dann wahrscheinlich die Reihenfolge korrect sein. Also zuerst Channel index=1 count=2 type=Remote und dann Channel index=3 count=2 type=Switch. Das count_from_sysinfo Attribute darf dann nicht verwendet werden.

Aber es könnte auch alles ganz anders funktionieren  :(
BananaPi + CUL868 + CUL433 + HM-UART + 1Wire

papa

Kannst Du vielleicht auch mal eine separate XML-Datei verwenden. In Deiner sind ja auch noch originale Geräte defineirt. Nicht das da was durcheinander kommt.
BananaPi + CUL868 + CUL433 + HM-UART + 1Wire

east

#299
jo. klingt logisch. Wenn ich in der Device Info 0x04 Kanäle drin habe und in der XML der Index 3 auftaucht, werden ab den 2.ten Kanal vier Switchkanäle erstellt. Durch Index 1, so wie jetzt werden die 4 switchkanäle durch 2 Remotekanäle überschrieben. OK probiere mal ein wenig und mache mal ne neue XML-Datei.

Da aber im Arduino nur jeweils 2 Kanäle erstellt sind, kommt der Arduino wahrscheinlich nicht mehr klar und hängt sich auf. (Grüne LED leuchtet ständig)