From b8a0e8ec8191205f7979b20b4d38012f58edbb4c Mon Sep 17 00:00:00 2001 From: Ralf Behrens Date: Tue, 18 Jan 2022 11:21:55 +0100 Subject: [PATCH] =?UTF-8?q?PowerSave=20=C3=BCber=20RTC=20Alarm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/MessenSensoren.h | 3 +- src/MessenSensoren.cpp | 79 ++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 42 +++++++++++++++------ 3 files changed, 111 insertions(+), 13 deletions(-) diff --git a/include/MessenSensoren.h b/include/MessenSensoren.h index e1c10a5..85b2a07 100644 --- a/include/MessenSensoren.h +++ b/include/MessenSensoren.h @@ -8,7 +8,8 @@ void PrintTimeDate(void); int16_t readVcc(void); void init_Messen(void); void MessenSensoren(void); - +void PowerDown(void); +void PowerUp(void); // nicht schoen aber funktioniert diff --git a/src/MessenSensoren.cpp b/src/MessenSensoren.cpp index 406aaa0..756d05f 100644 --- a/src/MessenSensoren.cpp +++ b/src/MessenSensoren.cpp @@ -214,3 +214,82 @@ void MessenSensoren() { hse.addVoltage(fUb/1000.0); // in Volt hse.addCounter(uiOnStd); // Zeit On } + +//----------------------------------------- +// +//----------------------------------------- +void PowerDown(void) +{ + pinMode(LED1, OUTPUT); + digitalWrite(LED1, LOW); // LED aus + +/* + // IOs + //pinMode(0, INPUT_PULLUP); // 2,4mA + pinMode(0, INPUT_PULLDOWN); // 2,39mA + // 1 = TxD + pinMode(2, INPUT_PULLDOWN); // == + // 3 = DIO0 + // 4 = Reset RF96 + // 5 = Power_I2C + digitalWrite(I2C_POWER, LOW); // 3V Power Pin + // 6 = DIO1 + pinMode(6, INPUT_PULLDOWN); // + // 7 = + pinMode(7, INPUT_PULLDOWN); // 2,39mA + // 8 = NSS + // 9 = A7 = Ubatt Sensor + // 10 = + pinMode(10, INPUT_PULLDOWN); // + // 11 = + pinMode(11, INPUT_PULLDOWN); // + // 12 = + pinMode(12, INPUT_PULLDOWN); // + // 13 = LED1 + digitalWrite(LED1, LOW); // LED aus + // 2,39mA + //----------- + // 14 = A0 + pinMode(14, INPUT_PULLDOWN); // = + // 15 = A1 + pinMode(15, INPUT_PULLDOWN); // == + // 16 = A2 + pinMode(16, INPUT_PULLDOWN); // = + // 17 = A3 + pinMode(17, INPUT_PULLDOWN); // = + // 18 = A4 + pinMode(18, INPUT_PULLDOWN); // = + // 19 = A5 + pinMode(19, INPUT_PULLDOWN); // = + // 19 = A5 + pinMode(19, INPUT_PULLDOWN); // = + // 20 = SDA + pinMode(20, INPUT_PULLDOWN); // = + // 21 = SCL + pinMode(21, INPUT_PULLDOWN); // 2,38mA +//--------------------- +// 22 = MISO +// 23 = MOSI +// 24 = SCK + for (int i=25;i<30;i++) pinMode(i, INPUT_PULLDOWN); // +// => 2,38mA + +//myRFM_setModeSleep(); + */ + +} +//------------------------------------------------- +//------------------------------------------------------------------- +void PowerUp(void) +{ +int i; + +// I2C Power einschalten LoRa Transponder +pinMode(I2C_POWER,OUTPUT); +digitalWrite(I2C_POWER, HIGH); +delay(10); +Wire.begin(); + +} + +//--------------------------------------------------- diff --git a/src/main.cpp b/src/main.cpp index 43c9861..705a08d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,9 +37,12 @@ #include #include #include +#include +#include #include "hseSensorProtocol.h" #include "MessenSensoren.h" -#include "ArduinoLowPower.h" + +RTCZero rtc; // This EUI must be in little-endian format, so least-significant-byte // first. When copying an EUI from ttnctl output, this means to reverse @@ -228,20 +231,27 @@ void onEvent(ev_t ev) { } Serial1.println(F("")); } - // Schedule next transmission - os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(TX_INTERVAL), do_send); - Serial1.print(F("WasTustDu=")); - Serial1.println(WasTustDu); - WasTustDu++; PrintTimeDate(); //Serial1.println(F("vor sleep")); - //Serial1.flush(); + Serial1.flush(); + + // Sleep for a period of TX_INTERVAL using single shot alarm + rtc.setAlarmEpoch(rtc.getEpoch() + TX_INTERVAL); + rtc.enableAlarm(rtc.MATCH_YYMMDDHHMMSS); + rtc.attachInterrupt(alarmMatch); - //LowPower.sleep((uint32_t) (TX_INTERVAL-10)*1000); // bis kurz vor dem Ereignis schlafen - //LowPower.sleep(1000); // ich will wissen wie häufig er hier vorbei kommt - + PowerDown(); + // Enter sleep mode + rtc.standbyMode(); + //Serial1.println(F("wieder aufgewacht")); // => er wacht nicht wieder auf + PowerUp(); + + // Schedule next transmission to be immediately after this + os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(1), do_send); + + break; case EV_LOST_TSYNC: @@ -297,9 +307,13 @@ void setup() { USBDevice.detach(); Serial1.begin(19200); - Serial1.println(F("Starting 1.04")); + Serial1.println(F("Starting 1.05")); Serial1.println(F(__FILE__)); Serial1.println(F(__DATE__)); + // Initialize RTC + rtc.begin(); + // Use RTC as a second timer instead of calendar + rtc.setEpoch(0); #ifdef __SAMD21G18A__ @@ -323,7 +337,7 @@ void setup() { os_init(); // Reset the MAC state. Session and pending data transfers will be discarded. LMIC_reset(); - + LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100); LMIC_setLinkCheckMode(0); LMIC_setDrTxpow(DR_SF7, 6); //LMIC_selectSubBand(1); @@ -338,4 +352,8 @@ void loop() { } +void alarmMatch() +{ + +}