4
4
// Global variables use 1,655 bytes (80%) of dynamic memory, leaving 393 bytes for local variables. Maximum is 2,048 bytes.
5
5
6
6
// define hardware connection and hard parameters
7
- #define VERSION 2.2
7
+ #define VERSION 2.3
8
8
#define masterID 0
9
- #define myID 4
9
+ #define myID 15
10
+
11
+ // still not implemented
12
+ #define BUTTON_PIN 2 // / THIS IS ACTUALLY USED BY TEC DIR
13
+
14
+ // bicolor LED (center pin goes to cathode)
15
+ #define GREEN_PIN 3
16
+ #define RED_PIN 4
10
17
11
18
// pin for sensors
12
19
#define optoresistor_PIN 15 // A1
18
25
// #define HUM_PIN 9
19
26
20
27
// pin for PELTIER TEC
21
- #define PELTIER_PWM 6 // what is the frequency of pin 6? pin 9 has a pwm frequency of 490hz
22
- #define PELTIER_DIR 4
28
+ #define PELTIER_PWM 5 // what is the frequency of pin 6? pin 9 has a pwm frequency of 490hz
29
+ #define PELTIER_DIR 2
23
30
24
31
// define hardware and shields used
25
32
#define USE_SENSIRION
26
33
#define USE_RADIO
27
- // #define USE_TEC
34
+ #define USE_TEC
28
35
// #define USE_TEC_PWM
29
36
// #define USE_SD 1 // we do not use SD on regular UNOs because a) we don't need it and b) it takes too much memory
30
- #define LOCAL_SERIAL
37
+ // #define LOCAL_SERIAL
31
38
32
39
#define CMD ' C'
33
40
#define REPORT ' R'
107
114
// External descriptor of data structure
108
115
#include " MyTypes.h"
109
116
117
+ // Experimenting with watchdog
118
+ #include < avr/wdt.h>
119
+
110
120
// Initialising objects and variables
111
121
112
122
unsigned long counter = 0 ;
@@ -122,9 +132,9 @@ configuration cfg = {
122
132
1 , // cfg.dd_mode 0 = DD, 1 = LD, 2 = LL, 3 = DL
123
133
124
134
true , // cfg.send_report
125
- 1 , // cfg.report_delay in minutes
135
+ 5 , // cfg.report_delay in minutes
126
136
127
- 25 .0 , // cfg.set_temp
137
+ 22 .0 , // cfg.set_temp
128
138
65.0 // cfg.set_hum
129
139
};
130
140
@@ -144,12 +154,13 @@ int MIN_SENSOR_PAUSE = 5000; // to avoid self heating of the probe we don't read
144
154
RF24 radio (RADIO_CE, RADIO_CS);
145
155
RF24Network network (radio);
146
156
RF24Mesh mesh (radio, network);
147
- #define MESH_RENEWAL_TIMEOUT 10000 // changing timeout from 60.000 ms to 15 .000ms
157
+ #define MESH_RENEWAL_TIMEOUT 5000 // changing timeout from 60.000 ms to 5 .000ms
148
158
#endif
149
159
150
160
151
161
void setup ()
152
- {
162
+ {
163
+
153
164
Serial.begin (115200 );
154
165
155
166
#if defined(LOCAL_SERIAL)
@@ -158,6 +169,7 @@ void setup()
158
169
159
170
pinMode (LED_PIN, OUTPUT);
160
171
pinMode (optoresistor_PIN, INPUT);
172
+
161
173
162
174
#if defined(USE_DHT)
163
175
dht.setup (HT_PIN);
@@ -194,10 +206,6 @@ void setup()
194
206
195
207
// saveConfiguration(); // Enable this on first update only, then reupload
196
208
setSyncProvider (RTC.get ); // get the time from the RTC
197
-
198
- // time_t artificial_time = 1464715350;
199
- // RTC.set(artificial_time);
200
- // setTime(artificial_time);
201
209
202
210
// Retrieves Lights ON/OFF timer values and last light status
203
211
loadConfiguration ();
@@ -208,6 +216,9 @@ void setup()
208
216
pinMode (PELTIER_PWM, OUTPUT);
209
217
pinMode (PELTIER_DIR, OUTPUT);
210
218
#endif
219
+
220
+ wdt_enable (WDTO_8S);
221
+
211
222
}
212
223
213
224
#if defined(LOCAL_SERIAL)
@@ -293,6 +304,8 @@ void serial_setTemperature(){
293
304
setTemperature (set_TEMP);
294
305
}
295
306
307
+
308
+
296
309
void serial_setHumidity (){
297
310
// set the current Humidity on node
298
311
char *arg;
@@ -354,9 +367,22 @@ void printError(const char *command) {
354
367
355
368
#endif // LOCAL_SERIAL
356
369
370
+ bool lightIsON ()
371
+ {
372
+ return CURRENT_LIGHT > 0 ;
373
+ }
374
+
375
+ bool lightIsOFF ()
376
+ {
377
+ return not lightIsON ();
378
+ }
379
+
380
+
357
381
void loop ()
358
382
{
359
383
384
+ wdt_reset ();
385
+
360
386
#if defined(USE_TEC)
361
387
// we do this continously but the freshness of the getTemperature result is
362
388
// controlled by the MIN_SENSOR_PAUSE variable
@@ -376,18 +402,18 @@ void loop()
376
402
switch (cfg.dd_mode ) {
377
403
378
404
case 0 : // DD
379
- if ( CURRENT_LIGHT > 0 ) { LightsOFF (); }
405
+ if ( lightIsON () ) { LightsOFF (); }
380
406
break ;
381
407
case 1 : // LD
382
- if (CURRENT_LIGHT == 0 && minute_of_the_day >= cfg.lights_on && minute_of_the_day < cfg.lights_off ) { LightsON (); }
383
- if (CURRENT_LIGHT > 0 && minute_of_the_day >= cfg.lights_off ) { LightsOFF (); }
408
+ if (lightIsOFF () && minute_of_the_day >= cfg.lights_on && minute_of_the_day < cfg.lights_off ) { LightsON (); }
409
+ if (lightIsON () && minute_of_the_day >= cfg.lights_off ) { LightsOFF (); }
384
410
break ;
385
411
case 2 : // LL
386
- if ( CURRENT_LIGHT == 0 ) { LightsON (); }
412
+ if ( lightIsOFF () ) { LightsON (); }
387
413
break ;
388
414
case 3 : // DL
389
- if (CURRENT_LIGHT > 0 && minute_of_the_day >= cfg.lights_off && minute_of_the_day < cfg.lights_on ) { LightsOFF (); }
390
- if (CURRENT_LIGHT == 0 && minute_of_the_day >= cfg.lights_on ) { LightsON (); }
415
+ if (lightIsON () && minute_of_the_day >= cfg.lights_off && minute_of_the_day < cfg.lights_on ) { LightsOFF (); }
416
+ if (lightIsOFF () && minute_of_the_day >= cfg.lights_on ) { LightsON (); }
391
417
break ;
392
418
default :
393
419
// do nothing
@@ -437,7 +463,7 @@ void loop()
437
463
fadeToLevel (rcvdPackage.set_light );
438
464
break ;
439
465
case ' F' :
440
- setInterval (rcvdPackage.set_light );
466
+ setTransmissionInterval (rcvdPackage.set_light );
441
467
break ;
442
468
case ' M' :
443
469
setLightMode (rcvdPackage.set_light );
@@ -467,7 +493,9 @@ void loop()
467
493
} // endif network
468
494
#endif // use radio
469
495
496
+ #if defined(LOCAL_SERIAL)
470
497
sCmd .readSerial ();
498
+ #endif
471
499
472
500
} // end of loop
473
501
@@ -524,7 +552,9 @@ void loadConfiguration()
524
552
void saveConfiguration ()
525
553
{
526
554
// saves values to EEPROM
527
- Serial.println (" Saving configuration to memory" );
555
+
556
+ Serial.println (" ==Saving:==" );
557
+ debug ();
528
558
EEPROM.write (0 , 1 );
529
559
EEPROM.put (1 , cfg);
530
560
}
@@ -546,7 +576,7 @@ void setRTCTime(time_t time_rcvd)
546
576
sendDataPackage (EVENT);
547
577
}
548
578
549
- void setInterval (byte interval)
579
+ void setTransmissionInterval (byte interval)
550
580
{
551
581
(interval < 1 ) ? cfg.report_delay = 1 : cfg.report_delay = interval;
552
582
cfg.send_report = ( cfg.report_delay > 0 );
@@ -672,15 +702,16 @@ void sendDataPackage(char header_type){
672
702
dataPackage.set_light = CURRENT_LIGHT;
673
703
674
704
// light timer data
675
- dataPackage.lights_on = cfg.lights_on * 60.0 ; // in seconds
676
- dataPackage.lights_off = cfg.lights_off * 60.0 ; // in seconds
705
+ dataPackage.lights_on = ( cfg.lights_on * 60.0 ) ; // in seconds
706
+ dataPackage.lights_off = ( cfg.lights_off * 60.0 ) ; // in seconds
677
707
dataPackage.dd_mode = cfg.dd_mode ;
678
708
709
+ Serial.println (" ==Sending:==" );
679
710
debug ();
680
711
681
712
#if defined(USE_RADIO)
682
713
Serial.print (F (" RF: " ));
683
- if (!mesh.write ( &dataPackage, ' R ' , sizeof (dataPackage), masterID )){
714
+ if (!mesh.write ( &dataPackage, header_type , sizeof (dataPackage), masterID )){
684
715
Serial.println (F (" FAIL" ));
685
716
} else { Serial.println (" OK" ); }
686
717
#endif
0 commit comments