Automatické zatváranie kurníku pre sliepky

Nedaří se vám s projektem a nenašli jste vhodné místo, kde se zeptat? Napište sem.
Pravidla fóra
Tohle subfórum je určeno pro konzultaci ucelených nápadů, popřípadě řešení komplexnějších projektů, které opravdu není možné rozdělit na menší části.
Většinu problémů jde rozdělit na menší a ptát se na ně v konkrétních subfórech.
Odpovědět
lukas700602
Příspěvky: 22
Registrován: 10 úno 2019, 22:17
Reputation: 0

Re: Automatické zatváranie kurníku pre sliepky

Příspěvek od lukas700602 » 12 úno 2019, 17:43

Určite ďakujem za tvoj názor , ešte sa s tým vyhrám trošku :D :lol:

pettr
Příspěvky: 5
Registrován: 07 led 2020, 09:35
Reputation: 0

Re: Automatické zatváranie kurníku pre sliepky

Příspěvek od pettr » 07 led 2020, 09:41

Já jsem našel toto: https://backyardpoultry.iamcountryside. ... coop-door/, líbí se mi, že je to nastavené přímo na východy a západy slunce + zpoždění kvůli soumraku, jen kdyby to ale uměl někdo přepsat na středoevropský čas...

Uživatelský avatar
pavel1tu
Příspěvky: 2054
Registrován: 26 říj 2017, 08:28
Reputation: 0
Bydliště: Trutnov
Kontaktovat uživatele:

Re: Automatické zatváranie kurníku pre sliepky

Příspěvek od pavel1tu » 07 led 2020, 11:12

pettr píše:
07 led 2020, 09:41
Já jsem našel toto: https://backyardpoultry.iamcountryside. ... coop-door/, líbí se mi, že je to nastavené přímo na východy a západy slunce + zpoždění kvůli soumraku, jen kdyby to ale uměl někdo přepsat na středoevropský čas...
Ale to není o středoevropském času
Prostě si tam najdeš své město, nebo nejbližší a pro každý den tam dáš číslo (je to kolik sekund od 0:00:00) kdy slunce vychází a zapadá
Nic jiného dělat nemusíš než změnit

Kód: Vybrat vše

// Sunset times in seconds after midnight for each ordinal day of the year, 
// eg, Jan 1 = array index 0, etc. The times are EST and are adjusted one
// hour when DST is in effect.
//
// The arrays are stored in program memory because dynamic memory is not
// big enough to hold them
//
static const long sunsetAr[] PROGMEM = {62760,62820,62820,62880,62940,63000,
63060,63120,63180,63240,63300,63360,63420,63480,63540,63600,63660,63720,63840,
63900,63960,64020,64080,64140,64200,64260,64380,64440,64500,64560,64620,64680,
64800,64860,64920,64980,65040,65100,65220,65280,65340,65400,65460,65520,65640,
65700,65760,65820,65880,65940,66000,66060,66180,66240,66300,66360,66420,66480,
66540,66600,66660,66720,66780,66840,66900,66960,67020,67080,67200,67260,67320,
67380,67440,67500,67560,67620,67680,67740,67800,67860,67920,67980,68040,68100,
68100,68160,68220,68280,68340,68400,68460,68520,68580,68640,68700,68760,68820,
68880,68940,69000,69060,69120,69180,69240,69300,69360,69420,69480,69540,69600,
69660,69720,69780,69840,69900,69960,70020,70080,70140,70200,70260,70320,70380,
70440,70440,70500,70560,70620,70680,70740,70800,70860,70920,70980,71040,71100,
71160,71220,71280,71280,71340,71400,71460,71520,71580,71580,71640,71700,71760,
71760,71820,71880,71940,71940,72000,72060,72060,72120,72120,72180,72180,72240,
72240,72300,72300,72360,72360,72360,72420,72420,72420,72420,72480,72480,72480,
72480,72480,72480,72480,72480,72480,72480,72480,72480,72480,72420,72420,72420,
72420,72360,72360,72300,72300,72300,72240,72240,72180,72120,72120,72060,72000,
72000,71940,71880,71820,71820,71760,71700,71640,71580,71520,71460,71400,71340,
71280,71220,71160,71100,71040,70920,70860,70800,70740,70680,70560,70500,70440,
70320,70260,70200,70080,70020,69960,69840,69780,69660,69600,69480,69420,69300,
69240,69120,69060,68940,68880,68760,68700,68580,68520,68400,68280,68220,68100,
68040,67920,67800,67740,67620,67560,67440,67320,67260,67140,67020,66960,66840,
66780,66660,66540,66480,66360,66300,66180,66060,66000,65880,65820,65700,65640,
65520,65400,65340,65220,65160,65040,64980,64860,64800,64740,64620,64560,64440,
64380,64320,64200,64140,64080,63960,63900,63840,63720,63660,63600,63540,63480,
63420,63300,63240,63180,63120,63060,63000,62940,62880,62820,62820,62760,62700,
62640,62580,62580,62520,62460,62460,62400,62340,62340,62280,62280,62220,62220,
62220,62160,62160,62160,62160,62100,62100,62100,62100,62100,62100,62100,62100,
62100,62100,62160,62160,62160,62160,62220,62220,62280,62280,62280,62340,62340,
62400,62460,62460,62520,62580,62580,62640,62700,62760};

static const long sunriseAr[] PROGMEM = {28620,28620,28680,28680,28680,28680,
28680,28620,28620,28620,28620,28620,28620,28560,28560,28560,28500,28500,28440,
28440,28380,28380,28320,28260,28260,28200,28140,28140,28080,28020,27960,27900,
27840,27780,27720,27660,27600,27540,27480,27420,27360,27300,27240,27180,27060,
27000,26940,26880,26760,26700,26640,26520,26460,26400,26280,26220,26160,26040,
25980,25860,25800,25680,25620,25500,25440,25320,25260,25140,25080,24960,24900,
24780,24720,24600,24540,24420,24300,24240,24120,24060,23940,23880,23760,23640,
23580,23460,23400,23280,23160,23100,22980,22920,22800,22740,22620,22560,22440,
22320,22260,22140,22080,21960,21900,21780,21720,21660,21540,21480,21360,21300,
21180,21120,21060,20940,20880,20820,20700,20640,20580,20520,20400,20340,20280,
20220,20160,20100,19980,19920,19860,19800,19740,19680,19620,19560,19500,19500,
19440,19380,19320,19260,19200,19200,19140,19080,19080,19020,19020,18960,18900,
18900,18900,18840,18840,18780,18780,18780,18720,18720,18720,18720,18720,18720,
18660,18660,18660,18660,18660,18660,18720,18720,18720,18720,18720,18780,18780,
18780,18780,18840,18840,18900,18900,18900,18960,18960,19020,19020,19080,19140,
19140,19200,19260,19260,19320,19380,19380,19440,19500,19560,19560,19620,19680,
19740,19740,19800,19860,19920,19980,20040,20100,20100,20160,20220,20280,20340,
20400,20460,20520,20580,20580,20640,20700,20760,20820,20880,20940,21000,21060,
21120,21180,21240,21240,21300,21360,21420,21480,21540,21600,21660,21720,21780,
21840,21840,21900,21960,22020,22080,22140,22200,22260,22320,22380,22380,22440,
22500,22560,22620,22680,22740,22800,22860,22920,22980,22980,23040,23100,23160,
23220,23280,23340,23400,23460,23520,23580,23640,23700,23700,23760,23820,23880,
23940,24000,24060,24120,24180,24240,24300,24360,24420,24480,24540,24600,24660,
24720,24780,24840,24900,25020,25080,25140,25200,25260,25320,25380,25440,25500,
25560,25620,25680,25800,25860,25920,25980,26040,26100,26160,26220,26280,26400,
26460,26520,26580,26640,26700,26760,26820,26880,26940,27060,27120,27180,27240,
27300,27360,27420,27480,27540,27600,27660,27720,27780,27780,27840,27900,27960,
28020,28080,28080,28140,28200,28200,28260,28320,28320,28380,28380,28440,28440,
28500,28500,28560,28560,28560,28620,28620,28620,28620};
a upravit TimeZone

Kód: Vybrat vše

// Globals
//
// Timezone rules - US Eastern Time Zone (New York, Detroit)
TimeChangeRule myDST = {"EDT", Second, Sun, Mar, 2, -240};    //Daylight time = UTC - 4 hours
TimeChangeRule myEST = {"EST", First, Sun, Nov, 2, -300};     //Standard time = UTC - 5 hours
Timezone myTZ(myDST, myEST);
PS: já takto svítím rybičkám, podle toho jak svítí sluníčko v Asii )mám rybky z Asie), ale posunuté do naší časové zony a podle statistik doby slunečního svitu pro daný měsíc i vytvářím zamračené/slunečné dny
UNO, NANO, Mikro, PRO mini, DUE, ESP32S2, RPi PICO
Pavel1TU
"Správně napsaný kod lze číst jako knihu"

pettr
Příspěvky: 5
Registrován: 07 led 2020, 09:35
Reputation: 0

Re: Automatické zatváranie kurníku pre sliepky

Příspěvek od pettr » 13 led 2020, 21:27

jak prosté :-) děkuju moc

pettr
Příspěvky: 5
Registrován: 07 led 2020, 09:35
Reputation: 0

Re: Automatické zatváranie kurníku pre sliepky

Příspěvek od pettr » 18 led 2020, 11:13

Tak mi to šlape podle východu a západu, bohužel ale přesně o hodinu jinak. V PC jsem neměl nastavené automatické změny času letní/zimní, tak jsem myslel, že je to ono. Ale i po přenastavení jsem stále tam. Modul času mám DS3231, s tou knihovnou mi to ale stále hlásí chyby o násobných knihovnách:

C:\Users\HP\Desktop\Step_One\Step_One.ino: In function 'void setup()':

Step_One:30:5: error: 'RTC' was not declared in this scope

RTC.set(utc);

^~~

Byly nalezené násobné knihovny "DS3231.h"
Použitý: C:\Users\HP\Documents\Arduino\libraries\DS3231
Byly nalezené násobné knihovny "Wire.h"
Použitý: C:\Program
Byly nalezené násobné knihovny "TimeLib.h"
Použitý: C:\Users\HP\Documents\Arduino\libraries\Time
Nepoužitý: C:\Users\HP\Documents\Arduino\libraries\Time-master
Byly nalezené násobné knihovny "Timezone.h"
Použitý: C:\Users\HP\Documents\Arduino\libraries\Timezone
Nepoužitý: C:\Users\HP\Documents\Arduino\libraries\Timezone-master
exit status 1
'RTC' was not declared in this scope


tak jsem vyzkoušel s knihovnou DS3232RTC, chybu nevyhazuje, ale stejně jsem na tom rozdílu té hodiny. V původním programu je to s knihovnou DS1307RTC, ale i s tou jsem stále na té hodině. (prodlevu mám 30 min, takže součet je 1,5 hod) Takže se už v tom pěkně ztrácím. Nevím, kde může být chyba. Nejdříve nahraju do Arduina Step ONE

Kód: Vybrat vše

/*----------------------------------------------------------------------*
 * SetRTCtoUTC
 *
 * Adapted from WorldClock example from the Timezone library examples.
 *
 *----------------------------------------------------------------------*/

#include <DS3231RTC.h>
#include <Wire.h>
#include <Time.h>        //http://www.arduino.cc/playground/Code/Time
#include <TimeLib.h>
#include <Timezone.h>    //https://github.com/JChristensen/Timezone

#pragma GCC diagnostic ignored "-Wwrite-strings"

TimeChangeRule usEDT = {"EDT", First, Sun, Nov, 2, -240};  //Eastern Daylight Time = UTC - 4 hours
TimeChangeRule usEST = {"EST", Third, Sun, Nov, 2, -300};   //Eastern Standard Time = UTC - 5 hours
Timezone usET(usEDT, usEST);

tmElements_t tm;

TimeChangeRule *tcr;        // pointer to the time change rule, use to get the TZ abbrev
time_t utc;

void setup(void)
{
    Serial.begin(9600);
    setTime(usET.toUTC(compileTime()));
    utc = now();
    RTC.set(utc);
    
}

void loop(void)
{
    Serial.println();
    utc = now();
    time_t local = usET.toLocal(utc, &tcr);
    Serial.print("Is DST in effect: ");
    Serial.println(usET.locIsDST(local));
    
    printTime(utc, "UTC", " Universal Coordinated Time");
    printTime(usET.toLocal(utc, &tcr), tcr -> abbrev, " New York");
    delay(10000);
}

//Function to return the compile date and time as a time_t value
time_t compileTime(void)
{
#define FUDGE 25        //fudge factor to allow for compile time (seconds, YMMV)

    char *compDate = __DATE__, *compTime = __TIME__, *months = "JanFebMarAprMayJunJulAugSepOctNovDec";
    char chMon[3], *m;
    int d, y;
    tmElements_t tm;
    time_t t;

    strncpy(chMon, compDate, 3);
    chMon[3] = '\0';
    m = strstr(months, chMon);
    tm.Month = ((m - months) / 3 + 1);

    tm.Day = atoi(compDate + 4);
    tm.Year = atoi(compDate + 7) - 1970;
    tm.Hour = atoi(compTime);
    tm.Minute = atoi(compTime + 3);
    tm.Second = atoi(compTime + 6);
    t = makeTime(tm);
    return t + FUDGE;        //add fudge factor to allow for compile time
}

//Function to print time with time zone
void printTime(time_t t, char *tz, char *loc)
{
    sPrintI00(hour(t));
    sPrintDigits(minute(t));
    sPrintDigits(second(t));
    Serial.print(' ');
    Serial.print(dayShortStr(weekday(t)));
    Serial.print(' ');
    sPrintI00(day(t));
    Serial.print(' ');
    Serial.print(monthShortStr(month(t)));
    Serial.print(' ');
    Serial.print(year(t));
    Serial.print(' ');
    Serial.print(tz);
    Serial.print(' ');
    Serial.print(loc);
    Serial.println();
}

//Print an integer in "00" format (with leading zero).
//Input value assumed to be between 0 and 99.
void sPrintI00(int val)
{
    if (val < 10) Serial.print('0');
    Serial.print(val, DEC);
    return;
}

//Print an integer in ":00" format (with leading zero).
//Input value assumed to be between 0 and 99.
void sPrintDigits(int val)
{
    Serial.print(':');
    if(val < 10) Serial.print('0');
    Serial.print(val, DEC);
}
a potom dohraju program ChickenDoor s upravenými časy pro Liberec

Kód: Vybrat vše

/*

   ChickenDoor - V0.6

    Opens and closes a linear actuator based on sunrise and sunset tables included in the program.

    Uses the Timezone library (url below) to automatically adjust the time twice yearly for Daylight
    Saving Time.

*/

// Includes
//
#include <Arduino.h>
#include <DS3232RTC.h>   //http://www.arduino.cc/playground/Code/Time
#include <Time.h>        //http://www.arduino.cc/playground/Code/Time
#include <TimeLib.h>
#include <Timezone.h>    //https://github.com/JChristensen/Timezone
#include <Wire.h>        //http://arduino.cc/en/Reference/Wire (supplied with the Arduino IDE)

#pragma GCC diagnostic ignored "-Wwrite-strings"

// Defines
//
#define DEBUG

#define OPEN     0
#define CLOSED   1
#define OFF      0
#define ON       1
#define SUNRISE_DELAY (30*60)
#define SUNSET_DELAY  (30*60)

// Sunset times in seconds after midnight for each ordinal day of the year, 
// eg, Jan 1 = array index 0, etc. The times are EST and are adjusted one
// hour when DST is in effect.
//
// The arrays are stored in program memory because dynamic memory is not
// big enough to hold them
//
static const long sunsetAr[] PROGMEM = {57840,57900,57960,58020,58080,58200,
58260,58320,58380,58500,58560,58620,58740,58800,58920,58980,59100,59160,59280,
59400,59520,59580,59700,59760,59940,60060,60120,60240,60360,60480,60540,60600,
60720,60840,60900,61020,61140,61260,61320,61440,61560,61680,61800,61860,61980,
62100,62220,62280,62400,62520,62640,62700,62820,62940,63060,63120,63240,63360,
63480,63540,63660,63780,63900,63960,64080,64200,64260,64380,64500,64560,64680,
64800,64860,64980,65100,65160,65280,65400,65460,65580,65700,65760,65880,65940,
66060,66180,66240,66360,66480,66540,66660,66720,66840,66960,67020,67140,67260,
67320,67440,67500,67620,67740,67800,67920,68040,68100,68220,68280,68400,68520,
68580,68700,68760,68880,69000,69060,69180,69240,69360,69480,69540,69660,69720,
69840,69960,70020,70140,70200,70320,70380,70500,70560,70680,70740,70860,70920,
71040,71100,71160,71280,71340,71460,71520,71580,71640,71760,71820,71880,71940,
72000,72120,72180,72240,72300,72360,72420,72480,72480,72540,72600,72660,72660,
72720,72780,72780,72840,72840,72960,72960,73020,73020,73020,73020,73020,73080,
73080,73080,73080,73020,73020,73020,73020,72960,72900,72900,72840,72840,72780,
72780,72720,72660,72660,72600,72540,72480,72420,72360,72300,72240,72180,72120,
72060,72000,71880,71820,71760,71700,71640,71580,71460,71400,71280,71160,71040,
70920,70860,70740,70620,70560,70440,70320,70200,70080,70020,69900,69780,69660,
69540,69420,69300,69180,69060,68940,68820,68700,68580,68460,68340,68220,68040,
67920,67800,67680,67560,67440,67260,67140,67020,66900,66780,66600,66480,66360,
66240,66060,65940,65820,65700,65580,65400,65280,65160,64980,64860,64740,64620,
64440,64320,64200,64080,63900,63780,63660,63540,63420,63240,63120,63000,62880,
62760,62580,62460,62340,62220,62100,61980,61860,61680,61560,61440,61320,61200,
61080,60960,60840,60720,60600,60480,60360,60240,60180,60060,59940,59820,59700,
59640,59520,59400,59280,59220,59100,59040,58920,58800,58740,58680,58560,58500,
58380,58320,58260,58200,58080,58020,57960,57900,57840,57780,57720,57660,57600,
57600,57540,57480,57420,57420,57360,57360,57300,57300,57300,57240,57240,57240,
57240,57240,57240,57240,57240,57240,57240,57240,57300,57300,57360,57360,57420,
57420,57480,57540,57540,57600,57660,57720,57780,57840};

static const long sunriseAr[] PROGMEM = {28860,28860,28860,28860,28860,28800,
28800,28800,28740,28740,28680,28680,28620,28560,28560,28500,28440,28380,28320,
28260,28200,28140,28080,28020,27960,27840,27780,27720,27600,27540,27480,27360,
27300,27180,27120,27000,26680,26820,26700,26580,26520,26400,26280,26160,26100,
25980,25860,25740,25620,25500,25380,25260,25140,25020,24900,24780,24660,24540,
24420,24300,24180,24060,23940,23760,23640,23520,23400,23280,23160,22980,22860,
22740,22620,22500,22320,22200,22080,21960,21840,21660,21540,21420,21300,21120,
21000,20880,20760,20640,20460,20340,20220,20100,19920,19800,19680,19560,19440,
19260,19140,19020,18900,18780,18660,18540,18360,18240,18120,18000,17880,17760,
17640,17520,17400,17280,17160,17040,16920,16800,16680,16620,16500,16380,16260,
16140,16080,15960,15840,15720,15660,15540,15480,15360,15240,15180,15060,15000,
14940,14820,14760,14700,14580,14520,14460,14400,14340,14280,14220,14160,14100,
14040,13980,13920,13860,13860,13800,13740,13740,13680,13680,13620,13620,13560,
13560,13560,13560,13560,13560,13560,13560,13560,13560,13560,13560,13560,13620,
13620,13620,13680,13680,13740,13740,13800,13860,13860,13920,13980,14040,14100,
14100,14160,14220,14280,14340,14400,14460,14580,14640,14700,14760,14820,14940,
15000,15060,15120,15240,15300,15360,15480,15540,15660,15720,15780,15900,15960,
16080,16140,16260,16320,16440,16500,16620,16680,16800,16860,16980,17040,17160,
17220,17340,17400,17520,17640,17700,17820,17880,18000,18060,18180,18240,18360,
18420,18540,18600,18720,18840,18900,19020,19080,19200,19260,19380,19440,19560,
19620,19740,19800,19920,20040,20100,20220,20280,20400,20460,20580,20640,20760,
20880,20940,21060,21120,21240,21300,21420,21540,21600,21720,21780,21900,21960,
22080,22200,22260,22380,22500,22560,22680,22740,22860,22980,23040,23160,23280,
23340,23460,23580,23640,23760,23880,23940,24060,24180,24300,24360,24480,24600,
24660,24780,24900,25020,25080,25200,25320,25380,25500,25620,25740,25800,25920,
26040,26100,26220,26340,26400,26520,26580,26700,26820,26880,27000,27060,27180,
27240,27360,27420,27480,27600,27660,27720,27840,27900,27960,28020,28080,28140,
28200,28260,28320,28380,28440,28500,28560,28620,28620,28680,28680,28740,28800,
28800,28800,28860,28860,28860,28860,28860,28860,28860};

// Constants
//
const int delayTime      = 1000;
const int relayOnePin    = 1;  // Unused
const int relayTwoPin    = 2;  // Door 1
const int relayThreePin  = 3;  // Door 2
const int relayFourPin   = 4;  // Lights
const int secondsPerHour = 3600;

// Days of months array for ordinal calculation
static const int monthLen[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

// Globals
//
// Timezone rules - US Eastern Time Zone (New York, Detroit)
TimeChangeRule myDST = {"EDT", Second, Sun, Mar, 2, -240};    //Daylight time = UTC - 4 hours
TimeChangeRule myEST = {"EST", First, Sun, Nov, 2, -300};     //Standard time = UTC - 5 hours
Timezone myTZ(myEST, myEST);

TimeChangeRule *tcr;        // pointer to the time change rule, use to get TZ abbrev
time_t utc, local;

int doorState = CLOSED;
int lightState = OFF;

// Init
void setup()
{
    long sunset  = 0;
    long sunrise = 0;
    long seconds = 0;

    // Initialize the relay pins
    pinMode(relayOnePin, OUTPUT);
    pinMode(relayTwoPin, OUTPUT);
    pinMode(relayThreePin, OUTPUT);
    pinMode(relayFourPin, OUTPUT);

#ifdef DEBUG
    // Start the serial port
    Serial.begin(9600);
    while (!Serial)
      ;
    delay(200);
#endif

    // Set the time using the RTC's time
    setSyncProvider(RTC.get);           // Get the time from the RTC 

#ifdef DEBUG
    if(timeStatus()!= timeSet)          // Again, this is check the TZ lib status
        Serial.println("Unable to sync with the RTC");
    else
        Serial.println("RTC has set the system time "); 
#endif

    // Door initialization based on TZ library time
    utc = now();
    local = myTZ.toLocal(utc, &tcr);

#ifdef DEBUG
    Serial.print("Start-up time: ");
    printTime(local, tcr -> abbrev);
#endif

    // We have the date and time, convert it to seconds since midnight
    seconds = toSeconds(hour(local), minute(local), 0);

    // Get the ordinal day of the year to use as an index into the sunset/rise arrays
    int ordinalDay = ordinalDayOfYear(tmYearToCalendar(year(local)), month(local), day(local));

    // Get the times adjusted for DST and open/close delay
    sunrise = getAdjustedSunriseTime(ordinalDay, local);
    sunset  = getAdjustedSunsetTime(ordinalDay, local);

    // Close or open the door, the door methods check for current state
    if ((seconds > sunrise) && (seconds < sunset))
    {
       doorState = CLOSED;
       openDoor();
    } else {
       doorState = OPEN;
       closeDoor();
    }

    // Turn the lights on (6AM) or off (9PM)
    initCoopLights(local);
}

void loop()
{
    long sunset = 0;
    long sunrise = 0;
    long seconds = 0;
    
    // Wait the current delay time
    delay(delayTime);

    // get current date and time
    utc = now();
    local = myTZ.toLocal(utc, &tcr);

#ifdef DEBUG
//    printTime(local, tcr -> abbrev);
#endif

    // We have the date and time
    seconds = toSeconds(hour(local), minute(local), 0);

    // Now get the ordinal day of the year
    int ordinalDay = ordinalDayOfYear(tmYearToCalendar(year(local)), month(local), day(local));

    // Get the times adjusted for DST and open/close delay
    sunrise = getAdjustedSunriseTime(ordinalDay, local);
    sunset  = getAdjustedSunsetTime(ordinalDay, local);

    // Close or open the door, the door methods check for current state
    if ((seconds > sunrise) && (seconds < sunset))
    {
       openDoor();
    } else {
       closeDoor();
    }

    // Turn the lights on (6AM) or off (9PM)
    setCoopLights(local);
}

void openDoor()
{
    // Is the door closed?
    if (doorState == CLOSED)
    {
#ifdef DEBUG
        Serial.print("Opening door: ");    
        utc = now();
        local = myTZ.toLocal(utc, &tcr);
        printTime(local, tcr -> abbrev);
#endif
        doorState = OPEN;

        // open the door
        digitalWrite(relayTwoPin, HIGH);
        digitalWrite(relayThreePin, HIGH);
    }

    return;
}

void closeDoor()
{
    // Is the door open?
    if (doorState == OPEN)
    {
#ifdef DEBUG
        Serial.print("Closing door: ");    
        utc = now();
        local = myTZ.toLocal(utc, &tcr);
        printTime(local, tcr -> abbrev);
#endif
            
        doorState = CLOSED;

        // close the door
        digitalWrite(relayTwoPin, LOW);
        digitalWrite(relayThreePin, LOW);
    }

    return;
}

void initCoopLights(time_t t)
{
  int curHour = hour(t);
  
  // On between 6AM and 9PM
  if (curHour > 5 && curHour < 21)
  {
      // Turn on the lights
      lightState = ON;
#ifdef DEBUG
  Serial.print("Turning lights on: ");
  utc = now();
  local = myTZ.toLocal(utc, &tcr);
  printTime(local, tcr -> abbrev);
#endif      
      digitalWrite(relayFourPin, HIGH);
  } else {

      // Turn off the lights
      lightState = OFF;
#ifdef DEBUG
  Serial.print("Turning lights off: ");
  utc = now();
  local = myTZ.toLocal(utc, &tcr);
  printTime(local, tcr -> abbrev);
#endif      
      digitalWrite(relayFourPin, LOW);
  }

  return;
}

void setCoopLights(time_t t)
{
  int curHour = hour(t);

  // On between 6AM and 9PM
  if (curHour > 5 && curHour < 21)
  {
    if (lightState == OFF)
    {
#ifdef DEBUG
  Serial.print("Turning lights on at ");
  Serial.println(curHour);
#endif
      lightState = ON;
      
      // Turn off the lights
      digitalWrite(relayFourPin, HIGH);
    }
  } else {
    if (lightState == ON)
    {
      lightState = OFF;
#ifdef DEBUG
  Serial.print("Turning lights off at ");
  Serial.println(curHour);
#endif       
      // Turn on the lights
      digitalWrite(relayFourPin, LOW);
    }  
  }

  return;
}

long toSeconds(long hours, long minutes, long seconds)
{
    long secs = (hours*secondsPerHour)+(minutes*60)+seconds;
    return secs;
}

int ordinalDayOfYear(int year, int month, int day)
{
    int ordinal = 0;

    // Is it a leap year?
    int leap = (year % 4 == 0) && (year % 100 != 0 || year % 400 == 0);

    // Add up the days of the months preceding the current month
    for (int i = 0; i < month - 1; i++)
    {
        ordinal += monthLen[i];
    }

    // Check for leap year
    if (leap && month > 2)
    {
        ordinal++;
    }

    // Include days in current month
    ordinal += day;

    return ordinal;
}

long getAdjustedSunriseTime(int ordinalDay, time_t local)
{
  // Get the sunrise time from the table - adjust index for zero-based array
  long sunrise = pgm_read_word_near(sunriseAr + (ordinalDay - 1));

  // Check for DST and adjust if necessary
  if (myTZ.locIsDST(local))
  {
      // Add an hour to sunrise
      sunrise += secondsPerHour;
  }
  // And finally add the sunrise opening delay
  sunrise += SUNRISE_DELAY;
  
  return sunrise;
}

long getAdjustedSunsetTime(int ordinalDay, time_t local)
{
  // Get the sunset time from the table - adjust index for zero-based array
  long sunset = pgm_read_word_near(sunsetAr + (ordinalDay - 1));

  // Check for DST and adjust if necessary
  if (myTZ.locIsDST(local))
  {
      // Add an hour to sunset
      sunset += secondsPerHour;
  }

  // And finally add the sunrise opening delay
  sunset += SUNSET_DELAY;

  return sunset;
}

#ifdef DEBUG

//Function to print time with time zone
void printTime(time_t t, char *tz)
{
    sPrintI00(hour(t));
    sPrintDigits(minute(t));
    sPrintDigits(second(t));
    Serial.print(' ');
    Serial.print(dayShortStr(weekday(t)));
    Serial.print(' ');
    sPrintI00(day(t));
    Serial.print(' ');
    Serial.print(monthShortStr(month(t)));
    Serial.print(' ');
    Serial.print(year(t));
    Serial.print(' ');
    Serial.print(tz);
    Serial.println();
}

//Print an integer in "00" format (with leading zero).
//Input value assumed to be between 0 and 99.
void sPrintI00(int val)
{
    if (val < 10) Serial.print('0');
    Serial.print(val, DEC);
    return;
}

//Print an integer in ":00" format (with leading zero).
//Input value assumed to be between 0 and 99.
void sPrintDigits(int val)
{
    Serial.print(':');
    if(val < 10) Serial.print('0');
    Serial.print(val, DEC);
}

#endif
A ještě, v programu vidím na čtvrtém relé světlo, ale jak se nastavuje, kdy svítí z toho nevyčtu. To už by ale byla třešnička na dortu:-), stačí když se zbavím tý hodiny a se změnou času nebudu trnout, že to pojede špatně.

pettr
Příspěvky: 5
Registrován: 07 led 2020, 09:35
Reputation: 0

Re: Automatické zatváranie kurníku pre sliepky

Příspěvek od pettr » 18 led 2020, 22:04

Tak asi chyba nalezena v Timezone

Kód: Vybrat vše

Timezone myTZ(myDST, myEST);

Mike_cz
Příspěvky: 11
Registrován: 02 říj 2017, 13:15
Reputation: 0

Re: Automatické zatváranie kurníku pre sliepky

Příspěvek od Mike_cz » 25 bře 2020, 18:40

Ahoj,

presne tento kod pouzivam take - a loni jsem ho sem dal (https://www.arduino-forum.cz/viewtopic. ... 8606#p8606). Nicmene, je tam nekde chybka, a nemuzu na ni prijit. Pokud si cas upravite pro sve mesto, tzn. zeditujete sunsetAr[] hodnoty, tak aby odpovidali vasemu casu, tak to nefunguje - i kdyz mam definovany datovy typ LONG pro array, a pak i pro promenne se kterymi se pocita, tak jakmile hodnota v array prekroci 65535(coz je 18hod a 12min) tak zacne pocitat od nuly. Dokazal by s tim nekdo poradit?
P.S.: v zime to bylo v pohode, takze jsem na to zapomnel, ale dneska to zhavarovalo, protoze nastal ten den "D", kdy zaviram pozdeji nez v 18.10 :(
Diky

Uživatelský avatar
pavel1tu
Příspěvky: 2054
Registrován: 26 říj 2017, 08:28
Reputation: 0
Bydliště: Trutnov
Kontaktovat uživatele:

Re: Automatické zatváranie kurníku pre sliepky

Příspěvek od pavel1tu » 25 bře 2020, 20:38

Někde se to blbě přetypovává, ten long se různě používá s int tak jestli to někde není potřeba přetypovat

Ale abych pravdu řekl, s tímto kodem jsem něco strávil - a dost mu nerozumím, dle mne by to šlo udělat jednodušeji, snad.

Nedaří se mi rozchodit 1307RTC modul, abych to mohl testovat, mám jen jeden (používám jiné) a asi je kaput ...
UNO, NANO, Mikro, PRO mini, DUE, ESP32S2, RPi PICO
Pavel1TU
"Správně napsaný kod lze číst jako knihu"

AstroMiK
Příspěvky: 592
Registrován: 08 pro 2017, 19:05
Reputation: 0

Re: Automatické zatváranie kurníku pre sliepky

Příspěvek od AstroMiK » 25 bře 2020, 21:39

Všechny hodnoty v těch polích vyděl 60. Tím se ti pak bez problémů vejdou do "INT".
Časy východů a západů pak nebudou v sekundách, ale v minutách.
O přesnost nepřijdeš, protože originální data v těch polích jsou stejně už zaokrouhlená na celé minuty.
Zároveň ušetříš spoustu místa v ProgMem.

V programu bude nutno upravit nějaké výpočty. Sekundy budeš ignorovat a budeš počítat jen:
minuty od půlnoci = (hodiny * 60) + minuty

a tam, jak se přidává hodina pro letní čas, tak místo přičítání
sunset (sunrise) += secondsPerHour;

bude něco jako
sunset (sunrise) += 60;

Celý program jsem nezkoušel, takže tam možná bude i někde něco dalšího.

Důležitý je, že se zruší ty nesmyslný obrovský sekundový "LONG" čísla a začne se počítat v normálních "INT" minutách.

Mike_cz
Příspěvky: 11
Registrován: 02 říj 2017, 13:15
Reputation: 0

Re: Automatické zatváranie kurníku pre sliepky

Příspěvek od Mike_cz » 26 bře 2020, 08:20

No jo, to me nenapadlo. Jak jednoduche. Diky moc. Uz jsem to upravil, prevedl na minuty, a vse funguje jak ma
jeste jednou diky

Odpovědět

Kdo je online

Uživatelé prohlížející si toto fórum: Žádní registrovaní uživatelé a 14 hostů