-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTermostato_Wifi_Caldera_v1.0.ino
1099 lines (875 loc) · 37.1 KB
/
Termostato_Wifi_Caldera_v1.0.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** *
WIFI MANAGER
1. Versión
Autor: Alberto Yebra
Abril 2019
Descripción:
Sistema de calefacción utiliza las siguientes sistemas
Wifi conexión
Conexión con Alexa
Conexión a sensor DHT temperatura
Versión 0.1. añadimos funcion TERMOSTATO
Modo Termostato ON - Automático (Depende de termostato externo)
Termostato OFF - Depende de la variable Calefacción ON (Encendido)
Calefacción OFF (Apagado)
Calefacción ON - Forzado encendemos calefacción y Termostato OFF
Calefacción OFF - Forzado apagamos calefacción y Termostato OFF
FUNCION LOCAL, EN LA MISMA PLACA
1- Dos RELES
2- Pantalla OLED
3- Sensor DHT (Desinstalado)
0.4
Incorpora lectura de temperatura por WEB en 192.168.1.5
0.5
- Change Wifimanage library becasue solve problem when wifi switch off and system was not recovering properly after serveral hours without Router AP Wifi signal
- NTP information
1.0 Primera versión estable instalada Diciembre 2021
nota compilar con la opción
auxmoESP 3.X.X: When using Arduino Core for ESP8266 v2.4.X, double check you are building the project with LwIP Variant set to "v1.4 Higher Bandwidth".
* */
//Librerías para manejar WifiManager
#include "Arduino.h"
#include <cstdlib>
#include <cstring>
#include <ESP8266WiFi.h>
#include <ESPAsyncWebServer.h>
#include <ESPAsyncTCP.h>
#include <WiFiUdp.h>
#include <NTPClient.h>
#include <AsyncElegantOTA.h>
// Replace with your network credentials (STATION)
//const char* ssid = "MOVISTAR_9A76_INV";
//const char* password = "XXXXXXXX";
const char* ssid = "XXXXXXX"; //Your SSID
const char* password = "XXXXXXX";//Your Password
#include <DNSServer.h>
//Librería para el parapadeo del led
#include <Ticker.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include "fauxmoESP.h"
#include "DHT.h"
#include <EEPROM.h>
//#include <ESP8266WebServer-impl.h>
//#include <Parsing-impl.h>
//#include <ESP8266WebServer.h>
//#include <Uri.h>
//#include <ESP8266WebServerSecure.h>
#include <Adafruit_Sensor.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <stdint.h>
//Humedity DHT22
#define DHTPIN 13 //(GPI1 13 - (D7)
#define DHTTYPE DHT22
/*Incluimos Blynk parametros*/
#include "BlynkSimpleEsp8266.h"
//OLED
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
//#define OLED_RESET LED_BUILTIN
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "XXXXXXXXXXXXXXXXXXX";
// Initialize the OLED display using Wire library
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); //D2=SDK D1=SCK As per labeling on NodeMCU
//Server para OTA
AsyncWebServer server(8080);
//Alexa Device (For Rely)
fauxmoESP fauxmo;
bool estadoDispositivos[7] = {false, false, false, false, false, false, false};
#define DISPOSITIVO_1 "Calefaccion"
#define DISPOSITIVO_2 "Termostato"
//Broker MQTT , Mosquito Server is installed in Raspberry
//const char* mqtt_server = "broker.mqtt-dashboard.com";
//const char* mqtt_server = "192.168.1.15";
int ContadorError = 0;
int ContadorhttpResponseCode_11 = 0; //Para reiniciar en caso de errores de comunicación
int ForzarPorComunicaciones = 0; //Variable para indicar que se ha Forzado el Termostato pared por pérdida de comunicacion
// Temperture-Consigna and histeresis variable
float Consigna ;
float Histe = 0.3;
boolean Calefaccion; //Variable que nos indica como está la calefacción
boolean CalefaccionF; //Variable para ver si forzamos la calefacción
boolean Termostato; //Variable que nos indica si el termostato está habilitado o apagado
boolean Modo;
//Modo es un boolean que:
// True. Significa en modo Calefacción - Calefacction is working
// False. Significa que está en reposo, lo que implica que funcionará en modo bypass hacia el termostato local - Bypass with Actual Temperture device
const char* serverNameTemp = "http://192.168.1.5/temperature";
const char* serverSetting = "http://192.168.1.5/setting";
String temperatureWEB;
String SettingWEB;
// Temporizador
unsigned long marcaTiempoDate = 0;
unsigned long tiempoRefreshDate = 1000;
// Variables almacena tiempo millis
int dias;
int horas;
int minutos;
int segundos;
// Cadena para almacenar texto formateado
char cadenaTiempo[16];
DHT dht(DHTPIN, DHTTYPE);
WiFiClient espClient;
//PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;
float t_ant = 0.0; //Variable que toma la medida de temperatura por si hubiera algún problema de medida previo, y seguir mostrando la anterior al fallo
struct MyStructEE {
float E_Consigna;
float E_Histeresis;
boolean E_Termostato;
boolean E_CalefaccionF; //Pulsador de calefacción, cuando está encendido dependiendo de la temperatura se acciona el quemador o no
};
//Define la Struct que contiene la información que vamos a representar en la pantalla OLED
struct StructOLED {
char cadenaTiempo[16];
float temperatura;
float consigna;
boolean quemador; //Indica si en estos momentos tenemos el quemador activado
int Secuencia_Quemador; //Para realizar la animacion
boolean termostato_pared; //Indica si el termostato de la pared está a ÓN
boolean calefaccion; //Indica si tenemos la calefacción habilitada
boolean mostrar_comunicacion; //Para indicar que hay un mensaje nuevo
char comunicaciones[25]; //Informacion sobre el estado de las comunicaciones
};
MyStructEE DatosEE;
StructOLED DatosOLED;
Ticker ticker;
// Pin LED azul
byte pinLed = 4;
static const unsigned char PROGMEM image_portada[8192] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x1f, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x7f, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 0xff, 0xff, 0xff, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0x0f, 0xff, 0xfc, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfe, 0x73, 0xe7, 0xff, 0xe3, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfe, 0xe7, 0xf7, 0xff, 0xef, 0xc7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfe, 0xef, 0xf7, 0xff, 0xee, 0x97, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfd, 0xef, 0xf7, 0xff, 0xef, 0xb7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfd, 0xe7, 0xe7, 0xff, 0xef, 0xb3, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfd, 0xef, 0xef, 0xff, 0xef, 0x3b, 0xff, 0xff, 0xff, 0xcf, 0xf0, 0x0f,
0xff, 0xff, 0xff, 0xff, 0xfd, 0xe0, 0x1f, 0xff, 0xe7, 0x7b, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x0f,
0xff, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xf0, 0x7b, 0xff, 0xff, 0xfc, 0xff, 0xf0, 0x0f,
0xff, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xfc, 0xff, 0xf0, 0x0f,
0xff, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x0f,
0xff, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x0f,
0xff, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xfb, 0xff, 0xff, 0xf8, 0xff, 0xf0, 0x0f,
0xff, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xf7, 0xf9, 0xff, 0xfb, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xf7, 0xfd, 0xff, 0xfb, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xf3, 0xf9, 0xff, 0xfb, 0xff, 0xff, 0xff, 0xfc, 0x1f, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xf4, 0x05, 0xff, 0xfb, 0xff, 0xff, 0xff, 0xfc, 0x1f, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xf7, 0xfd, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xfc, 0x1f, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xfd, 0xff, 0xf7, 0xff, 0xff, 0xfe, 0x1c, 0x1f, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xfd, 0xff, 0xf7, 0xff, 0xff, 0xfe, 0x1c, 0x1f, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xbf, 0xff, 0xff, 0xff, 0xef, 0xff, 0xff, 0xfe, 0x1f, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0xff, 0xff, 0xff, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xff, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x7f, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xef, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0x83, 0xff, 0xff, 0xff, 0xff, 0xed, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xef, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xbf, 0x47, 0x8e, 0x1d, 0x1e, 0x2d, 0xe1, 0xd1, 0xe2, 0xe1, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xbf, 0x3b, 0x75, 0xec, 0xed, 0xcd, 0xde, 0xce, 0xdc, 0xde, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0x87, 0x7b, 0x7d, 0xed, 0xed, 0xed, 0xde, 0xde, 0xde, 0xde, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xbf, 0x7b, 0x7c, 0x0d, 0xed, 0xed, 0xc0, 0xde, 0xde, 0xde, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xbf, 0x7b, 0x7d, 0xfd, 0xed, 0xed, 0xdf, 0xde, 0xde, 0x5e, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xbf, 0x7b, 0x75, 0xfd, 0xed, 0xcd, 0xdf, 0xde, 0xdc, 0xde, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0x83, 0x7b, 0x8e, 0x0d, 0xee, 0x2d, 0xe0, 0xde, 0xe2, 0xe1, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
static const unsigned char PROGMEM image_data_CalefaccionOFF[1024] = {
0x01, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x0f, 0xf0, 0x1f, 0xc3, 0xf8,
0x01, 0x00, 0x02, 0x0f, 0xf0, 0x1f, 0xc3, 0xf8, 0x01, 0x00, 0x02, 0x30, 0x0c, 0x60, 0x0c, 0x00,
0x01, 0x00, 0x02, 0x30, 0x0c, 0x60, 0x0c, 0x00, 0x01, 0x00, 0x02, 0x30, 0x0c, 0x60, 0x0c, 0x00,
0x01, 0x00, 0x02, 0x30, 0x0c, 0x60, 0x0c, 0x00, 0x01, 0xff, 0xfe, 0x30, 0x0c, 0x7f, 0xcf, 0xf8,
0x01, 0xff, 0xfe, 0x30, 0x0c, 0x7f, 0xcf, 0xf8, 0x01, 0x00, 0x02, 0x30, 0x0c, 0x60, 0x0c, 0x00,
0x01, 0x7f, 0xfa, 0x30, 0x0c, 0x60, 0x0c, 0x00, 0x01, 0x7f, 0xfa, 0x30, 0x0c, 0x60, 0x0c, 0x00,
0x01, 0x7f, 0xfa, 0x30, 0x0c, 0x60, 0x0c, 0x00, 0x01, 0x7f, 0xfa, 0x0f, 0xf0, 0x60, 0x0c, 0x00,
0x01, 0x00, 0x02, 0x0f, 0xf0, 0x60, 0x0c, 0x00, 0x01, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00
};
static const unsigned char PROGMEM image_data_CalefaccionON[1024] = {
0x01, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x03, 0xfc, 0x0c, 0x00, 0xc0,
0x01, 0x7f, 0xfa, 0x03, 0xfc, 0x0c, 0x00, 0xc0, 0x01, 0x7f, 0xfa, 0x0c, 0x03, 0x0f, 0x00, 0xc0,
0x01, 0x7f, 0xfa, 0x0c, 0x03, 0x0f, 0x00, 0xc0, 0x01, 0x7f, 0xfa, 0x0c, 0x03, 0x0c, 0xc0, 0xc0,
0x01, 0x00, 0x02, 0x0c, 0x03, 0x0c, 0xc0, 0xc0, 0x01, 0xff, 0xfe, 0x0c, 0x03, 0x0c, 0x30, 0xc0,
0x01, 0xff, 0xfe, 0x0c, 0x03, 0x0c, 0x30, 0xc0, 0x01, 0x00, 0x02, 0x0c, 0x03, 0x0c, 0x0c, 0xc0,
0x01, 0x00, 0x02, 0x0c, 0x03, 0x0c, 0x0c, 0xc0, 0x01, 0x00, 0x02, 0x0c, 0x03, 0x0c, 0x03, 0xc0,
0x01, 0x00, 0x02, 0x0c, 0x03, 0x0c, 0x03, 0xc0, 0x01, 0x00, 0x02, 0x03, 0xfc, 0x0c, 0x00, 0xc0,
0x01, 0x00, 0x02, 0x03, 0xfc, 0x0c, 0x00, 0xc0, 0x01, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00
};
static const unsigned char PROGMEM image_data_Quemador1[1024] = {
0x00, 0x00, 0xfc, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, 0x3f, 0x73, 0x00, 0x00, 0x00,
0x00, 0x00, 0x81, 0x61, 0x41, 0xbe, 0x00, 0x00, 0x00, 0x00, 0x61, 0xc1, 0x40, 0xa3, 0x00, 0x00,
0x00, 0x06, 0x60, 0x01, 0xc0, 0xe0, 0xc0, 0x00, 0x00, 0x05, 0xc0, 0x00, 0x00, 0x00, 0x40, 0x00,
0x00, 0x06, 0x01, 0x80, 0x0c, 0x80, 0x40, 0x00, 0x00, 0x03, 0xc3, 0xc4, 0x3d, 0xf0, 0x40, 0x00,
0x00, 0x00, 0xc1, 0xcc, 0x3f, 0xf1, 0xc0, 0x00, 0x00, 0x00, 0xc1, 0xfb, 0xff, 0xc3, 0x00, 0x00,
0x00, 0x00, 0xc0, 0x01, 0xef, 0x02, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0xc3, 0x1e, 0x00, 0x00,
0x00, 0x00, 0x30, 0x30, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0xe0, 0xc0, 0x00, 0x00,
0x00, 0x00, 0x1f, 0xed, 0xa1, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc7, 0x1f, 0x00, 0x00, 0x00
};
static const unsigned char PROGMEM image_data_Quemador2[1024] = {
0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x03, 0xf0, 0x00, 0x00, 0x00,
0x00, 0x01, 0x90, 0x73, 0x70, 0x07, 0x80, 0x00, 0x00, 0x06, 0x70, 0xd1, 0x78, 0x07, 0x80, 0x00,
0x00, 0x06, 0x78, 0x93, 0xcc, 0x05, 0x80, 0x00, 0x00, 0x05, 0xc8, 0xb6, 0x0c, 0x1c, 0x80, 0x00,
0x00, 0x06, 0x0c, 0xb4, 0x04, 0xb1, 0x80, 0x00, 0x00, 0x03, 0xcf, 0xdc, 0x35, 0xb1, 0x80, 0x00,
0x00, 0x00, 0xce, 0x8c, 0x3f, 0xfb, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x70, 0x7c, 0x27, 0x00, 0x00,
0x00, 0x00, 0xc0, 0x00, 0x29, 0xcf, 0x00, 0x00, 0x00, 0x01, 0x87, 0xc0, 0x07, 0xfe, 0x00, 0x00,
0x00, 0x03, 0x0c, 0x30, 0x0d, 0xe0, 0x00, 0x00, 0x00, 0x02, 0x0c, 0x38, 0xf8, 0x00, 0x00, 0x00,
0x00, 0x03, 0xef, 0xed, 0xb0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xc7, 0x00, 0x00, 0x00, 0x00
};
static const unsigned char PROGMEM image_data_TermostatoPared [] = {
0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x10, 0xf8, 0x04, 0x70, 0x00, 0x3f, 0xf8, 0x04, 0x10, 0x04, 0x04, 0x50, 0x00, 0x40, 0x04, 0x04,
0x10, 0x04, 0x04, 0x70, 0x00, 0x43, 0x84, 0x04, 0x10, 0x04, 0x04, 0x00, 0x00, 0x40, 0x04, 0x04,
0x10, 0x04, 0x04, 0x00, 0x00, 0x7f, 0xfc, 0x04, 0x10, 0x78, 0x00, 0x00, 0x00, 0x40, 0x04, 0x04,
0x10, 0x80, 0x04, 0x00, 0x00, 0x40, 0x04, 0x04, 0x10, 0x80, 0x04, 0x00, 0x00, 0x41, 0x04, 0x04,
0x10, 0x80, 0x04, 0x00, 0x00, 0x43, 0x84, 0x04, 0x10, 0x80, 0x04, 0x00, 0x00, 0x41, 0x04, 0x04,
0x10, 0x7c, 0x04, 0x00, 0x00, 0x40, 0x04, 0x04, 0x10, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x04,
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc
};
//GESTION DE PETICION HTTP CON PARAMETRO
String serverPeticion = "http://192.168.1.5/temperature?Status=";
int str_len = serverPeticion.length() + 10;
char Peticion_CHAR[50];
// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");
// Variable to save current epoch time
unsigned long epochTime;
// Function that gets current epoch time
unsigned long getTime() {
timeClient.update();
unsigned long now = timeClient.getEpochTime();
return now;
}
unsigned long previousMillis = 0;
unsigned long interval = 30000;
void setup()
{
//NTP init ntp with offset
// Set offset time in seconds to adjust for your timezone, for example:
// GMT +1 = 3600
timeClient.begin();
timeClient.setTimeOffset(3600);
DatosOLED.mostrar_comunicacion = 0; //Inicialmente estamos a 0 en las comunicaciones no mensaje de ESTADO;
DatosOLED.Secuencia_Quemador = 0; //Para visualización iniciamos la variable de animacion;
Serial.begin(115200);
pinMode(D5, OUTPUT); // Initialize the BUILTIN_LED pin as an output --Relé 1
pinMode(D6, OUTPUT); //Relé 2
digitalWrite(D5, HIGH);
digitalWrite(D6, HIGH);
Serial.println("Initializing OLED Display");
Serial.begin(115200);
Serial.println("");
// Modo del pin
pinMode(pinLed, OUTPUT);
//client.setServer(mqtt_server, 1883);//Configuramos el servidor (En este caso nuestra RASP
//client.setCallback(callback);
// Empezamos el temporizador que hará parpadear el LED
ticker.attach(0.2, parpadeoLed);
WiFi.mode(WIFI_AP_STA);
// Set device as a Wi-Fi Station
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Setting as a Wi-Fi Station..");
}
Serial.print("Station IP Address: ");
Serial.println(WiFi.localIP());
Serial.print("Wi-Fi Channel: ");
Serial.println(WiFi.channel());
WiFi.setAutoReconnect(true);
WiFi.persistent(true);
// Eliminamos el temporizador
ticker.detach();
// Apagamos el LED
//digitalWrite(pinLed, HIGH);
//dht.begin();
//LECTURA DE PARÁMETROS DE LA EEPROM
// Consigna
// Histéresis
// Modo
//Leemos los valores de la EEPROM
Leer_EEPROM();
//ALEXA
// Habilitamos la librería para el descubrimiento y cambio de estado
// de los dispositivos
fauxmo.setPort(80); // This is required for gen3 devices
fauxmo.enable(true);
// Damos de alta los diferentes dispositivos y grupos
fauxmo.addDevice(DISPOSITIVO_1); //ID0
fauxmo.addDevice(DISPOSITIVO_2); //ID0
// Decimos cuales van a ser nuestras funciones para obtener estado
// y para establecerlo...
fauxmo.onSetState(establecerEstado);
//fauxmo.onGetState(obtenerEstado);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
display.clearDisplay();
display.invertDisplay(true);
display.fillScreen(0); //Limpiamos la pantalla
display.drawBitmap(0, 0, image_portada, 128, 64, SSD1306_WHITE);
display.display();
delay(3000); // Pause for 2 seconds
//TEXTO CON FUENTE PREDETERMINADA
display.invertDisplay(false);
display.fillScreen(0); //Limpiamos la pantalla
display.setFont(); //Fuente por defecto -si no la hemos cambiado no es necesario seleccionarla
display.setTextSize(1);
display.setTextColor(1, 0);
display.setCursor(0, 0);
display.println("Temperatura");
display.setTextSize(2);
display.print("IKER-ANDER");
display.setTextSize(2);
display.setTextColor(1, 0); //Color invertido
display.setCursor(0, 32);
display.print("Iniciando...");
display.display(); //Refrescamos la pantalla para visualizarlo
Serial.println("Iniciando OLED");
delay(4000);
Blynk.config(auth);
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(200, "text/plain", "Hi! I am ESP8266.");
});
AsyncElegantOTA.begin(&server); // Start ElegantOTA
server.begin();
Serial.println("HTTP server started");
}
void loop() {
AsyncElegantOTA.loop();
String Mensaje;
unsigned long currentMillis = millis();
// if WiFi is down, try reconnecting every CHECK_WIFI_TIME seconds
if ((WiFi.status() != WL_CONNECTED) && (currentMillis - previousMillis >=interval)) {
Serial.print(millis());
Serial.println("Reconnecting to WiFi...");
WiFi.disconnect();
WiFi.begin(ssid, password);
Serial.println(WiFi.localIP());
//Alternatively, you can restart your board
//ESP.restart();
Serial.println(WiFi.RSSI());
previousMillis = currentMillis;
}
// Protección overflow
if (millis() < marcaTiempoDate) {
marcaTiempoDate = millis();
}
// Comprobar is hay que actualizar temperatura
if (millis() - marcaTiempoDate >= tiempoRefreshDate)
{
// Actualizar variables de tiempo
millisToTiempo(millis());
// Componer cadena con la información del tiempo formateada
sprintf(cadenaTiempo, "%02d:%02d:%02d:%02d", timeClient.getDay(), timeClient.getHours(), timeClient.getMinutes(), timeClient.getSeconds());
// Marca de tiempo
marcaTiempoDate = millis();
}
Blynk.run();
fauxmo.handle();
///Parte de lectura
long now = millis();
if (now - lastMsg > 10000) {
lastMsg = now;
++value;
//snprintf (msg, 75, "%d", t);
float h = 0;//dht.readHumidity(); Se mira en remoto
float t = 0;//dht.readTemperature();
//NTP: UPDATE DATE
timeClient.update();
epochTime = getTime();
Serial.print("Epoch Time: ");
Serial.println(epochTime);
if (isnan(h) || isnan(t)) {
Serial.println("Error en la lectura del sensor!\n");
return;
}
//Modificación para la WEB
temperatureWEB = Status_httpGETRequest();
Serial.println("Temperature: " + temperatureWEB);
if ( temperatureWEB == "nan") {
Serial.print("Lectura erronea");
// Componer cadena con la información del tiempo formateada
sprintf(DatosOLED.comunicaciones, "Error 1 de lec de Sensor");
DatosOLED.mostrar_comunicacion = 1; //Encontramos evento de mensaje
temperatureWEB = "0";
}
t = temperatureWEB.toFloat();
Serial.println(t);
if (t < 1.0) {
ContadorError = ContadorError + 1;
Serial.println("Incrementamos contador");
Serial.println(ContadorError);
t = t_ant; //Actualizamos al valor anterior para no perderlo
sprintf(DatosOLED.comunicaciones, "Error n del Sensor");
DatosOLED.mostrar_comunicacion = 1; //Encontramos evento de mensaje
} else {
ContadorError = 0;
t_ant = t;
//En el caso de recuperar la comunicacion y estando en termosta pared deshabilitado volveriamos a deshabilitar el termostato pared
if (ForzarPorComunicaciones == 1) { //
DatosEE.E_Termostato = 0; //Volvemos a deshabilitar el Termostato Pared por haber sido deshabilitado por pérdida de comunicacion
Blynk.virtualWrite(V1, LOW);
ForzarPorComunicaciones = 0;
}
}
Serial.println("Contador de errores de lectura: " + ContadorError);
//Lectura para Blynk
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
Serial.print(" Humedad: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperatura: ");
Serial.print(t);
Serial.print(" *C \n");
sprintf(DatosOLED.cadenaTiempo, cadenaTiempo);
DatosOLED.temperatura = t;
Serial.print(" Calefaccion");
Serial.print(Calefaccion);
Serial.print(" CalefaccionF");
Serial.print(CalefaccionF);
Serial.print(" Consigna");
Serial.print(Consigna);
Serial.print(" Histeresis");
Serial.print(Histe);
Serial.print("Modo");
Serial.print(Modo);
if (ContadorError > 50) { //En el caso que tengamos más de 10 lecturas erróneas forzamos el termostato a 0
DatosEE.E_Termostato = 1;
ForzarPorComunicaciones = 1;
Blynk.virtualWrite(V1, HIGH);
Serial.println("Debido a errores habiltamos termostato");
DatosOLED.mostrar_comunicacion = 1; //Encontramos evento de mensaje
sprintf(DatosOLED.comunicaciones, "Pasamos a termostato Pared");
t_ant = 0.0; //Aquí damos la lectura ya por mala y ponemos 0 así se representará siempre cero
}
if (DatosEE.E_Termostato == 0) {
//Termostato apagado , Miramos si tenemos Calefacción Encendida o apagada
if (DatosEE.E_CalefaccionF == 1) {
Serial.println("Calefacción on");
Serial.print(t);
Serial.print(" ");
Serial.print(Consigna);
if (Modo == 1 && t > Consigna + Histe) {
Serial.println("Apagamos");
Modo = 0;
apagar();
//Mandamos info de apagado
}
if (Modo == 0 && t < Consigna - Histe) {
Serial.println("Encendemos");
encender();
Modo = 1;
}
} else {
//Apagar
apagar();
Serial.print("Apagamos");
Modo = 0;
}
if (Modo == 0) {
apagar();
}
if (Modo == 1) {
encender();
}
} else {//Termostato Pared
Modo = 0;
reposo();
Serial.print(" ********Termostato Pared activado ******** ");
}
}
//Tomamos consigna para OLED
DatosOLED.consigna = round(Consigna);
//Tomamos estado del quemador para OLED
OLED_print();
//delay(2000);
}
// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V1
BLYNK_WRITE(V1) //TERMOSTATO
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
// process received value
if (pinValue == 1) {
DatosEE.E_Termostato = 1;
} else {
DatosEE.E_Termostato = 0;
}
Grabar_EEPROM();
}
//Obtenemos la Consigna
BLYNK_WRITE(V7){ // This function gets called each time something changes on the widget
int value = param.asInt(); // This gets the 'value' of the Widget as an integer
Consigna = (float)value;
DatosEE.E_Consigna = Consigna;
Grabar_EEPROM();
}
BLYNK_WRITE(V2) //calefacción
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
// process received value
if (pinValue == 1) {
DatosEE.E_CalefaccionF = 1;
} else {
DatosEE.E_CalefaccionF = 0;
}
Grabar_EEPROM();
}
//OLED function
void OLED_print() {
//Serial.print("\n OLED:Secuencia_QUEMADOR:");
//Serial.print(DatosOLED.Secuencia_Quemador);
display.clearDisplay();
display.fillScreen(0); //Limpiamos la pantalla
// Dibujar texto tiempo
DatosOLED.Secuencia_Quemador = DatosOLED.Secuencia_Quemador + 1;
if (DatosOLED.Secuencia_Quemador>5000) {
DatosOLED.Secuencia_Quemador= 1000;
}
//SE muestra el menaje una vez recibida una comunicación, después ya el funcionamiento de todo
if (DatosOLED.mostrar_comunicacion == 1) {
DatosOLED.mostrar_comunicacion = 0; //Manejo del mensaje
display.setTextSize(2);
display.setCursor(0, 0);
display.println(DatosOLED.comunicaciones);
} else { //Para mostrar el funcionamiento normal
//Bloque 1
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(DatosOLED.cadenaTiempo);
//Bloque 2
display.setTextSize(2);
display.setCursor(0, 16);
display.println(DatosOLED.temperatura, 1);
//display.cp437(true);
//display.write(167);
//display.println("C");
// Bloque 3
display.setTextSize(2);
display.setCursor(70, 0);
display.println(DatosOLED.consigna, 1);
//display.cp437(true);
//display.write(167);
//display.println("C");
// Bloque 4
//Serial.print("\n OLED:Quemador:");
//Serial.print(DatosOLED.quemador);
if (DatosOLED.quemador == 1) {
if (DatosOLED.Secuencia_Quemador == 1) {
display.drawBitmap(64, 16, image_data_Quemador1, 64, 16, SSD1306_WHITE);
} else {
DatosOLED.Secuencia_Quemador = 0;
display.drawBitmap(64, 16, image_data_Quemador2, 64, 16, SSD1306_WHITE);
}
}
// Bloque 5
//Serial.println("DatosOLED.termostato_pared");
//Serial.println(DatosOLED.termostato_pared);
//Serial.print("\n OLED:Termostato:");
//Serial.print(DatosEE.E_Termostato);
if (DatosEE.E_Termostato == 1) {
//display.fillCircle(16,48 , 8, SSD1306_WHITE);
display.drawBitmap(0, 40, image_data_TermostatoPared, 64, 16, SSD1306_WHITE);
}//else display.drawCircle(16, 48, 8, SSD1306_WHITE);
// Bloque 6
//Serial.print("\n OLED:Calefaccion:");
//Serial.print(DatosEE.E_CalefaccionF);
if (DatosEE.E_CalefaccionF == 1) {
display.drawBitmap(64, 40, image_data_CalefaccionON, 64, 16, SSD1306_WHITE);
} else display.drawBitmap(64, 40, image_data_CalefaccionOFF, 64, 16, SSD1306_WHITE);
//display.drawCircle(96, 64, 8, SSD1306_WHITE);
// Bloque 7
display.setTextSize(1);
display.setCursor(0, 56);
display.println(DatosOLED.comunicaciones);
//Limpiamos el buffer una vez mostrada una vez mostrada en el display
sprintf(DatosOLED.comunicaciones, "");
}
display.display();
}
//Esta función se invoca cada vez que viene un mensaje nuevo
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
//Distinguimos
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
if (strcmp(topic, "casa/consigna") == 0) { //Formato de envío 23.4
Serial.println("RECIBIDO CONSIGNA");
char temperatura[4];
temperatura[0] = (char)payload[0];
temperatura[1] = (char)payload[1];
temperatura[2] = (char)payload[2];
temperatura[3] = (char)payload[3];
Consigna = atof(temperatura);
// TemperaturaF=temperatura.toFloat();
Serial.println("Consigna ");
Serial.println(Consigna);
//GRABAMOS EN LA ESTRUCTURA
DatosEE.E_Consigna = Consigna;
Grabar_EEPROM();
}
if (strcmp(topic, "casa/histeresis") == 0) { //Formato de envío 23.4
Serial.println("RECIBIDA histeresis");
char histeresis[2];
histeresis[0] = (char)payload[0];
histeresis[1] = (char)payload[1];
histeresis[2] = (char)payload[2];
histeresis[3] = (char)payload[3];
Histe = atof(histeresis);
// TemperaturaF=temperatura.toFloat();
Serial.println("Hiteresis ");
Serial.println(Histe);
DatosEE.E_Histeresis = Histe;
Grabar_EEPROM();
}
if (strcmp(topic, "casa/modo") == 0) { //Formato de envío 23.4
Serial.println("RECIBIDO Modo");
//Primer dígito indica el Modo (0 si es modo Termostato Local 1 si es Termostato Automático gestionado por ESP)
//Segundo dígito indica el Calefaccion (0 Forzado a apagar 1 Forzado a encender)
if ((char)payload[0] == '0') {
// Modo Termostato local
DatosEE.E_Termostato = 0;
Modo = 0;
Serial.println("Termostato local activado");
}
if ((char)payload[0] == '1') {
// Modo Termostato ESP
DatosEE.E_Termostato = 1;
Modo = 1;
Serial.println("Termostato ESP8266 activado");
}
if ((char)payload[1] == '0') {
// Modo Forzado apagado
DatosEE.E_CalefaccionF = 0;
CalefaccionF = 0;
Serial.println("Forzamos OFF de calefacción");
}
if ((char)payload[1] == '1') {
// Modo Forzado encendido
DatosEE.E_CalefaccionF = 1;
CalefaccionF = 1;
Serial.println("Forzamos ON de calefacción");
}
Grabar_EEPROM();
Leer_EEPROM();
}
}
void parpadeoLed() {
// Cambiar de estado el LED
byte estado = digitalRead(pinLed);
digitalWrite(pinLed, !estado);
}
void encender() {
//FUNCION PARA ENCENDER CALEFFACION (TERMOSTATO OFF)
digitalWrite(D5, LOW);
digitalWrite(D6, LOW);
DatosOLED.quemador = 1;
DatosOLED.termostato_pared = 0;
}
void apagar() {
//FUNCION PARA APAGAR CALEFACCION (TERMOSTATO OFF)
digitalWrite(D5, LOW);
digitalWrite(D6, HIGH);
DatosOLED.quemador = 0;
DatosOLED.termostato_pared = 0;
}
void reposo() {
//FUNCION PARA APAGAR CALEFACCION (TERMOSTATO ON)
digitalWrite(D5, HIGH);
digitalWrite(D6, HIGH);
DatosOLED.quemador = 0;
DatosOLED.termostato_pared = 1;
}
void Grabar_EEPROM() {
//FUNCION PARA APAGAR CALEFACCION
int eeAddress = 0;
//eeAddress += sizeof(MyStructEE);
EEPROM.begin( sizeof(MyStructEE) );
EEPROM.put( eeAddress, DatosEE );
//EEPROM.write(eeAddress,DatosEE );
EEPROM.end();
Serial.println( "Estructura grabada: " );
Serial.println( DatosEE.E_Consigna );
Serial.println( DatosEE.E_Histeresis );
Serial.println( DatosEE.E_Termostato );
Serial.println( DatosEE.E_CalefaccionF );
//DatosEE.E_Consigna = Consigna;
//EEPROM.update( eeAddress, DatosEE );
}
void Leer_EEPROM() {
int eeAddress = 0; //EEPROM address to start reading from
EEPROM.begin(sizeof(MyStructEE));
EEPROM.get( eeAddress, DatosEE );
//EEPROM.read(DatosEE);
EEPROM.end();
Serial.println( "Estructura leida: " );
Serial.println( DatosEE.E_Consigna );
Serial.println( DatosEE.E_Histeresis );
Serial.println( DatosEE.E_Termostato );
Serial.println( DatosEE.E_CalefaccionF );
Consigna = DatosEE.E_Consigna;
Histe = DatosEE.E_Histeresis;
CalefaccionF = DatosEE.E_CalefaccionF;
//Modo = DatosEE.E_Termostato;
Histe = 0.3;
DatosEE.E_Histeresis= Histe;
}
//ALEXA
bool obtenerEstado(unsigned char idDispositivo, const char * nombreDispositivo) {
return estadoDispositivos[idDispositivo];
}
//ALEXA
void establecerEstado(unsigned char idDispositivo, const char * nombreDispositivo, bool estado, unsigned char value) {
Serial.printf("Dispositivo #%d (%s) estado: %s Valor:%s \n", idDispositivo, nombreDispositivo, estado ? "encendido" : "apagado");
// Establecemos el estado del dispositivo concreto
estadoDispositivos[idDispositivo] = estado;
// En función del dispositivo recibido...
switch (idDispositivo) {
case 0: //Calefaccion
{
if (estado == 1) {
DatosEE.E_CalefaccionF = 1;
Blynk.virtualWrite(V2, HIGH);
} else {
DatosEE.E_CalefaccionF = 0;
Blynk.virtualWrite(V2, LOW);
}
}
break;
case 1://Termostato
{
if (estado == 1) {
DatosEE.E_Termostato = 1;
//DatosOLED.termostato_pared=1;
Blynk.virtualWrite(V1, HIGH);
} else {
DatosEE.E_Termostato = 0;
//DatosOLED.termostato_pared=0;
Blynk.virtualWrite(V1, LOW);
}
}
break;
}
Grabar_EEPROM();