Ich habe den Sketch von der-pw erweitert um eine RTC.
Code: Alles auswählen
//- -----------------------------------------------------------------------------------------------------------------------
// AskSin++
// 2016-10-31 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
#define USE_WOR
#define EI_NOTEXTERNAL
#include <EnableInterrupt.h>
#include <AskSinPP.h>
#include <LowPower.h>
#include <Switch.h>
#include <ResetOnBoot.h>
// we use a Pro Mini
// Arduino pin for the LED
// D4 == PIN 4 on Pro Mini
#define LED_PIN 4
// Arduino pin for the config button
// B0 == PIN 8 on Pro Mini
#define CONFIG_BUTTON_PIN 8
#define RELAY1_PIN 5 //change to D5 for further PWM Options
// === Define the clock ===
// Remove comment if you have an external oscillator like a 32kHz crystal
#define USE_RTC
// number of available peers per channel
#define PEERS_PER_CHANNEL 8
// all library classes are placed in the namespace 'as'
using namespace as;
// define all device properties
const struct DeviceInfo PROGMEM devinfo = {
{0x42,0xA2,0x07}, // Device ID
"papa42a207", // Device Serial
{0x00,0x6c}, // Device Model
0x10, // Firmware Version
as::DeviceType::Switch, // Device Type
{0x01,0x00} // Info Bytes
};
/**
* Configure the used hardware
*/
typedef AvrSPI<10,11,12,13> RadioSPI;
//typedef AskSin<StatusLed<LED_PIN>,BattSensor<AsyncMeter<InternalVCC>>,Radio<RadioSPI,2> > Hal;
#ifdef USE_RTC
typedef AskSinRTC<StatusLed<LED_PIN>,BattSensor<AsyncMeter<ExternalVCC<17,7,LOW,3300> >>,Radio<RadioSPI,2> > Hal;
#else
typedef AskSin<StatusLed<LED_PIN>,BattSensor<AsyncMeter<ExternalVCC<17,7,LOW,3300> >>,Radio<RadioSPI,2> > Hal;
#endif
DEFREGISTER(Reg0,DREG_INTKEY,DREG_LEDMODE,MASTERID_REGS,DREG_LOWBATLIMIT)
class SwList0 : public RegList0<Reg0> {
public:
SwList0(uint16_t addr) : RegList0<Reg0>(addr) {}
void defaults () {
clear();
lowBatLimit(22);
}
};
// setup the device with channel type and number of channels
class SwitchType : public MultiChannelDevice<Hal,SwitchChannel<Hal,PEERS_PER_CHANNEL,SwList0>,1,SwList0> {
public:
typedef MultiChannelDevice<Hal,SwitchChannel<Hal,PEERS_PER_CHANNEL,SwList0>,1,SwList0> DevType;
SwitchType (const DeviceInfo& i,uint16_t addr) : DevType(i,addr) {}
virtual ~SwitchType () {}
virtual void configChanged () {
DevType::configChanged();
//uint8_t lowbat = getList0().lowBatLimit();
uint8_t lowbat = getList0().lowBatLimit() / 5; //factor 5 to get low bat message at 1V (CCU 5V)
DDECLN(lowbat);
if( lowbat > 0 ) {
battery().low(lowbat);
}
}
};
Hal hal;
SwitchType sdev(devinfo,0x20);
ResetOnBoot<SwitchType> resetOnBoot(sdev);
ConfigToggleButton<SwitchType> cfgBtn(sdev);
#ifndef USE_WOR
BurstDetector<Hal> bd(hal);
#endif
void initPeerings (bool first) {
// create internal peerings - CCU2 needs this
if( first == true ) {
HMID devid;
sdev.getDeviceID(devid);
for( uint8_t i=1; i<=sdev.channels(); ++i ) {
Peer ipeer(devid,i);
sdev.channel(i).peer(ipeer);
}
}
}
void setup () {
DINIT(57600,ASKSIN_PLUS_PLUS_IDENTIFIER);
bool first = sdev.init(hal);
sdev.channel(1).init(RELAY1_PIN);
buttonISR(cfgBtn,CONFIG_BUTTON_PIN);
initPeerings(first);
#ifdef USE_RTC
#ifndef USE_WOR
// start burst detection
bd.enable(rtc);
#endif
#else
#ifndef USE_WOR
// start burst detection
bd.enable(sysclock);
#endif
#endif
#ifdef USE_RTC
// stay on for 15 seconds after start
hal.activity.stayAwake(15);
// measure battery every hour
hal.battery.init(60UL*60, rtc);
#else
// stay on for 15 seconds after start
hal.activity.stayAwake(seconds2ticks(15));
// measure battery every hour
hal.battery.init(seconds2ticks(60UL*60),sysclock);
#endif
resetOnBoot.init();
sdev.initDone();
//if (sdev.getMasterID() == HMID::broadcast) { DPRINTLN(F("START PAIRING")); sdev.startPairing(); } // start pairing of no master id is present
}
void loop() {
bool worked = hal.runready();
bool poll = sdev.pollRadio();
if( worked == false && poll == false ) {
hal.activity.savePower<Sleep<> >(hal);
}
}
Code: Alles auswählen
AskSin++ v5.0.0 (Dec 4 2021 23:46:02)
Address Space: 32 - 250
00000000
Init Storage: CAFEA52E
CC init1
CC Version: 14
- ready
eVcc: 477
4
<- 0E 01 86 10 42A207 000000 06 01 00 00 00 - 1261
debounce
pressed
longpressed
longreleased
<- 1A 02 84 00 42A207 000000 10 00 6C 70 61 70 61 34 32 61 32 30 37 10 01 01 00 - 1591
-> 10 01 B0 01 67113F 42A207 00 05 00 00 00 00 00 - 2131
<- 0A 01 80 02 42A207 67113F 00 - 2250
-> 13 0A A0 01 67113F 42A207 00 08 02 01 0A 67 0B 11 0C 3F - 2287
<- 0A 0A 80 02 42A207 67113F 00 - 2410
-> 0B 13 A0 01 67113F 42A207 00 06 - 2439
4
<- 0A 13 82 02 42A207 67113F 00 - 2560
-> 10 1C A0 01 67113F 42A207 00 04 00 00 00 00 00 - 2603
<- 18 1C 80 10 42A207 67113F 02 02 01 05 00 0A 67 0B 11 0C 3F 12 16 00 00 - 2734
-> 10 25 A0 01 67113F 42A207 01 04 00 00 00 00 01 - 2768
<- 14 25 80 10 42A207 67113F 02 08 00 30 06 56 00 57 24 00 00 - 2899
-> 0B 2E A0 01 67113F 42A207 01 03 - 2928
<- 12 2E 80 10 42A207 67113F 01 42 A2 07 01 00 00 00 00 - 3057
-> 10 37 A0 01 67113F 42A207 01 04 42 A2 07 01 03 - 3092
<- 1A 37 A0 10 42A207 67113F 02 02 00 03 00 04 32 05 64 06 00 07 FF 08 00 09 FF - 3225
-> 0A 37 80 02 67113F 42A207 00 - 3340
waitAck: 01
<- 1A 37 A0 10 42A207 67113F 02 0A 01 0B 14 0C 63 82 00 83 00 84 32 85 64 86 00 - 3385
-> 0A 37 80 02 67113F 42A207 00 - 3502
waitAck: 01
<- 18 37 80 10 42A207 67113F 02 87 FF 88 00 89 FF 8A 01 8B 14 8C 63 00 00 - 3545
-> 0B 40 B0 01 67113F 42A207 01 0E - 21585
<- 0E 40 82 10 42A207 67113F 06 01 00 00 1E - 21714
-> 0E 49 B0 11 67113F 42A207 02 01 C8 00 00 - 22216
<- 0E 49 80 02 42A207 67113F 01 01 C8 00 1E - 22343
-> 0E 52 B0 11 67113F 42A207 02 01 00 00 00 - 22847
<- 0E 52 80 02 42A207 67113F 01 01 00 00 1E - 22974
debounce
pressed
released
-> 0B 03 02 40 42A207 42A207 01 03 - 23486
<- 0E 04 A2 10 42A207 67113F 06 01 C8 00 1E - 23615
-> 0A 04 80 02 67113F 42A207 00 - 23740
waitAck: 01
debounce
pressed
released
-> 0B 05 02 40 42A207 42A207 01 05 - 24246
<- 0E 06 A2 10 42A207 67113F 06 01 00 00 21 - 24375
-> 0A 06 80 02 67113F 42A207 00 - 24500
waitAck: 01