Skip to content

Commit eb0dcab

Browse files
committed
SmartHome v5.0beta4
1 parent 6393059 commit eb0dcab

18 files changed

+3732
-34
lines changed

SmartHome_ESP8266/SmartHome_v50beta4/SmartHome_v50beta4.ino

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
/*
2-
***** SmartHome v5.0 *****
2+
***** SmartHome v5.0beta4 *****
3+
4+
TESTED ON
5+
Arduino: 1.8.7
6+
Core: ESP8266 Community versione 2.4.0
7+
Scheda: Generic ESP8266 Module, 80 MHz, ck, 26 MHz, 40MHz, Flash Mode (tabella sotto), Flash Size (tabella sotto), v2 Prebuilt (MSS=536), Disabled, None, 115200
8+
9+
Nodemcu -> Flash Mode:DIO Flash Size:4M
10+
Electrodragon -> Flash Mode:DIO Flash Size:4M
11+
Hipposwitch -> Flash Mode:DIO Flash Size:4M
12+
GC -> Flash Mode:DIO Flash Size:2M
13+
ESP01 -> Flash Mode:DIO Flash Size:1M
14+
SONOFFDUAL -> Flash Mode:QIO Flash Size:1M
15+
SONOFF 4CH PRO R2 -> Flash Mode:DOUT Flash Size:1M oppure Scheda: ESP8285
16+
Shelly1 -> Flash Mode:DIO Flash Size:2M
17+
18+
GPIO
19+
OUT 1: nodemcu=12 (D6) - ESP01=0 - elctrodragon=12 - hipposwitch=12 - Shelly1=4 - SONOFFDUAL=14 - 4CH PRO=12
20+
OUT 2: nodemcu=13 (D7) - ESP01=2 - elctrodragon=13 - hipposwitch=14 - SONOFFDUAL=15 - 4CH PRO=5
21+
OUT 3: 4CH PRO=4
22+
OUT 4: 4CH PRO=15
23+
IN 1: nodemcu=4 (D2) - ESP01=1 - elctrodragon=4 - hipposwitch=? - Shelly1=5 - SONOFFDUAL=4 - 4CH PRO=0
24+
IN 2: nodemcu=5 (D1) - ESP01=3 - elctrodragon=5 - hipposwitch=? - SONOFFDUAL=5 - 4CH PRO=9
25+
IN 3: 4CH PRO=10
26+
IN 4: 4CH PRO=14
27+
BUILTIN_LED nodemcu=16 - ESP01=4 - SONOFFDUAL=13 - elctrodragon=16 - hipposwitch=15 - Shelly1=16 - 4CH PRO=13
28+
Inversione RELE nodemcu=1 - ESP01=1 - SONOFFDUAL=0 - elctrodragon=0 - hipposwitch=0 - Shelly1=0 - 4CH PRO=0
29+
Inversione Status_LED_GPIO nodemcu=1 - ESP01=1 - SONOFFDUAL=1 - elctrodragon=0 - hipposwitch=0 - Shelly1=1 - 4CH PRO=1
30+
resistenza PullUp verso vcc
31+
resistenza PullDown verso gnd
32+
333
434
Comandi MQTT verso il topic nodo Tapparella:
535
su - alza la Tapparella
@@ -37,7 +67,7 @@
3767
3868
Comandi MQTT verso il topic nodo Sensore:
3969
stato - restituisce lo stato del nodo
40-
70+
4171
Comandi MQTT verso il topic ACK
4272
ack - interroga tutti i nodi presenti
4373
@@ -53,13 +83,12 @@
5383
_ Max 5 nodi Tapparella
5484
_ Max 10 nodi Interruttore
5585
_ Max 10 nodi Impulso
56-
_ Max 2 nodo Termostato
86+
_ Max 1 nodo Termostato
5787
_ Max 10 nodi Temporizzatore
5888
_ Max 10 nodi Sensore
5989
_ Rimappato EEPROM
6090
_ Aggiunto topic di ack di ogni singlolo nodo dove il nodo conferma il proprio cambiamento di stato
6191
_ Eliminato doppio rele in Interruttore, Termostato e Impulso (ora tutti i nodi hanno un solo rele' (tranne naturalmente Tapparella))
62-
_ Momentaneamente rimossa compatibiltàcon i moduli ESP01 serial rele
6392
6493
Changelog v4.5:
6594
_ SONOFF DUAL support
@@ -73,20 +102,6 @@
73102
_ reset giornaliero
74103
_ Bug fix
75104
76-
77-
TESTED ON
78-
Arduino: 1.8.7
79-
Core: ESP8266 Community versione 2.4.0
80-
Scheda: Generic ESP8266 Module, 80 MHz, ck, 26 MHz, 40MHz, Flash Mode (tabella sotto), Flash Size (tabella sotto), v2 Prebuilt (MSS=536), Disabled, None, 115200
81-
82-
Nodemcu -> Flash Mode:DIO Flash Size:4M(1M SPIFFS)
83-
Electrodragon -> Flash Mode:DIO Flash Size:4M(1M SPIFFS)
84-
Hipposwitch -> Flash Mode:DIO Flash Size:4M(1M SPIFFS)
85-
GC -> Flash Mode:DIO Flash Size:2M(1M SPIFFS)
86-
ESP01 -> Flash Mode:DIO Flash Size:1M(256k SPIFFS)
87-
SONOFFDUAL -> Flash Mode:QIO Flash Size:1M(256k SPIFFS)
88-
SONOFF 4CH PRO R2 -> Flash Mode:DOUT Flash Size:1M(256k SPIFFS) oppure Scheda: ESP8285
89-
Shelly1 -> Flash Mode:DIO Flash Size:2M(1M SPIFFS)
90105
*/
91106

92107
#include <TPush.h>
@@ -101,7 +116,7 @@ uint8_t mac[6]; // Variabile MAC ADDRESS
101116
int t = 0; // Variabile per intercettare il rilascio del bottone
102117
unsigned long start_millis;
103118

104-
#define MinFreeHeap 5000
119+
#define MinFreeHeap 5000
105120

106121
TPush TIMER_REFRESH_CONNESSIONE, TIMER_LAMPEGGIO;
107122
TPush TIMER_RESET_GIORNALIERO;
@@ -113,15 +128,15 @@ void setup() {
113128
Check_flash_chip_configuration();
114129
setup_EEPROM();
115130
setup_GPIO();
116-
131+
117132
setup_Tapparella();
118133
setup_Termostato();
119134
setup_Interruttore();
120135
setup_Impulso();
121136
setup_Temporizzatore();
122137
setup_Sensore();
123138
setup_Display();
124-
//setup_NuovoNodo();
139+
//setup_NuovoNodo();
125140

126141
setup_wifi();
127142
setup_web();
1.92 MB
Binary file not shown.
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
/*
2+
SmartHome mappa della EEPROM dell'ESP8266
3+
4+
0 -> SmartHome Tapparella 1 - Tapparella_tempo_max (long 4th byte)
5+
1 -> SmartHome Tapparella 1 - Tapparella_tempo_max (long 3th byte)
6+
2 -> SmartHome Tapparella 1 - Tapparella_tempo_max (long 2nd byte)
7+
3 -> SmartHome Tapparella 1 - Tapparella_tempo_max (long 1st byte)
8+
4 -> SmartHome Tapparella 2 - Tapparella_tempo_max (long 4th byte)
9+
5 -> SmartHome Tapparella 2 - Tapparella_tempo_max (long 3th byte)
10+
6 -> SmartHome Tapparella 2 - Tapparella_tempo_max (long 2nd byte)
11+
7 -> SmartHome Tapparella 2 - Tapparella_tempo_max (long 1st byte)
12+
8 -> SmartHome Tapparella 3 - Tapparella_tempo_max (long 4th byte)
13+
9 -> SmartHome Tapparella 3 - Tapparella_tempo_max (long 3th byte)
14+
10 -> SmartHome Tapparella 3 - Tapparella_tempo_max (long 2nd byte)
15+
11 -> SmartHome Tapparella 3 - Tapparella_tempo_max (long 1st byte)
16+
12 -> SmartHome Tapparella 4 - Tapparella_tempo_max (long 4th byte)
17+
13 -> SmartHome Tapparella 4 - Tapparella_tempo_max (long 3th byte)
18+
14 -> SmartHome Tapparella 4 - Tapparella_tempo_max (long 2nd byte)
19+
15 -> SmartHome Tapparella 4 - Tapparella_tempo_max (long 1st byte)
20+
16 -> SmartHome Tapparella 5 - Tapparella_tempo_max (long 4th byte)
21+
17 -> SmartHome Tapparella 5 - Tapparella_tempo_max (long 3th byte)
22+
18 -> SmartHome Tapparella 5 - Tapparella_tempo_max (long 2nd byte)
23+
19 -> SmartHome Tapparella 5 - Tapparella_tempo_max (long 1st byte)
24+
25+
40 -> SmartHome Tapparella 1 - 1=lock 0=unlock (int 2nd byte)
26+
41 -> SmartHome Tapparella 1 - 1=lock 0=unlock (int 1st byte)
27+
42 -> SmartHome Tapparella 2 - 1=lock 0=unlock (int 2nd byte)
28+
43 -> SmartHome Tapparella 2 - 1=lock 0=unlock (int 1st byte)
29+
44 -> SmartHome Tapparella 3 - 1=lock 0=unlock (int 2nd byte)
30+
45 -> SmartHome Tapparella 3 - 1=lock 0=unlock (int 1st byte)
31+
46 -> SmartHome Tapparella 4 - 1=lock 0=unlock (int 2nd byte)
32+
47 -> SmartHome Tapparella 4 - 1=lock 0=unlock (int 1st byte)
33+
48 -> SmartHome Tapparella 5 - 1=lock 0=unlock (int 2nd byte)
34+
49 -> SmartHome Tapparella 5 - 1=lock 0=unlock (int 1st byte)
35+
36+
100 -> SmartHome Termostato 1 - AUTO 1=AUTO 0=MAN (int 2nd byte)
37+
101 -> SmartHome Termostato 1 - AUTO 1=AUTO 0=MAN (int 1st byte)
38+
102 -> SmartHome Termostato 2 - AUTO 1=AUTO 0=MAN (int 2nd byte)
39+
103 -> SmartHome Termostato 2 - AUTO 1=AUTO 0=MAN (int 1st byte)
40+
104 -> SmartHome Termostato 1 - TERMOSTATO (float 4th byte)
41+
105 -> SmartHome Termostato 1 - TERMOSTATO (float 3th byte)
42+
106 -> SmartHome Termostato 1 - TERMOSTATO (float 2nd byte)
43+
107 -> SmartHome Termostato 1 - TERMOSTATO (float 1st byte)
44+
108 -> SmartHome Termostato 2 - TERMOSTATO (float 4th byte)
45+
109 -> SmartHome Termostato 2 - TERMOSTATO (float 3th byte)
46+
110 -> SmartHome Termostato 2 - TERMOSTATO (float 2nd byte)
47+
111 -> SmartHome Termostato 2 - TERMOSTATO (float 1st byte)
48+
49+
200 -> SmartHome RELE Interruttore 1 (int 2nd byte)
50+
201 -> SmartHome RELE Interruttore 1 (int 1st byte)
51+
202 -> SmartHome RELE Interruttore 2 (int 2nd byte)
52+
203 -> SmartHome RELE Interruttore 2 (int 1st byte)
53+
204 -> SmartHome RELE Interruttore 3 (int 2nd byte)
54+
205 -> SmartHome RELE Interruttore 3 (int 1st byte)
55+
206 -> SmartHome RELE Interruttore 4 (int 2nd byte)
56+
207 -> SmartHome RELE Interruttore 4 (int 1st byte)
57+
208 -> SmartHome RELE Interruttore 5 (int 2nd byte)
58+
209 -> SmartHome RELE Interruttore 5 (int 1st byte)
59+
210 -> SmartHome RELE Interruttore 6 (int 2nd byte)
60+
211 -> SmartHome RELE Interruttore 6 (int 1st byte)
61+
212 -> SmartHome RELE Interruttore 7 (int 2nd byte)
62+
213 -> SmartHome RELE Interruttore 7 (int 1st byte)
63+
214 -> SmartHome RELE Interruttore 8 (int 2nd byte)
64+
215 -> SmartHome RELE Interruttore 8 (int 1st byte)
65+
216 -> SmartHome RELE Interruttore 9 (int 2nd byte)
66+
217 -> SmartHome RELE Interruttore 9 (int 1st byte)
67+
218 -> SmartHome RELE Interruttore 10 (int 2nd byte)
68+
219 -> SmartHome RELE Interruttore 10 (int 1st byte)
69+
70+
250 -> SmartHome valore Dimmer 1 (int 2nd byte)
71+
251 -> SmartHome valore Dimmer 1 (int 1st byte)
72+
252 -> SmartHome valore Dimmer 2 (int 2nd byte)
73+
253 -> SmartHome valore Dimmer 2 (int 1st byte)
74+
254 -> SmartHome valore Dimmer 3 (int 2nd byte)
75+
255 -> SmartHome valore Dimmer 3 (int 1st byte)
76+
256 -> SmartHome valore Dimmer 4 (int 2nd byte)
77+
257 -> SmartHome valore Dimmer 4 (int 1st byte)
78+
258 -> SmartHome valore Dimmer 5 (int 2nd byte)
79+
259 -> SmartHome valore Dimmer 5 (int 1st byte)
80+
260 -> SmartHome valore Dimmer 6 (int 2nd byte)
81+
261 -> SmartHome valore Dimmer 6 (int 1st byte)
82+
262 -> SmartHome valore Dimmer 7 (int 2nd byte)
83+
263 -> SmartHome valore Dimmer 7 (int 1st byte)
84+
264 -> SmartHome valore Dimmer 8 (int 2nd byte)
85+
265 -> SmartHome valore Dimmer 8 (int 1st byte)
86+
266 -> SmartHome valore Dimmer 9 (int 2nd byte)
87+
267 -> SmartHome valore Dimmer 9 (int 1st byte)
88+
268 -> SmartHome valore Dimmer 10 (int 2nd byte)
89+
269 -> SmartHome valore Dimmer 10 (int 1st byte)
90+
91+
300 -> SmartHome Temporizzatore 1 - Temporizzatore_tempo (long 4th byte)
92+
301 -> SmartHome Temporizzatore 1 - Temporizzatore_tempo (long 3th byte)
93+
302 -> SmartHome Temporizzatore 1 - Temporizzatore_tempo (long 2nd byte)
94+
303 -> SmartHome Temporizzatore 1 - Temporizzatore_tempo (long 1st byte)
95+
304 -> SmartHome Temporizzatore 2 - Temporizzatore_tempo (long 4th byte)
96+
305 -> SmartHome Temporizzatore 2 - Temporizzatore_tempo (long 3th byte)
97+
306 -> SmartHome Temporizzatore 2 - Temporizzatore_tempo (long 2nd byte)
98+
307 -> SmartHome Temporizzatore 2 - Temporizzatore_tempo (long 1st byte)
99+
308 -> SmartHome Temporizzatore 3 - Temporizzatore_tempo (long 4th byte)
100+
309 -> SmartHome Temporizzatore 3 - Temporizzatore_tempo (long 3th byte)
101+
310 -> SmartHome Temporizzatore 3 - Temporizzatore_tempo (long 2nd byte)
102+
311 -> SmartHome Temporizzatore 3 - Temporizzatore_tempo (long 1st byte)
103+
312 -> SmartHome Temporizzatore 4 - Temporizzatore_tempo (long 4th byte)
104+
313 -> SmartHome Temporizzatore 4 - Temporizzatore_tempo (long 3th byte)
105+
314 -> SmartHome Temporizzatore 4 - Temporizzatore_tempo (long 2nd byte)
106+
315 -> SmartHome Temporizzatore 4 - Temporizzatore_tempo (long 1st byte)
107+
316 -> SmartHome Temporizzatore 5 - Temporizzatore_tempo (long 4th byte)
108+
317 -> SmartHome Temporizzatore 5 - Temporizzatore_tempo (long 3th byte)
109+
318 -> SmartHome Temporizzatore 5 - Temporizzatore_tempo (long 2nd byte)
110+
319 -> SmartHome Temporizzatore 5 - Temporizzatore_tempo (long 1st byte)
111+
112+
350 -> SmartHome Display 1 riga 1
113+
370 -> SmartHome Display 1 riga 2
114+
390 -> SmartHome Display 1 riga 3
115+
116+
117+
400 -> NFC UID (4 byte)
118+
...
119+
500 ->
120+
*/
121+
122+
#include <EEPROM.h>
123+
124+
void setup_EEPROM() {
125+
// Inizializza EEPROM
126+
Debug_MSG_LN("EEPROM initializing");
127+
Debug_MSG_LN("");
128+
EEPROM.begin(512);
129+
delay(100);
130+
}
131+
132+
void EEPROM_clear_reset() { // Pulisce la EEPROM e resetta l'ESP
133+
EEPROM.begin(512);
134+
// write a 0 to all 512 bytes of the EEPROM
135+
Debug_MSG("EEPROM clear:");
136+
for (int i = 0; i < 512; i++) {
137+
EEPROM.write(i, 0);
138+
Debug_MSG(".");
139+
}
140+
Debug_MSG_LN("");
141+
Debug_MSG_LN("EEPROM CLEARED!");
142+
EEPROM.end();
143+
Debug_MSG_LN("RESET!");
144+
delay(500);
145+
ESP.restart();
146+
}
147+
148+
//This function will write a 4 byte (32bit) long to the eeprom at
149+
//the specified address to address + 3.
150+
void EEPROMWritelong(int address, long value) {
151+
//Decomposition from a long to 4 bytes by using bitshift.
152+
//One = Most significant -> Four = Least significant byte
153+
byte four = (value & 0xFF);
154+
byte three = ((value >> 8) & 0xFF);
155+
byte two = ((value >> 16) & 0xFF);
156+
byte one = ((value >> 24) & 0xFF);
157+
//Write the 4 bytes into the eeprom memory.
158+
EEPROM.write(address, four);
159+
EEPROM.write(address + 1, three);
160+
EEPROM.write(address + 2, two);
161+
EEPROM.write(address + 3, one);
162+
EEPROM.commit();
163+
}
164+
165+
//This function will return a 4 byte (32bit) long from the eeprom
166+
//at the specified address to address + 3.
167+
long EEPROMReadlong(long address) {
168+
//Read the 4 bytes from the eeprom memory.
169+
long four = EEPROM.read(address);
170+
long three = EEPROM.read(address + 1);
171+
long two = EEPROM.read(address + 2);
172+
long one = EEPROM.read(address + 3);
173+
//Return the recomposed long by using bitshift.
174+
return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF);
175+
}
176+
177+
int eepromReadInt(int address) {
178+
int value = 0x0000;
179+
value = value | (EEPROM.read(address) << 8);
180+
value = value | EEPROM.read(address + 1);
181+
return value;
182+
}
183+
184+
void eepromWriteInt(int address, int value) {
185+
EEPROM.write(address, (value >> 8) & 0xFF );
186+
EEPROM.write(address + 1, value & 0xFF);
187+
EEPROM.commit();
188+
}
189+
190+
float eepromReadFloat(int address) {
191+
union u_tag {
192+
byte b[4];
193+
float fval;
194+
} u;
195+
u.b[0] = EEPROM.read(address);
196+
u.b[1] = EEPROM.read(address + 1);
197+
u.b[2] = EEPROM.read(address + 2);
198+
u.b[3] = EEPROM.read(address + 3);
199+
return u.fval;
200+
}
201+
202+
void eepromWriteFloat(int address, float value) {
203+
union u_tag {
204+
byte b[4];
205+
float fval;
206+
} u;
207+
u.fval = value;
208+
EEPROM.write(address , u.b[0]);
209+
EEPROM.write(address + 1, u.b[1]);
210+
EEPROM.write(address + 2, u.b[2]);
211+
EEPROM.write(address + 3, u.b[3]);
212+
}

0 commit comments

Comments
 (0)