| ... | ... |
@@ -8,11 +8,11 @@ |
| 8 | 8 |
#include <ESP8266HTTPClient.h> |
| 9 | 9 |
#include <ESP8266httpUpdate.h> |
| 10 | 10 |
|
| 11 |
-#define DEBUG 0 //0=off 1=on |
|
| 11 |
+#define DEBUG 1 //0=off 1=on |
|
| 12 | 12 |
#define PIR D1 // pinul de date D1 la care se conecteaza PIRul |
| 13 | 13 |
|
| 14 | 14 |
bool ARM,lastPIR; |
| 15 |
-float interval_alarma = 20000; // la ce interval sa trimita notificarile 20 sec = 20000 |
|
| 15 |
+float interval_alarma = 60000; // la ce interval sa trimita notificarile 20 sec = 20000 |
|
| 16 | 16 |
float t_alarma=0; |
| 17 | 17 |
|
| 18 | 18 |
char mqtt_user[9]; //le va lua din FS |
| ... | ... |
@@ -169,6 +169,11 @@ void setup() |
| 169 | 169 |
reconectez(); |
| 170 | 170 |
client.setCallback(getMessage); //setez functia care parseaza mesajele venite prin mqtt |
| 171 | 171 |
|
| 172 |
+ String json = "{\"ARM\":\"";
|
|
| 173 |
+ json += String (ARM); |
|
| 174 |
+ json += "\"}"; |
|
| 175 |
+ client.publish(mqttPIR, json.c_str(),TRUE); |
|
| 176 |
+ |
|
| 172 | 177 |
} |
| 173 | 178 |
|
| 174 | 179 |
void getMessage(char* topic, byte* payload, unsigned int length) {
|
| ... | ... |
@@ -218,7 +223,9 @@ void getMessage(char* topic, byte* payload, unsigned int length) {
|
| 218 | 218 |
String json = "{\"ARM\":\"";
|
| 219 | 219 |
json += String (ARM); |
| 220 | 220 |
json += "\"}"; |
| 221 |
+ #if DEBUG |
|
| 221 | 222 |
Serial.println(json); |
| 223 |
+ #endif |
|
| 222 | 224 |
client.publish(mqttPIR, json.c_str(),TRUE); |
| 223 | 225 |
} |
| 224 | 226 |
|
| ... | ... |
@@ -296,7 +303,7 @@ void loop() |
| 296 | 296 |
if (digitalRead(PIR)==1){ //daca am alarma
|
| 297 | 297 |
if (millis() - t_alarma > interval_alarma){ //daca a trecut timpul de la alarma anterioara
|
| 298 | 298 |
String json = "{\"PIR\":1}";
|
| 299 |
- client.publish(mqttALM, json.c_str(),TRUE); |
|
| 299 |
+ client.publish(mqttALM, json.c_str(),FALSE); |
|
| 300 | 300 |
t_alarma=millis(); |
| 301 | 301 |
#if DEBUG |
| 302 | 302 |
Serial.print("Trimis mqtt alarm:");
|