├── .gitignore ├── Arduino_Base_API └── Arduino_Base_API.ino ├── Conecta_Raspberry └── Conecta_Raspberry.ino ├── Grabar_Datos_Luminosidad ├── Ficheros_Raspberry │ ├── Graba_GET.php │ └── Graba_POST.php ├── Luminosidad_GET │ └── Luminosidad_GET.ino └── Luminosidad_POST │ └── Luminosidad_POST.ino ├── Grabar_Datos_Luminosidad_ESP ├── Ficheros_Raspberry │ ├── Graba_GET.php │ └── Graba_POST.php ├── Luminosidad_GET_ESP │ └── Luminosidad_GET_ESP.ino └── Luminosidad_POST_ESP │ └── Luminosidad_POST_ESP.ino ├── IoT_en_90_Minutos ├── IoT_en_90_Minutos.ino └── secrets2.h ├── LICENSE ├── Montajes Fritzing ├── IoT en 90 minutos.fzz └── IoT en 90 minutos_bb.png ├── README.md ├── data_logger_temperatura_DHCP └── data_logger_temperatura_DHCP.ino ├── mqtt_auth_curso └── mqtt_auth_curso.ino ├── mqtt_esp8266 └── mqtt_esp8266.ino ├── mqtt_temperatura_DHT └── mqtt_temperatura_DHT.ino ├── mqtt_temperatura_suscriptor └── mqtt_temperatura_suscriptor.ino ├── node-red ├── arduino-node-red │ └── arduino-node-red.ino └── node-red.json └── publish_cuenta_atras └── publish_cuenta_atras.ino /.gitignore: -------------------------------------------------------------------------------- 1 | secrets.h -------------------------------------------------------------------------------- /Arduino_Base_API/Arduino_Base_API.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | byte mac[] = { 5 | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xYY //Sustituir YY por el numero de MAC correcto 6 | }; 7 | 8 | EthernetClient client; 9 | String webString = ""; 10 | char url[] = "aemet.es"; //Poner la URL que llama la PAI 11 | char comando[] = ""; //comando de llamada a la API 12 | 13 | void setup() 14 | { 15 | Serial.begin(9600); 16 | Serial.println("Ejemplo de uso de APIs con Arduino, iniciar Arduino para lanzar una nueva llamada a la API"); 17 | String cadenaLeida = ""; 18 | // start the Ethernet connection: 19 | Serial.println("inicializando red..."); 20 | if (Ethernet.begin(mac) == 0) { 21 | Serial.println("Failed to configure Ethernet using DHCP"); 22 | for (;;) 23 | ; 24 | } 25 | else { 26 | Serial.print("IP asignada por DHCP: "); 27 | Serial.println(Ethernet.localIP()); 28 | } 29 | 30 | if (client.connect(url, 80)) { 31 | Serial.println("connected"); 32 | client.println("GET /xml/municipios/localidad_26089.xml HTTP/1.1"); 33 | client.println(); 34 | } 35 | else { 36 | Serial.println("connection failed"); 37 | } 38 | 39 | void loop() 40 | { 41 | if (client.available()) { 42 | char c = client.read(); 43 | webString += c; 44 | Serial.print(c); 45 | } 46 | 47 | if (!client.connected()) { 48 | Serial.println(); 49 | Serial.println("disconnecting."); 50 | client.stop(); 51 | //Serial.println(webString); 52 | for (;;) 53 | ; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Conecta_Raspberry/Conecta_Raspberry.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xYY}; //Sustituir YY por el numero de MAC correcto 6 | 7 | byte ip_raspberrypi[] = {192, 168, 6, Z}; //Sustituir Z por la IP de la Raspberry Pi 8 | 9 | EthernetClient client; 10 | 11 | void setup() 12 | { 13 | Serial.begin(9600); 14 | // start the Ethernet connection: 15 | Serial.println("inicializando red..."); 16 | //Ethernet.begin(mac, ip, DNS, gateway, subnet); 17 | 18 | if (Ethernet.begin(mac) == 0) { 19 | Serial.println("Failed to configure Ethernet using DHCP"); 20 | for (;;) 21 | ; 22 | } 23 | else { 24 | Serial.print("IP asignada por DHCP: "); 25 | Serial.println(Ethernet.localIP()); 26 | } 27 | 28 | delay(1000); 29 | } 30 | 31 | void loop() 32 | { 33 | //Conecto a Raspberry Pi 34 | if (client.connect(ip_raspberrypi, 80)) { 35 | Serial.println("connected"); 36 | client.println("GET /prueba.html HTTP/1.1"); 37 | client.println("Host: miraspberry"); 38 | client.println("Connection: close"); 39 | client.println(); 40 | } 41 | else { 42 | Serial.println("connection failed"); 43 | } 44 | 45 | //Espero respuesta raspberry Pi 46 | while (client.available() == 0) { 47 | //espero 48 | Serial.print("."); 49 | delay(100); 50 | } 51 | 52 | String webString = ""; 53 | 54 | //Leo respuesta Raspberry Pi 55 | do { 56 | char caracter_leido = client.read(); 57 | webString += caracter_leido; 58 | delay(5); 59 | } while (client.available() > 0); 60 | 61 | Serial.print("He recibido de Raspberry Pi: "); 62 | Serial.println(webString); 63 | client.stop(); 64 | 65 | delay(5000); 66 | } 67 | -------------------------------------------------------------------------------- /Grabar_Datos_Luminosidad/Ficheros_Raspberry/Graba_GET.php: -------------------------------------------------------------------------------- 1 | connect_errno) { 19 | echo "Lo sentimos, este sitio web está experimentando problemas."; 20 | echo "Error: Fallo al conectarse a MySQL debido a: \n"; 21 | echo "Errno: " . $mysqli->connect_errno . "\n"; 22 | echo "Error: " . $mysqli->connect_error . "\n"; 23 | exit; 24 | } 25 | 26 | $sql = "INSERT INTO luminosidad (fecha, arduino, IntensidadLuminosa) VALUES (CURRENT_TIMESTAMP, {$arduino}, {$IntensidadLuminosa})"; 27 | 28 | if (!$resultado = $mysqli->query($sql)) { 29 | echo "Lo sentimos, este sitio web está experimentando problemas."; 30 | echo "Error: La ejecución de la consulta falló debido a: \n"; 31 | echo "Query: " . $sql . "\n"; 32 | echo "Errno: " . $mysqli->errno . "\n"; 33 | echo "Error: " . $mysqli->error . "\n"; 34 | exit; 35 | } 36 | 37 | $mysqli->close(); 38 | echo ("GRABADOS"); 39 | ?> 40 | -------------------------------------------------------------------------------- /Grabar_Datos_Luminosidad/Ficheros_Raspberry/Graba_POST.php: -------------------------------------------------------------------------------- 1 | connect_errno) { 19 | echo "Lo sentimos, este sitio web está experimentando problemas."; 20 | echo "Error: Fallo al conectarse a MySQL debido a: \n"; 21 | echo "Errno: " . $mysqli->connect_errno . "\n"; 22 | echo "Error: " . $mysqli->connect_error . "\n"; 23 | exit; 24 | } 25 | 26 | $sql = "INSERT INTO luminosidad (fecha, arduino, IntensidadLuminosa) VALUES (CURRENT_TIMESTAMP, {$arduino}, {$IntensidadLuminosa})"; 27 | 28 | if (!$resultado = $mysqli->query($sql)) { 29 | echo "Lo sentimos, este sitio web está experimentando problemas."; 30 | echo "Error: La ejecución de la consulta falló debido a: \n"; 31 | echo "Query: " . $sql . "\n"; 32 | echo "Errno: " . $mysqli->errno . "\n"; 33 | echo "Error: " . $mysqli->error . "\n"; 34 | exit; 35 | } 36 | 37 | $mysqli->close(); 38 | echo ("GRABADOS"); 39 | ?> 40 | -------------------------------------------------------------------------------- /Grabar_Datos_Luminosidad/Luminosidad_GET/Luminosidad_GET.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define NUM_ARDUINO "X" //Poner en X el número de Arduino 4 | const int LDRPin = A0; 5 | 6 | byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xYY}; //Sustituir YY por el numero de MAC correcto 7 | 8 | byte ip_raspberrypi[] = {192, 168, 6, Z}; //Sustituir Z por la IP de la Raspberry Pi 9 | 10 | EthernetClient client; 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | // start the Ethernet connection: 16 | Serial.println("inicializando red..."); 17 | //Ethernet.begin(mac, ip, DNS, gateway, subnet); 18 | 19 | if (Ethernet.begin(mac) == 0) { 20 | Serial.println("Failed to configure Ethernet using DHCP"); 21 | for (;;) 22 | ; 23 | } 24 | else { 25 | Serial.print("IP asignada por DHCP: "); 26 | Serial.println(Ethernet.localIP()); 27 | } 28 | 29 | delay(1000); 30 | } 31 | 32 | void loop() 33 | { 34 | //Leo datos de luminosidad 35 | int luminosidad = analogRead(LDRPin); 36 | 37 | //Conecto a Raspberry Pi 38 | if (client.connect(ip_raspberrypi, 80)) { 39 | Serial.println("connected"); 40 | client.println("GET /Graba_GET.php?arduino=" + String(NUM_ARDUINO) + "&IntensidadLuminosa=" + String(luminosidad) + " HTTP/1.1"); 41 | client.println("Host: miraspberry"); 42 | client.println("Connection: close"); 43 | client.println(); 44 | } 45 | else { 46 | Serial.println("connection failed"); 47 | } 48 | 49 | //Espero respuesta raspberry Pi 50 | while (client.available() == 0) { 51 | //espero 52 | Serial.print("."); 53 | delay(100); 54 | } 55 | 56 | String webString = ""; 57 | 58 | //Leo respuesta Raspberry Pi 59 | do { 60 | char caracter_leido = client.read(); 61 | webString += caracter_leido; 62 | delay(5); 63 | } while (client.available() > 0); 64 | 65 | Serial.print("He recibido de Raspberry Pi: "); 66 | Serial.println(webString); 67 | client.stop(); 68 | 69 | delay(5000); 70 | } 71 | -------------------------------------------------------------------------------- /Grabar_Datos_Luminosidad/Luminosidad_POST/Luminosidad_POST.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define NUM_ARDUINO "X" //Poner en X el número de Arduino 4 | const int LDRPin = A0; 5 | 6 | byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xYY}; //Sustituir YY por el numero de MAC correcto 7 | 8 | byte ip_raspberrypi[] = {192, 168, 6, Z}; //Sustituir Z por la IP de la Raspberry Pi 9 | 10 | EthernetClient client; 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | // start the Ethernet connection: 16 | Serial.println("inicializando red..."); 17 | //Ethernet.begin(mac, ip, DNS, gateway, subnet); 18 | 19 | if (Ethernet.begin(mac) == 0) { 20 | Serial.println("Failed to configure Ethernet using DHCP"); 21 | for (;;) 22 | ; 23 | } 24 | else { 25 | Serial.print("IP asignada por DHCP: "); 26 | Serial.println(Ethernet.localIP()); 27 | } 28 | 29 | delay(1000); 30 | } 31 | 32 | void loop() 33 | { 34 | //Leo datos de luminosidad 35 | int luminosidad = analogRead(LDRPin); 36 | String post_string = "arduino=" + String(NUM_ARDUINO) + "&IntensidadLuminosa=" + String(luminosidad); 37 | 38 | //Conecto a Raspberry Pi 39 | if (client.connect(ip_raspberrypi, 80)) { 40 | Serial.println("connected"); 41 | client.println("POST /Graba_POST.php HTTP/1.1"); 42 | client.println("Host: miraspberry"); 43 | client.println("Content-Type: application/x-www-form-urlencoded"); 44 | client.println("Connection: close"); 45 | client.print("Content-Length: "); 46 | client.println(post_string.length()); 47 | client.println(""); 48 | client.println(post_string); 49 | client.println(""); 50 | Serial.println("Peticion enviada---->"); 51 | Serial.println("POST /Graba_POST.php HTTP/1.1"); 52 | Serial.println("Host: miraspberry"); 53 | Serial.println("Content-Type: application/x-www-form-urlencoded"); 54 | Serial.println("Connection: close"); 55 | Serial.print("Content-Length: "); 56 | Serial.println(post_string.length()); 57 | Serial.println(""); 58 | Serial.println(post_string); 59 | Serial.println(""); 60 | } 61 | else { 62 | Serial.println("connection failed"); 63 | } 64 | 65 | //Espero respuesta raspberry Pi 66 | while (client.available() == 0) { 67 | //espero 68 | Serial.print("."); 69 | delay(100); 70 | } 71 | 72 | String webString = ""; 73 | 74 | //Leo respuesta Raspberry Pi 75 | do { 76 | char caracter_leido = client.read(); 77 | webString += caracter_leido; 78 | delay(5); 79 | } while (client.available() > 0); 80 | 81 | Serial.print("He recibido de Raspberry Pi: "); 82 | Serial.println(webString); 83 | client.stop(); 84 | 85 | delay(5000); 86 | } 87 | -------------------------------------------------------------------------------- /Grabar_Datos_Luminosidad_ESP/Ficheros_Raspberry/Graba_GET.php: -------------------------------------------------------------------------------- 1 | connect_errno) { 19 | echo "Lo sentimos, este sitio web está experimentando problemas."; 20 | echo "Error: Fallo al conectarse a MySQL debido a: \n"; 21 | echo "Errno: " . $mysqli->connect_errno . "\n"; 22 | echo "Error: " . $mysqli->connect_error . "\n"; 23 | exit; 24 | } 25 | 26 | $sql = "INSERT INTO luminosidad (fecha, arduino, IntensidadLuminosa) VALUES (CURRENT_TIMESTAMP, {$arduino}, {$IntensidadLuminosa})"; 27 | 28 | if (!$resultado = $mysqli->query($sql)) { 29 | echo "Lo sentimos, este sitio web está experimentando problemas."; 30 | echo "Error: La ejecución de la consulta falló debido a: \n"; 31 | echo "Query: " . $sql . "\n"; 32 | echo "Errno: " . $mysqli->errno . "\n"; 33 | echo "Error: " . $mysqli->error . "\n"; 34 | exit; 35 | } 36 | 37 | $mysqli->close(); 38 | echo ("GRABADOS"); 39 | ?> 40 | -------------------------------------------------------------------------------- /Grabar_Datos_Luminosidad_ESP/Ficheros_Raspberry/Graba_POST.php: -------------------------------------------------------------------------------- 1 | connect_errno) { 19 | echo "Lo sentimos, este sitio web está experimentando problemas."; 20 | echo "Error: Fallo al conectarse a MySQL debido a: \n"; 21 | echo "Errno: " . $mysqli->connect_errno . "\n"; 22 | echo "Error: " . $mysqli->connect_error . "\n"; 23 | exit; 24 | } 25 | 26 | $sql = "INSERT INTO luminosidad (fecha, arduino, IntensidadLuminosa) VALUES (CURRENT_TIMESTAMP, {$arduino}, {$IntensidadLuminosa})"; 27 | 28 | if (!$resultado = $mysqli->query($sql)) { 29 | echo "Lo sentimos, este sitio web está experimentando problemas."; 30 | echo "Error: La ejecución de la consulta falló debido a: \n"; 31 | echo "Query: " . $sql . "\n"; 32 | echo "Errno: " . $mysqli->errno . "\n"; 33 | echo "Error: " . $mysqli->error . "\n"; 34 | exit; 35 | } 36 | 37 | $mysqli->close(); 38 | echo ("GRABADOS"); 39 | ?> 40 | -------------------------------------------------------------------------------- /Grabar_Datos_Luminosidad_ESP/Luminosidad_GET_ESP/Luminosidad_GET_ESP.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #define NUM_ARDUINO "X" //Poner en X el número de Arduino 3 | const int LDRPin = A0; 4 | 5 | byte ip_raspberrypi[] = {192, 168, 6, Z}; //Sustituir Z por la IP de la Raspberry Pi 6 | 7 | const char* ssid = "ssid"; 8 | const char* password = "password"; 9 | 10 | WiFiClient client; 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | 16 | Serial.print("Connecting to "); 17 | Serial.println(ssid); 18 | 19 | WiFi.begin(ssid, password); 20 | 21 | while (WiFi.status() != WL_CONNECTED) { 22 | delay(500); 23 | Serial.print("."); 24 | } 25 | 26 | Serial.println(""); 27 | Serial.println("WiFi connected"); 28 | Serial.println("IP address: "); 29 | Serial.println(WiFi.localIP()); 30 | 31 | delay(1000); 32 | } 33 | 34 | void loop() 35 | { 36 | //Leo datos de luminosidad 37 | int luminosidad = analogRead(LDRPin); 38 | 39 | //Conecto a Raspberry Pi 40 | if (client.connect(ip_raspberrypi, 80)) { 41 | Serial.println("connected"); 42 | client.println("GET /Graba_GET.php?arduino=" + String(NUM_ARDUINO) + "&IntensidadLuminosa=" + String(luminosidad) + " HTTP/1.1"); 43 | client.println("Host: miraspberry"); 44 | client.println("Connection: close"); 45 | client.println(); 46 | } 47 | else { 48 | Serial.println("connection failed"); 49 | } 50 | 51 | //Espero respuesta raspberry Pi 52 | while (client.available() == 0) { 53 | //espero 54 | Serial.print("."); 55 | delay(100); 56 | } 57 | 58 | String webString = ""; 59 | 60 | //Leo respuesta Raspberry Pi 61 | do { 62 | char caracter_leido = client.read(); 63 | webString += caracter_leido; 64 | delay(5); 65 | } while (client.available() > 0); 66 | 67 | Serial.print("He recibido de Raspberry Pi: "); 68 | Serial.println(webString); 69 | client.stop(); 70 | 71 | delay(5000); 72 | } 73 | -------------------------------------------------------------------------------- /Grabar_Datos_Luminosidad_ESP/Luminosidad_POST_ESP/Luminosidad_POST_ESP.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #define NUM_ARDUINO "X" //Poner en X el número de Arduino 3 | const int LDRPin = A0; 4 | 5 | byte ip_raspberrypi[] = {192, 168, 6, Z}; //Sustituir Z por la IP de la Raspberry Pi 6 | 7 | const char* ssid = "ssid"; 8 | const char* password = "password"; 9 | 10 | WiFiClient client; 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | 16 | Serial.print("Connecting to "); 17 | Serial.println(ssid); 18 | 19 | WiFi.begin(ssid, password); 20 | 21 | while (WiFi.status() != WL_CONNECTED) { 22 | delay(500); 23 | Serial.print("."); 24 | } 25 | 26 | Serial.println(""); 27 | Serial.println("WiFi connected"); 28 | Serial.println("IP address: "); 29 | Serial.println(WiFi.localIP()); 30 | 31 | delay(1000); 32 | } 33 | 34 | void loop() 35 | { 36 | //Leo datos de luminosidad 37 | int luminosidad = analogRead(LDRPin); 38 | String post_string = "arduino=" + String(NUM_ARDUINO) + "&IntensidadLuminosa=" + String(luminosidad); 39 | 40 | //Conecto a Raspberry Pi 41 | if (client.connect(ip_raspberrypi, 80)) { 42 | Serial.println("connected"); 43 | client.println("POST /Graba_POST.php HTTP/1.1"); 44 | client.println("Host: miraspberry"); 45 | client.println("Content-Type: application/x-www-form-urlencoded"); 46 | client.println("Connection: close"); 47 | client.print("Content-Length: "); 48 | client.println(post_string.length()); 49 | client.println(""); 50 | client.println(post_string); 51 | client.println(""); 52 | Serial.println("Peticion enviada---->"); 53 | Serial.println("POST /Graba_POST.php HTTP/1.1"); 54 | Serial.println("Host: miraspberry"); 55 | Serial.println("Content-Type: application/x-www-form-urlencoded"); 56 | Serial.println("Connection: close"); 57 | Serial.print("Content-Length: "); 58 | Serial.println(post_string.length()); 59 | Serial.println(""); 60 | Serial.println(post_string); 61 | Serial.println(""); 62 | } 63 | else { 64 | Serial.println("connection failed"); 65 | } 66 | 67 | //Espero respuesta raspberry Pi 68 | while (client.available() == 0) { 69 | //espero 70 | Serial.print("."); 71 | delay(100); 72 | } 73 | 74 | String webString = ""; 75 | 76 | //Leo respuesta Raspberry Pi 77 | do { 78 | char caracter_leido = client.read(); 79 | webString += caracter_leido; 80 | delay(5); 81 | } while (client.available() > 0); 82 | 83 | Serial.print("He recibido de Raspberry Pi: "); 84 | Serial.println(webString); 85 | client.stop(); 86 | 87 | delay(5000); 88 | } 89 | -------------------------------------------------------------------------------- /IoT_en_90_Minutos/IoT_en_90_Minutos.ino: -------------------------------------------------------------------------------- 1 | #include "ThingSpeak.h" 2 | #include "secrets2.h" 3 | #include 4 | #include 5 | #include 6 | 7 | char ssid[] = SECRET_SSID; // your network SSID (name) 8 | char pass[] = SECRET_PASS; // your network password 9 | 10 | WiFiClient client; 11 | 12 | unsigned long myChannelNumber = SECRET_CH_ID; 13 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 14 | 15 | // You should get Auth Token in the Blynk App. 16 | // Go to the Project Settings (nut icon). 17 | char auth[] = AUTH_TOKEN; 18 | 19 | int pinDHT11 = D2; 20 | SimpleDHT11 dht11(pinDHT11); 21 | 22 | unsigned long tiempo_envio; 23 | 24 | boolean estado_boton; 25 | 26 | void setup() { 27 | Serial.begin(9600); 28 | 29 | Serial.println("inicializando red..."); 30 | Serial.print("Connecting to "); 31 | Serial.println(SECRET_SSID); 32 | 33 | WiFi.mode(WIFI_STA); 34 | 35 | // Connect or reconnect to WiFi 36 | if (WiFi.status() != WL_CONNECTED) { 37 | Serial.print("Attempting to connect to SSID: "); 38 | Serial.println(SECRET_SSID); 39 | while (WiFi.status() != WL_CONNECTED) { 40 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 41 | Serial.print("."); 42 | delay(5000); 43 | } 44 | Serial.println("\nConnected."); 45 | } 46 | 47 | Serial.println(""); 48 | Serial.println("WiFi connected"); 49 | Serial.println("IP address: "); 50 | Serial.println(WiFi.localIP()); 51 | Serial.println("Iniciando datalogger..."); 52 | 53 | ThingSpeak.begin(client); 54 | Blynk.begin(auth, SECRET_SSID, SECRET_PASS); 55 | 56 | tiempo_envio = millis(); 57 | 58 | pinMode(D4, OUTPUT); //BUILTIN LED 59 | estado_boton = digitalRead(D3); 60 | } 61 | 62 | void loop() { 63 | Blynk.run(); 64 | 65 | // reconnect to WiFi 66 | if (WiFi.status() != WL_CONNECTED) { 67 | Serial.print("Attempting to connect to SSID: "); 68 | Serial.println(SECRET_SSID); 69 | while (WiFi.status() != WL_CONNECTED) { 70 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 71 | Serial.print("."); 72 | delay(5000); 73 | } 74 | Serial.println("\nConnected."); 75 | } 76 | 77 | boolean boton = digitalRead(D3); 78 | if (boton != estado_boton) { 79 | if (boton == HIGH) { 80 | Serial.print("Puerta Abierta"); 81 | grabaEvento(1); 82 | } 83 | else { 84 | Serial.print("Puerta Cerrada"); 85 | grabaEvento(0); 86 | } 87 | estado_boton = boton; 88 | } 89 | 90 | //llamar a grabar datos cada 30 segundos... 91 | if ((millis() - tiempo_envio) > 30000) { 92 | grabaDatos(); 93 | tiempo_envio = millis(); 94 | } 95 | } 96 | 97 | void grabaDatos() { 98 | Serial.println("================================="); 99 | Serial.println("Leyendo DHT11..."); 100 | 101 | // read without samples. 102 | byte temperature = 0; 103 | byte humidity = 0; 104 | int err = SimpleDHTErrSuccess; 105 | if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { 106 | Serial.print("Read DHT11 failed, err="); Serial.println(err); delay(1000); 107 | return; 108 | } 109 | 110 | Serial.print("Sample OK: "); 111 | Serial.print((int)temperature); Serial.print(" *C, "); 112 | Serial.print((int)humidity); Serial.println(" H"); 113 | 114 | ThingSpeak.setField(1, temperature); 115 | ThingSpeak.setField(2, humidity); 116 | 117 | // write to the ThingSpeak channel 118 | int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 119 | if (x == 200) { 120 | Serial.println("Channel update successful."); 121 | } 122 | else { 123 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 124 | } 125 | 126 | //Mando datos a Blynk 127 | Blynk.virtualWrite(V0, temperature); 128 | Blynk.virtualWrite(V1, humidity); 129 | } 130 | 131 | void grabaEvento(int evento) { 132 | Serial.println("================================="); 133 | Serial.println("Mandando Evento..."); 134 | 135 | // write to the ThingSpeak channel 136 | ThingSpeak.setField(3, evento); 137 | int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 138 | if (x == 200) { 139 | Serial.println("Channel update successful."); 140 | } 141 | else { 142 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /IoT_en_90_Minutos/secrets2.h: -------------------------------------------------------------------------------- 1 | // Use this file to store all of the private credentials 2 | // and connection details 3 | 4 | #define SECRET_SSID "MySSID" // replace MySSID with your WiFi network name 5 | #define SECRET_PASS "MyPassword" // replace MyPassword with your WiFi password 6 | 7 | #define SECRET_CH_ID 000000 // replace 0000000 with your channel number 8 | #define SECRET_WRITE_APIKEY "XYZ" // replace XYZ with your channel write API Key 9 | 10 | #define AUTH_TOKEN "ZZZZZZZZZZZ" 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Montajes Fritzing/IoT en 90 minutos.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jecrespo/Curso-IoT-Open-Source/eaec3de8d89f1e2006fd01f9e19b1169f845423a/Montajes Fritzing/IoT en 90 minutos.fzz -------------------------------------------------------------------------------- /Montajes Fritzing/IoT en 90 minutos_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jecrespo/Curso-IoT-Open-Source/eaec3de8d89f1e2006fd01f9e19b1169f845423a/Montajes Fritzing/IoT en 90 minutos_bb.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Curso-IoT-Open-Source 2 | Repositorio Ejercicios del curso “Desarrollo Soluciones IoT con Herramientas Libres” 3 | 4 | Documentación Curso disponible en: 5 | * https://www.aprendiendoarduino.com/cursos/curso-iot-open-source-2018/ 6 | * https://www.aprendiendoarduino.com/cursos/curso-iot-open-source-2019/ 7 | * https://www.aprendiendoarduino.com/cursos/fundamentos-iot-open-source-para-aplicaciones-industriales/ 8 | * https://www.aprendiendoarduino.com/cursos/fundamentos-iot-open-source-para-formacion-profesional/ 9 | -------------------------------------------------------------------------------- /data_logger_temperatura_DHCP/data_logger_temperatura_DHCP.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Timer.h" //Descargar de https://github.com/JChristensen/Timer 4 | 5 | #define NUM_ARDUINO X //Sustituir X por el numero de Arduino correcto 6 | 7 | byte mac[] = {0x90, 0xA2, 0xDA, 0x0F, 0x70, 0xYY}; //Sustituir YY por el numero de MAC correcto 8 | 9 | char url[] = "www.aprendiendoarduino.com"; 10 | 11 | EthernetClient client; 12 | Timer t; 13 | String webString = ""; 14 | 15 | void setup() 16 | { 17 | 18 | Serial.begin(9600); 19 | Serial.println("inicializando red..."); 20 | if (Ethernet.begin(mac) == 0) { 21 | Serial.println("Failed to configure Ethernet using DHCP"); 22 | for (;;) 23 | ; 24 | } 25 | else { 26 | Serial.print("IP asignada por DHCP: "); 27 | Serial.println(Ethernet.localIP()); 28 | } 29 | Serial.println("Iniciando datalogger..."); 30 | delay(1000); 31 | t.every(5000,grabaDatos); 32 | } 33 | 34 | void loop() 35 | { 36 | webString = ""; 37 | t.update(); 38 | if (client.available()) { 39 | Serial.println("Respuesta del Servidor---->"); 40 | while (client.available()){ 41 | char c = client.read(); 42 | webString += c; 43 | } 44 | Serial.println(webString); 45 | if (webString.indexOf("GRABADOS") > 0) Serial.println("Datos guardados correctamente"); 46 | else Serial.println("Error al guardar los datos"); 47 | 48 | client.stop(); 49 | } 50 | } 51 | 52 | void grabaDatos(){ 53 | Serial.println("leyendo temperatura... "); 54 | int sensorVal = analogRead(A0); 55 | Serial.print("Valor Leido: "); 56 | Serial.println(sensorVal); 57 | 58 | Serial.println("connecting to server..."); 59 | if (client.connect(url, 80)) { 60 | Serial.println("connected"); 61 | client.print("GET /servicios/datos/grabaDatos.php?arduino="+(String)NUM_ARDUINO+"&dato="); 62 | client.print(sensorVal); 63 | client.println(" HTTP/1.1"); 64 | client.println("Host: www.aprendiendoarduino.com"); 65 | client.println("Connection: close"); 66 | client.println(); 67 | } 68 | else { 69 | Serial.println("connection failed"); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /mqtt_auth_curso/mqtt_auth_curso.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Basic MQTT example with Authentication 3 | 4 | - connects to an MQTT server, providing username 5 | and password 6 | - publishes "hello world" to the topic "outTopic" 7 | - subscribes to the topic "inTopic" 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | // Update these with values suitable for your network. 15 | byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xYY }; //Sustituir YY por número de puesto 16 | 17 | IPAddress server(192, 168, 6, 72); 18 | 19 | void callback(char* topic, byte* payload, unsigned int length) { 20 | Serial.print("Message arrived ["); 21 | Serial.print(topic); 22 | Serial.print("] "); 23 | for (int i = 0; i < length; i++) { 24 | Serial.print((char)payload[i]); 25 | } 26 | Serial.println(); 27 | } 28 | 29 | EthernetClient ethClient; 30 | PubSubClient client(server, 1883, callback, ethClient); 31 | 32 | void setup() 33 | { 34 | Ethernet.begin(mac); 35 | Serial.begin(9600); 36 | // Note - the default maximum packet size is 128 bytes. If the 37 | // combined length of clientId, username and password exceed this, 38 | // you will need to increase the value of MQTT_MAX_PACKET_SIZE in 39 | // PubSubClient.h 40 | 41 | if (client.connect("arduinoClientXX", "curso_iot", "raspberry")) { //Sustituir XX por número de puesto 42 | client.publish("outTopic", "hello world"); 43 | client.subscribe("inTopic"); 44 | } 45 | } 46 | 47 | void loop() 48 | { 49 | client.loop(); 50 | } 51 | -------------------------------------------------------------------------------- /mqtt_esp8266/mqtt_esp8266.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Basic ESP8266 MQTT example 3 | 4 | This sketch demonstrates the capabilities of the pubsub library in combination 5 | with the ESP8266 board/library. 6 | 7 | It connects to an MQTT server then: 8 | - publishes "hello world" to the topic "outTopic" every two seconds 9 | - subscribes to the topic "inTopic", printing out any messages 10 | it receives. NB - it assumes the received payloads are strings not binary 11 | - If the first character of the topic "inTopic" is an 1, switch ON the ESP Led, 12 | else switch it off 13 | 14 | It will reconnect to the server if the connection is lost using a blocking 15 | reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to 16 | achieve the same result without blocking the main loop. 17 | 18 | To install the ESP8266 board, (using Arduino 1.6.4+): 19 | - Add the following 3rd party board manager under "File -> Preferences -> Additional Boards Manager URLs": 20 | http://arduino.esp8266.com/stable/package_esp8266com_index.json 21 | - Open the "Tools -> Board -> Board Manager" and click install for the ESP8266" 22 | - Select your ESP8266 in "Tools -> Board" 23 | 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | // Update these with values suitable for your network. 30 | 31 | const char* ssid = "........"; 32 | const char* password = "........"; 33 | const char* mqtt_server = "broker.mqtt-dashboard.com"; 34 | const char* mosquitto_user = "curso_iot"; 35 | const char* mosquitto_password = "........"; 36 | 37 | WiFiClient espClient; 38 | PubSubClient client(espClient); 39 | long lastMsg = 0; 40 | char msg[50]; 41 | int value = 0; 42 | 43 | void setup_wifi() { 44 | 45 | delay(10); 46 | // We start by connecting to a WiFi network 47 | Serial.println(); 48 | Serial.print("Connecting to "); 49 | Serial.println(ssid); 50 | 51 | WiFi.begin(ssid, password); 52 | 53 | while (WiFi.status() != WL_CONNECTED) { 54 | delay(500); 55 | Serial.print("."); 56 | } 57 | 58 | randomSeed(micros()); 59 | 60 | Serial.println(""); 61 | Serial.println("WiFi connected"); 62 | Serial.println("IP address: "); 63 | Serial.println(WiFi.localIP()); 64 | } 65 | 66 | void callback(char* topic, byte* payload, unsigned int length) { 67 | Serial.print("Message arrived ["); 68 | Serial.print(topic); 69 | Serial.print("] "); 70 | for (int i = 0; i < length; i++) { 71 | Serial.print((char)payload[i]); 72 | } 73 | Serial.println(); 74 | 75 | // Switch on the LED if an 1 was received as first character 76 | if ((char)payload[0] == '1') { 77 | digitalWrite(BUILTIN_LED, LOW); // Turn the LED on (Note that LOW is the voltage level 78 | // but actually the LED is on; this is because 79 | // it is active low on the ESP-01) 80 | } else { 81 | digitalWrite(BUILTIN_LED, HIGH); // Turn the LED off by making the voltage HIGH 82 | } 83 | 84 | } 85 | 86 | void reconnect() { 87 | // Loop until we're reconnected 88 | while (!client.connected()) { 89 | Serial.print("Attempting MQTT connection..."); 90 | // Create a random client ID 91 | String clientId = "ESP8266Client-"; 92 | clientId += String(random(0xffff), HEX); 93 | // Attempt to connect 94 | if (client.connect(clientId.c_str()),mosquitto_user,mosquitto_password) { 95 | Serial.println("connected"); 96 | // Once connected, publish an announcement... 97 | client.publish("outTopic", "hello world"); 98 | // ... and resubscribe 99 | client.subscribe("inTopic"); 100 | } else { 101 | Serial.print("failed, rc="); 102 | Serial.print(client.state()); 103 | Serial.println(" try again in 5 seconds"); 104 | // Wait 5 seconds before retrying 105 | delay(5000); 106 | } 107 | } 108 | } 109 | 110 | void setup() { 111 | pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output 112 | Serial.begin(115200); 113 | setup_wifi(); 114 | client.setServer(mqtt_server, 1883); 115 | client.setCallback(callback); 116 | } 117 | 118 | void loop() { 119 | 120 | if (!client.connected()) { 121 | reconnect(); 122 | } 123 | client.loop(); 124 | 125 | long now = millis(); 126 | if (now - lastMsg > 2000) { 127 | lastMsg = now; 128 | ++value; 129 | snprintf (msg, 50, "hello world #%ld", value); 130 | Serial.print("Publish message: "); 131 | Serial.println(msg); 132 | client.publish("outTopic", msg); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /mqtt_temperatura_DHT/mqtt_temperatura_DHT.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define DHTPIN 6 7 | #define DHTTYPE DHT11 8 | 9 | // Direccion MAC 10 | byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xYY }; //Sustituir YY por el número de kit 11 | 12 | // IP del servidor 13 | IPAddress mqtt_server(192, 168, X, X); //poner la IP de mosquitto al que conectarse 14 | 15 | // Topic con el que trabajamos 16 | const char* topicNameT = "temperaturaXX/temp"; //Sustituir XX por el número de kit 17 | const char* topicNameH = "temperaturaXX/hum"; //Sustituir XX por el número de kit 18 | 19 | DHT dht(DHTPIN, DHTTYPE); 20 | EthernetClient ethClient; 21 | PubSubClient client(ethClient); 22 | 23 | void setup() 24 | { 25 | Serial.begin(9600); 26 | if (Ethernet.begin(mac) == 0) { 27 | Serial.println("Failed to configure Ethernet using DHCP"); 28 | } 29 | client.setServer(mqtt_server, 1883); 30 | dht.begin(); 31 | } 32 | 33 | void loop() 34 | { 35 | if (client.connected()) { 36 | // Envio 37 | float temp = dht.readTemperature(); 38 | float hum = dht.readHumidity(); 39 | char bufferT[10]; 40 | char bufferH[10]; 41 | dtostrf(temp, 0, 0, bufferT); //solo para Arduinos con MCU AVR https://www.microchip.com/webdoc/AVRLibcReferenceManual/group__avr__stdlib_1ga060c998e77fb5fc0d3168b3ce8771d42.html 42 | client.publish(topicNameT, bufferT); 43 | dtostrf(hum, 0, 0, bufferH); 44 | client.publish(topicNameH, bufferH); 45 | Serial.println("Temperatura: " + String(bufferT) + " Humedad: " + String(bufferH)); 46 | // Tiempo entre envios (en ms) 47 | delay(5000); 48 | } 49 | else { 50 | Serial.print("Connecting ...\n"); 51 | client.connect("arduinoClientXX", "curso_iot", "raspberry"); //Sustituir XX por número de puesto 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /mqtt_temperatura_suscriptor/mqtt_temperatura_suscriptor.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // Direccion MAC 6 | byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xYY }; //Cambiar YY por el número de kit 7 | 8 | // IP del servidor 9 | IPAddress mqtt_server(192, 168, x, x); //Cambiar por la IP del servidor mosquitto 10 | 11 | // Topic con el que trabajamos 12 | const char* topicName = "temperaturaXX/#"; //Sustituir XX por el número del kit a suscribirse 13 | 14 | EthernetClient ethClient; 15 | PubSubClient client(ethClient); 16 | 17 | void callback(char* topic, byte* payload, unsigned int length) { 18 | Serial.print("Message arrived ["); 19 | Serial.print(topic); 20 | Serial.print("] - Longitud Mensaje: "); 21 | Serial.print(length); 22 | Serial.print(" bytes - Mensaje: "); 23 | int i = 0; 24 | for (i = 0; i < length; i++) { 25 | Serial.print((char)payload[i]); 26 | } 27 | Serial.println(); 28 | } 29 | 30 | void setup() 31 | { 32 | Serial.begin(9600); 33 | if (Ethernet.begin(mac) == 0) { 34 | Serial.println("Failed to configure Ethernet using DHCP"); 35 | } 36 | client.setServer(mqtt_server, 1883); 37 | client.setCallback(callback); 38 | } 39 | 40 | void loop() 41 | { 42 | if (!client.connected()) { 43 | Serial.print("Connecting ..."); 44 | if (client.connect("arduinoClientXX", "curso_iot", "raspberry")) { //Sustituir XX por número de puesto 45 | Serial.println("connected"); 46 | client.subscribe(topicName); 47 | } else { 48 | delay(5000); 49 | } 50 | } 51 | // Cliente a la escucha 52 | client.loop(); 53 | } 54 | -------------------------------------------------------------------------------- /node-red/arduino-node-red/arduino-node-red.ino: -------------------------------------------------------------------------------- 1 | /* 2 | demo-mqtt para implementar un sistema de aviso de temperaturas 3 | 4 | El montaje consiste en: 5 | - Arduino Mega 6 | - Ethernet Shield 7 | - Dos sondas DHT22 conectada a los pines 6 y 7 8 | - Un led bicolor (Rojo/Verde) conectado a los pines 22 y 23 9 | 10 | Topics suscritos: 11 | - umbral_1 12 | - umbral_2 13 | 14 | Topics publicados: 15 | - Temp_1 16 | - Temp_2 17 | - Hum_1 18 | - Hum_2 19 | - reconnect 20 | 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include //librería https://github.com/JChristensen/Timer 27 | #include //librería https://github.com/jecrespo/DHTlib 28 | 29 | #define PIN_Sensor_Sonda_1 6 30 | #define PIN_Sensor_Sonda_2 7 31 | #define PIN_LED_1 3 32 | #define PIN_LED_2 4 33 | #define PIN_AVISO 5 34 | 35 | Timer t; 36 | 37 | dht sonda_1; 38 | dht sonda_2; 39 | 40 | unsigned long int anterior = 0; 41 | 42 | // Update these with values suitable for your network. 43 | byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xYY }; 44 | IPAddress server(192, 168, 1, X); 45 | 46 | // Respuesta de los topic a los que me he subscrito en la función reconnect 47 | void callback(char* topic, char* payload, unsigned int length) { 48 | Serial.print("Message arrived ["); 49 | Serial.print(topic); 50 | Serial.print("] "); 51 | for (int i = 0; i < length; i++) { 52 | Serial.print((char)payload[i]); 53 | } 54 | Serial.println(); 55 | payload[length] = '\0'; //Para que pueda convertir correctamente a String 56 | 57 | //analizar el topic y el payload para ejecutar lo necesario con String 58 | String topic_S = topic; 59 | String payload_S = payload; 60 | 61 | if (topic_S == "Alarma_1") { 62 | if (payload_S == "true") { 63 | digitalWrite(PIN_LED_1, HIGH); 64 | } 65 | else 66 | digitalWrite(PIN_LED_1, LOW); 67 | } 68 | 69 | if (topic_S == "Alarma_2") { 70 | if (payload_S == "true") { 71 | digitalWrite(PIN_LED_2, HIGH); 72 | } 73 | else 74 | digitalWrite(PIN_LED_2, LOW); 75 | } 76 | if (topic_S == "Aviso") { 77 | if (payload_S == "ON") { 78 | digitalWrite(PIN_AVISO, HIGH); 79 | } 80 | else 81 | digitalWrite(PIN_AVISO, LOW); 82 | } 83 | } 84 | 85 | EthernetClient ethClient; 86 | PubSubClient client(ethClient); 87 | 88 | // Función reconexión que se ejecuta en el loop si pierdo conexión 89 | // En reconnect también me subscribo a los topics y publico que me he reiniciado 90 | void reconnect() { 91 | // Loop until we're reconnected 92 | while (!client.connected()) { 93 | Serial.print("Attempting MQTT connection..."); 94 | // Attempt to connect 95 | if (client.connect("arduinoClientYY","curso_iot","password")) { 96 | Serial.println("connected"); 97 | // Once connected, publish an announcement... 98 | client.publish("reconnect", "Arduino Connect!!!"); 99 | // ... and resubscribe 100 | client.subscribe("Umbral_1"); 101 | client.subscribe("Umbral_2"); 102 | client.subscribe("Alarma_1"); 103 | client.subscribe("Alarma_2"); 104 | client.subscribe("Aviso"); 105 | } else { 106 | Serial.print("failed, rc="); 107 | Serial.print(client.state()); 108 | Serial.println(" try again in 5 seconds"); 109 | // Wait 5 seconds before retrying 110 | delay(5000); 111 | } 112 | } 113 | } 114 | 115 | // Función que publica cada 10 segundos la temperatura en los topics 116 | void sendTemperatures () { 117 | Serial.println("Send Temperatures..."); 118 | int resultado_1 = sonda_1.read22(PIN_Sensor_Sonda_1); 119 | int resultado_2 = sonda_2.read22(PIN_Sensor_Sonda_2); 120 | if (resultado_1 == DHTLIB_OK) { 121 | char buffer_t[6]; 122 | char buffer_h[6]; 123 | float temperatura_1 = sonda_1.temperature; 124 | float humedad_1 = sonda_1.humidity; 125 | float2char(temperatura_1, buffer_t); 126 | float2char(humedad_1, buffer_h); 127 | Serial.println("-- Sonda 1 --"); 128 | Serial.print(temperatura_1); 129 | Serial.print(" -> "); 130 | Serial.println(buffer_t); 131 | Serial.print(humedad_1); 132 | Serial.print(" -> "); 133 | Serial.println(buffer_h); 134 | client.publish("Temp_1", buffer_t); 135 | client.publish("Hum_1", buffer_h); 136 | } 137 | else { 138 | //publicar en contador, ver si podría se algo como añadir 1 al topic 139 | switch (resultado_1) 140 | { 141 | case DHTLIB_ERROR_CHECKSUM: 142 | Serial.print("Checksum error,\t"); 143 | break; 144 | case DHTLIB_ERROR_TIMEOUT: 145 | Serial.print("Time out error,\t"); 146 | break; 147 | default: 148 | Serial.print("Unknown error,\t"); 149 | break; 150 | } 151 | } 152 | 153 | if (resultado_2 == DHTLIB_OK) { 154 | char buffer_t[6]; 155 | char buffer_h[6]; 156 | float temperatura_2 = sonda_2.temperature; 157 | float humedad_2 = sonda_2.humidity; 158 | float2char(temperatura_2, buffer_t); 159 | float2char(humedad_2, buffer_h); 160 | Serial.println("-- Sonda 2 --"); 161 | Serial.print(temperatura_2); 162 | Serial.print(" -> "); 163 | Serial.println(buffer_t); 164 | Serial.print(humedad_2); 165 | Serial.print(" -> "); 166 | Serial.println(buffer_h); 167 | client.publish("Temp_2", buffer_t); 168 | client.publish("Hum_2", buffer_h); 169 | } 170 | else { 171 | //publicar en contador, ver si podría se algo como añadir 1 al topic 172 | switch (resultado_2) 173 | { 174 | case DHTLIB_ERROR_CHECKSUM: 175 | Serial.println("Checksum error,\t"); 176 | break; 177 | case DHTLIB_ERROR_TIMEOUT: 178 | Serial.println("Time out error,\t"); 179 | break; 180 | default: 181 | Serial.println("Unknown error,\t"); 182 | break; 183 | } 184 | } 185 | } 186 | 187 | void setup() 188 | { 189 | Serial.begin(9600); 190 | pinMode(PIN_LED_1,OUTPUT); 191 | pinMode(PIN_LED_2,OUTPUT); 192 | pinMode(PIN_AVISO,OUTPUT); 193 | 194 | t.every(10000, sendTemperatures); 195 | 196 | client.setServer(server, 1883); 197 | client.setCallback(callback); 198 | 199 | Ethernet.begin(mac); 200 | // Allow the hardware to sort itself out 201 | delay(1500); 202 | } 203 | 204 | void loop() 205 | { 206 | t.update(); 207 | 208 | if (!client.connected()) { 209 | reconnect(); 210 | } 211 | 212 | client.loop(); 213 | } 214 | 215 | int float2char(float number, char* buffer_c) { //Solo para número de 99.99 hasta 0. buffer[6]={'2','6','.','3','5',\0} 216 | if ((number > 99.99) || (number < 0)) 217 | return 0; 218 | 219 | int entero = floor(number); 220 | int decimal = round((number - entero) * 100); 221 | 222 | int decenas = int(floor(entero / 10)); 223 | int unidades = int(floor(entero - (decenas * 10))); 224 | int decimal_1 = int(floor(decimal / 10)); 225 | int decimal_2 = int(floor(decimal - (decimal_1 * 10))); 226 | 227 | //sumo 48 para obtener el código ascii del número 228 | buffer_c[0] = char(decenas + 48); 229 | buffer_c[1] = char(unidades + 48); 230 | buffer_c[2] = '.'; 231 | buffer_c[3] = char(decimal_1 + 48); 232 | buffer_c[4] = char(decimal_2 + 48); 233 | buffer_c[5] = '\0'; 234 | return 1; 235 | } 236 | -------------------------------------------------------------------------------- /node-red/node-red.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "16dd348f.f2594b", 4 | "type": "tab", 5 | "label": "Principal", 6 | "disabled": false, 7 | "info": "#Flujo principal" 8 | }, 9 | { 10 | "id": "5aafcc20.2b1944", 11 | "type": "tab", 12 | "label": "Dashboard Principal", 13 | "disabled": false, 14 | "info": "" 15 | }, 16 | { 17 | "id": "cb7e17dd.f3a1e8", 18 | "type": "tab", 19 | "label": "Dashboard Gráficas", 20 | "disabled": false, 21 | "info": "Toda la lógica para hacer el **Dashboard**" 22 | }, 23 | { 24 | "id": "7362cfa.855473", 25 | "type": "tab", 26 | "label": "Debug", 27 | "disabled": false, 28 | "info": "Hacer debug de diversas variables" 29 | }, 30 | { 31 | "id": "19bf36dd.e910d9", 32 | "type": "subflow", 33 | "name": "Subflow 2", 34 | "info": "Ejemplo que entra un dato y saca dos", 35 | "in": [ 36 | { 37 | "x": 121, 38 | "y": 224, 39 | "wires": [] 40 | } 41 | ], 42 | "out": [ 43 | { 44 | "x": 458, 45 | "y": 335, 46 | "wires": [ 47 | { 48 | "id": "19bf36dd.e910d9", 49 | "port": 0 50 | } 51 | ] 52 | }, 53 | { 54 | "x": 459, 55 | "y": 131, 56 | "wires": [ 57 | { 58 | "id": "19bf36dd.e910d9", 59 | "port": 0 60 | } 61 | ] 62 | } 63 | ] 64 | }, 65 | { 66 | "id": "19511945.9ab8d7", 67 | "type": "mqtt-broker", 68 | "z": "", 69 | "broker": "192.7.0.8", 70 | "port": "1883", 71 | "clientid": "", 72 | "usetls": false, 73 | "compatmode": true, 74 | "keepalive": "60", 75 | "cleansession": true, 76 | "birthTopic": "", 77 | "birthQos": "0", 78 | "birthPayload": "", 79 | "willTopic": "", 80 | "willQos": "0", 81 | "willPayload": "" 82 | }, 83 | { 84 | "id": "beb4d114.5df97", 85 | "type": "ui_group", 86 | "z": "", 87 | "name": "Arduino MQTT demo", 88 | "tab": "e78e3383.cf041", 89 | "disp": true, 90 | "width": "18", 91 | "collapse": false 92 | }, 93 | { 94 | "id": "9317c821.078318", 95 | "type": "ui_base", 96 | "theme": { 97 | "name": "theme-dark", 98 | "lightTheme": { 99 | "default": "#0094CE", 100 | "baseColor": "#0094CE", 101 | "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif", 102 | "edited": true, 103 | "reset": false 104 | }, 105 | "darkTheme": { 106 | "default": "#097479", 107 | "baseColor": "#097479", 108 | "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif", 109 | "edited": true, 110 | "reset": false 111 | }, 112 | "customTheme": { 113 | "name": "Untitled Theme 1", 114 | "default": "#4B7930", 115 | "baseColor": "#4B7930", 116 | "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif" 117 | }, 118 | "themeState": { 119 | "base-color": { 120 | "default": "#097479", 121 | "value": "#097479", 122 | "edited": false 123 | }, 124 | "page-titlebar-backgroundColor": { 125 | "value": "#097479", 126 | "edited": false 127 | }, 128 | "page-backgroundColor": { 129 | "value": "#111111", 130 | "edited": false 131 | }, 132 | "page-sidebar-backgroundColor": { 133 | "value": "#000000", 134 | "edited": false 135 | }, 136 | "group-textColor": { 137 | "value": "#0eb8c0", 138 | "edited": false 139 | }, 140 | "group-borderColor": { 141 | "value": "#555555", 142 | "edited": false 143 | }, 144 | "group-backgroundColor": { 145 | "value": "#333333", 146 | "edited": false 147 | }, 148 | "widget-textColor": { 149 | "value": "#eeeeee", 150 | "edited": false 151 | }, 152 | "widget-backgroundColor": { 153 | "value": "#097479", 154 | "edited": false 155 | }, 156 | "widget-borderColor": { 157 | "value": "#333333", 158 | "edited": false 159 | }, 160 | "base-font": { 161 | "value": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif" 162 | } 163 | } 164 | }, 165 | "site": { 166 | "name": "Node-RED Dashboard", 167 | "hideToolbar": "false", 168 | "allowSwipe": "false", 169 | "allowTempTheme": "true", 170 | "dateFormat": "DD/MM/YYYY", 171 | "sizes": { 172 | "sx": 48, 173 | "sy": 48, 174 | "gx": 6, 175 | "gy": 6, 176 | "cx": 6, 177 | "cy": 6, 178 | "px": 0, 179 | "py": 0 180 | } 181 | } 182 | }, 183 | { 184 | "id": "e78e3383.cf041", 185 | "type": "ui_tab", 186 | "z": "", 187 | "name": "Home", 188 | "icon": "dashboard", 189 | "order": 1 190 | }, 191 | { 192 | "id": "87a6b5c3.019628", 193 | "type": "ui_tab", 194 | "z": "", 195 | "name": "Graficas", 196 | "icon": "dashboard", 197 | "order": 2 198 | }, 199 | { 200 | "id": "f171ed8e.140c2", 201 | "type": "ui_group", 202 | "z": "", 203 | "name": "Sonda 1", 204 | "tab": "87a6b5c3.019628", 205 | "order": 2, 206 | "disp": true, 207 | "width": "6", 208 | "collapse": false 209 | }, 210 | { 211 | "id": "b49deb9b.d50248", 212 | "type": "MySQLdatabase", 213 | "z": "", 214 | "host": "192.7.0.4", 215 | "port": "3306", 216 | "db": "demo-mqtt", 217 | "tz": "" 218 | }, 219 | { 220 | "id": "484d1a65.316dc4", 221 | "type": "ui_group", 222 | "z": "", 223 | "name": "Sonda 2", 224 | "tab": "87a6b5c3.019628", 225 | "order": 2, 226 | "disp": true, 227 | "width": "6", 228 | "collapse": false 229 | }, 230 | { 231 | "id": "4010bd65.8e36e4", 232 | "type": "ui_group", 233 | "z": "", 234 | "name": "Sonda 1", 235 | "tab": "e78e3383.cf041", 236 | "order": 2, 237 | "disp": true, 238 | "width": "6", 239 | "collapse": false 240 | }, 241 | { 242 | "id": "2add410e.699e8e", 243 | "type": "ui_group", 244 | "z": "", 245 | "name": "Sonda 2", 246 | "tab": "e78e3383.cf041", 247 | "order": 3, 248 | "disp": true, 249 | "width": "6", 250 | "collapse": false 251 | }, 252 | { 253 | "id": "14a44092.e1d76f", 254 | "type": "ui_group", 255 | "z": "", 256 | "name": "LED", 257 | "tab": "e78e3383.cf041", 258 | "order": 4, 259 | "disp": true, 260 | "width": "6", 261 | "collapse": false 262 | }, 263 | { 264 | "id": "e954864d.b06f88", 265 | "type": "inject", 266 | "z": "16dd348f.f2594b", 267 | "name": "Temperatura", 268 | "topic": "Temperatura", 269 | "payload": "25.5", 270 | "payloadType": "num", 271 | "repeat": "", 272 | "crontab": "", 273 | "once": false, 274 | "x": 288.7500457763672, 275 | "y": 824.5833282470703, 276 | "wires": [ 277 | [ 278 | "2afedaa9.a5f086" 279 | ] 280 | ] 281 | }, 282 | { 283 | "id": "2afedaa9.a5f086", 284 | "type": "mqtt out", 285 | "z": "16dd348f.f2594b", 286 | "name": "", 287 | "topic": "Temperatura", 288 | "qos": "", 289 | "retain": "", 290 | "broker": "19511945.9ab8d7", 291 | "x": 592.5000457763672, 292 | "y": 824.5833282470703, 293 | "wires": [] 294 | }, 295 | { 296 | "id": "6786f49b.3f508c", 297 | "type": "debug", 298 | "z": "7362cfa.855473", 299 | "name": "", 300 | "active": false, 301 | "console": "false", 302 | "complete": "false", 303 | "x": 510, 304 | "y": 100, 305 | "wires": [] 306 | }, 307 | { 308 | "id": "a6225f81.3c2f7", 309 | "type": "mqtt in", 310 | "z": "7362cfa.855473", 311 | "name": "Hora", 312 | "topic": "Hora", 313 | "qos": "2", 314 | "broker": "19511945.9ab8d7", 315 | "x": 150, 316 | "y": 40, 317 | "wires": [ 318 | [ 319 | "6786f49b.3f508c" 320 | ] 321 | ] 322 | }, 323 | { 324 | "id": "a7adde0f.7e1ea", 325 | "type": "ui_text", 326 | "z": "cb7e17dd.f3a1e8", 327 | "group": "f171ed8e.140c2", 328 | "order": 3, 329 | "width": 0, 330 | "height": 0, 331 | "name": "", 332 | "label": "Temperatura Sonda 1", 333 | "format": "{{msg.payload}}", 334 | "layout": "row-spread", 335 | "x": 440, 336 | "y": 40, 337 | "wires": [] 338 | }, 339 | { 340 | "id": "3f05dbb1.9fa624", 341 | "type": "mqtt in", 342 | "z": "cb7e17dd.f3a1e8", 343 | "name": "Temperatura Sonda 1", 344 | "topic": "Temp_1", 345 | "qos": "2", 346 | "broker": "19511945.9ab8d7", 347 | "x": 181, 348 | "y": 89, 349 | "wires": [ 350 | [ 351 | "a7adde0f.7e1ea", 352 | "4a477754.016d88", 353 | "ab5b1041.a5ba" 354 | ] 355 | ] 356 | }, 357 | { 358 | "id": "7ce78ce9.406604", 359 | "type": "mqtt in", 360 | "z": "7362cfa.855473", 361 | "name": "", 362 | "topic": "Temp_1", 363 | "qos": "2", 364 | "broker": "19511945.9ab8d7", 365 | "x": 150, 366 | "y": 100, 367 | "wires": [ 368 | [ 369 | "6786f49b.3f508c" 370 | ] 371 | ] 372 | }, 373 | { 374 | "id": "57fd8f60.e7015", 375 | "type": "mqtt in", 376 | "z": "7362cfa.855473", 377 | "name": "", 378 | "topic": "reconnect", 379 | "qos": "2", 380 | "broker": "19511945.9ab8d7", 381 | "x": 160, 382 | "y": 340, 383 | "wires": [ 384 | [ 385 | "6786f49b.3f508c" 386 | ] 387 | ] 388 | }, 389 | { 390 | "id": "2c1c34bb.f01dfc", 391 | "type": "mqtt in", 392 | "z": "7362cfa.855473", 393 | "name": "", 394 | "topic": "Temp_2", 395 | "qos": "2", 396 | "broker": "19511945.9ab8d7", 397 | "x": 150, 398 | "y": 160, 399 | "wires": [ 400 | [ 401 | "6786f49b.3f508c" 402 | ] 403 | ] 404 | }, 405 | { 406 | "id": "5fe5c9eb.005658", 407 | "type": "mqtt in", 408 | "z": "7362cfa.855473", 409 | "name": "", 410 | "topic": "Hum_1", 411 | "qos": "2", 412 | "broker": "19511945.9ab8d7", 413 | "x": 150, 414 | "y": 220, 415 | "wires": [ 416 | [ 417 | "6786f49b.3f508c" 418 | ] 419 | ] 420 | }, 421 | { 422 | "id": "b2181db3.cdbca", 423 | "type": "mqtt in", 424 | "z": "7362cfa.855473", 425 | "name": "", 426 | "topic": "Hum_2", 427 | "qos": "2", 428 | "broker": "19511945.9ab8d7", 429 | "x": 150, 430 | "y": 280, 431 | "wires": [ 432 | [ 433 | "6786f49b.3f508c" 434 | ] 435 | ] 436 | }, 437 | { 438 | "id": "85fc1c6d.b2013", 439 | "type": "mqtt in", 440 | "z": "cb7e17dd.f3a1e8", 441 | "name": "Humedad Sonda 1", 442 | "topic": "Hum_1", 443 | "qos": "2", 444 | "broker": "19511945.9ab8d7", 445 | "x": 170, 446 | "y": 160, 447 | "wires": [ 448 | [ 449 | "984de665.496208", 450 | "4a477754.016d88", 451 | "ab5b1041.a5ba" 452 | ] 453 | ] 454 | }, 455 | { 456 | "id": "accf6d08.87be", 457 | "type": "inject", 458 | "z": "5aafcc20.2b1944", 459 | "name": "Hora", 460 | "topic": "", 461 | "payload": "", 462 | "payloadType": "date", 463 | "repeat": "10", 464 | "crontab": "", 465 | "once": true, 466 | "x": 150, 467 | "y": 40, 468 | "wires": [ 469 | [ 470 | "7dedb6c7.65d848" 471 | ] 472 | ] 473 | }, 474 | { 475 | "id": "502f2788.1923a8", 476 | "type": "ui_text", 477 | "z": "5aafcc20.2b1944", 478 | "group": "beb4d114.5df97", 479 | "order": 2, 480 | "width": "0", 481 | "height": "0", 482 | "name": "", 483 | "label": "Hora", 484 | "format": "{{msg.payload}}", 485 | "layout": "row-left", 486 | "x": 570, 487 | "y": 40, 488 | "wires": [] 489 | }, 490 | { 491 | "id": "984de665.496208", 492 | "type": "ui_text", 493 | "z": "cb7e17dd.f3a1e8", 494 | "group": "f171ed8e.140c2", 495 | "order": 4, 496 | "width": 0, 497 | "height": 0, 498 | "name": "", 499 | "label": "Humedad Sonda 1", 500 | "format": "{{msg.payload}}", 501 | "layout": "row-spread", 502 | "x": 430, 503 | "y": 160, 504 | "wires": [] 505 | }, 506 | { 507 | "id": "2b64536e.0e31dc", 508 | "type": "ui_chart", 509 | "z": "cb7e17dd.f3a1e8", 510 | "name": "", 511 | "group": "484d1a65.316dc4", 512 | "order": 2, 513 | "width": 0, 514 | "height": 0, 515 | "label": "Sonda 2 - 1h", 516 | "chartType": "line", 517 | "legend": "true", 518 | "xformat": "HH:mm:ss", 519 | "interpolate": "linear", 520 | "nodata": "", 521 | "dot": false, 522 | "ymin": "", 523 | "ymax": "", 524 | "removeOlder": 1, 525 | "removeOlderPoints": "", 526 | "removeOlderUnit": "3600", 527 | "cutout": 0, 528 | "useOneColor": false, 529 | "colors": [ 530 | "#1f77b4", 531 | "#aec7e8", 532 | "#ff7f0e", 533 | "#2ca02c", 534 | "#98df8a", 535 | "#d62728", 536 | "#ff9896", 537 | "#9467bd", 538 | "#c5b0d5" 539 | ], 540 | "useOldStyle": false, 541 | "x": 410, 542 | "y": 280, 543 | "wires": [ 544 | [], 545 | [] 546 | ] 547 | }, 548 | { 549 | "id": "695f2e74.ae557", 550 | "type": "ui_text", 551 | "z": "cb7e17dd.f3a1e8", 552 | "group": "484d1a65.316dc4", 553 | "order": 3, 554 | "width": 0, 555 | "height": 0, 556 | "name": "", 557 | "label": "Temperatura Sonda 2", 558 | "format": "{{msg.payload}}", 559 | "layout": "row-spread", 560 | "x": 440, 561 | "y": 240, 562 | "wires": [] 563 | }, 564 | { 565 | "id": "bfaf8905.d926d8", 566 | "type": "mqtt in", 567 | "z": "cb7e17dd.f3a1e8", 568 | "name": "Temperatura Sonda 2", 569 | "topic": "Temp_2", 570 | "qos": "2", 571 | "broker": "19511945.9ab8d7", 572 | "x": 180, 573 | "y": 240, 574 | "wires": [ 575 | [ 576 | "2b64536e.0e31dc", 577 | "695f2e74.ae557", 578 | "7958222f.f7a12c" 579 | ] 580 | ] 581 | }, 582 | { 583 | "id": "6d2c5eed.7e89d", 584 | "type": "mqtt in", 585 | "z": "cb7e17dd.f3a1e8", 586 | "name": "Humedad Sonda 2", 587 | "topic": "Hum_2", 588 | "qos": "2", 589 | "broker": "19511945.9ab8d7", 590 | "x": 170, 591 | "y": 300, 592 | "wires": [ 593 | [ 594 | "d085b4ee.8dee58", 595 | "2b64536e.0e31dc", 596 | "7958222f.f7a12c" 597 | ] 598 | ] 599 | }, 600 | { 601 | "id": "d085b4ee.8dee58", 602 | "type": "ui_text", 603 | "z": "cb7e17dd.f3a1e8", 604 | "group": "484d1a65.316dc4", 605 | "order": 4, 606 | "width": 0, 607 | "height": 0, 608 | "name": "", 609 | "label": "Humedad Sonda 2", 610 | "format": "{{msg.payload}}", 611 | "layout": "row-spread", 612 | "x": 430, 613 | "y": 360, 614 | "wires": [] 615 | }, 616 | { 617 | "id": "4a477754.016d88", 618 | "type": "ui_chart", 619 | "z": "cb7e17dd.f3a1e8", 620 | "name": "", 621 | "group": "f171ed8e.140c2", 622 | "order": 2, 623 | "width": 0, 624 | "height": 0, 625 | "label": "Sonda 1 - 1h", 626 | "chartType": "line", 627 | "legend": "true", 628 | "xformat": "HH:mm:ss", 629 | "interpolate": "linear", 630 | "nodata": "", 631 | "dot": false, 632 | "ymin": "", 633 | "ymax": "", 634 | "removeOlder": 1, 635 | "removeOlderPoints": "", 636 | "removeOlderUnit": "3600", 637 | "cutout": 0, 638 | "useOneColor": false, 639 | "colors": [ 640 | "#1f77b4", 641 | "#aec7e8", 642 | "#ff7f0e", 643 | "#2ca02c", 644 | "#98df8a", 645 | "#d62728", 646 | "#ff9896", 647 | "#9467bd", 648 | "#c5b0d5" 649 | ], 650 | "useOldStyle": false, 651 | "x": 410, 652 | "y": 80, 653 | "wires": [ 654 | [], 655 | [] 656 | ] 657 | }, 658 | { 659 | "id": "47ddf2e4.733cbc", 660 | "type": "ui_gauge", 661 | "z": "5aafcc20.2b1944", 662 | "name": "UMBRAL", 663 | "group": "4010bd65.8e36e4", 664 | "order": 2, 665 | "width": 0, 666 | "height": 0, 667 | "gtype": "gage", 668 | "title": "UMBRAL", 669 | "label": "ºC", 670 | "format": "{{value}}", 671 | "min": "10", 672 | "max": "40", 673 | "colors": [ 674 | "#ff0000", 675 | "#008000", 676 | "#ff0000" 677 | ], 678 | "seg1": "20", 679 | "seg2": "26", 680 | "x": 340, 681 | "y": 160, 682 | "wires": [] 683 | }, 684 | { 685 | "id": "92b2de93.e1c24", 686 | "type": "mqtt in", 687 | "z": "5aafcc20.2b1944", 688 | "name": "Umbral sonda 1", 689 | "topic": "Umbral_1", 690 | "qos": "2", 691 | "broker": "19511945.9ab8d7", 692 | "x": 160, 693 | "y": 160, 694 | "wires": [ 695 | [ 696 | "47ddf2e4.733cbc" 697 | ] 698 | ] 699 | }, 700 | { 701 | "id": "cfd94cfb.4ead7", 702 | "type": "mqtt out", 703 | "z": "5aafcc20.2b1944", 704 | "name": "Umbral sonda 1", 705 | "topic": "Umbral_1", 706 | "qos": "", 707 | "retain": "", 708 | "broker": "19511945.9ab8d7", 709 | "x": 360, 710 | "y": 100, 711 | "wires": [] 712 | }, 713 | { 714 | "id": "5b3fd6c8.9648d8", 715 | "type": "ui_slider", 716 | "z": "5aafcc20.2b1944", 717 | "name": "", 718 | "label": "Temperatura", 719 | "group": "4010bd65.8e36e4", 720 | "order": 3, 721 | "width": 0, 722 | "height": 0, 723 | "passthru": false, 724 | "topic": "", 725 | "min": "10", 726 | "max": "40", 727 | "step": 1, 728 | "x": 150, 729 | "y": 100, 730 | "wires": [ 731 | [ 732 | "cfd94cfb.4ead7" 733 | ] 734 | ] 735 | }, 736 | { 737 | "id": "7972a553.9f8f9c", 738 | "type": "ui_gauge", 739 | "z": "5aafcc20.2b1944", 740 | "name": "UMBRAL", 741 | "group": "2add410e.699e8e", 742 | "order": 3, 743 | "width": 0, 744 | "height": 0, 745 | "gtype": "gage", 746 | "title": "UMBRAL", 747 | "label": "ºC", 748 | "format": "{{value}}", 749 | "min": "10", 750 | "max": "40", 751 | "colors": [ 752 | "#ff0000", 753 | "#008000", 754 | "#ff0000" 755 | ], 756 | "seg1": "20", 757 | "seg2": "26", 758 | "x": 340, 759 | "y": 280, 760 | "wires": [] 761 | }, 762 | { 763 | "id": "8a6152f5.2ced2", 764 | "type": "mqtt in", 765 | "z": "5aafcc20.2b1944", 766 | "name": "Umbral sonda 2", 767 | "topic": "Umbral_2", 768 | "qos": "2", 769 | "broker": "19511945.9ab8d7", 770 | "x": 160, 771 | "y": 280, 772 | "wires": [ 773 | [ 774 | "7972a553.9f8f9c" 775 | ] 776 | ] 777 | }, 778 | { 779 | "id": "75084f43.7fa31", 780 | "type": "mqtt out", 781 | "z": "5aafcc20.2b1944", 782 | "name": "Umbral sonda 2", 783 | "topic": "Umbral_2", 784 | "qos": "", 785 | "retain": "", 786 | "broker": "19511945.9ab8d7", 787 | "x": 360, 788 | "y": 220, 789 | "wires": [] 790 | }, 791 | { 792 | "id": "84fcdc8.dbdf02", 793 | "type": "ui_slider", 794 | "z": "5aafcc20.2b1944", 795 | "name": "", 796 | "label": "Temperatura", 797 | "group": "2add410e.699e8e", 798 | "order": 4, 799 | "width": 0, 800 | "height": 0, 801 | "passthru": false, 802 | "topic": "", 803 | "min": "10", 804 | "max": "40", 805 | "step": 1, 806 | "x": 150, 807 | "y": 220, 808 | "wires": [ 809 | [ 810 | "75084f43.7fa31" 811 | ] 812 | ] 813 | }, 814 | { 815 | "id": "35eb13d6.3ede9c", 816 | "type": "ui_template", 817 | "z": "5aafcc20.2b1944", 818 | "group": "beb4d114.5df97", 819 | "name": "", 820 | "order": 1, 821 | "width": 0, 822 | "height": 0, 823 | "format": "
\n

Demo de Arduino con MQTT

", 824 | "storeOutMessages": true, 825 | "fwdInMessages": true, 826 | "templateScope": "local", 827 | "x": 140, 828 | "y": 580, 829 | "wires": [ 830 | [] 831 | ] 832 | }, 833 | { 834 | "id": "ab5b1041.a5ba", 835 | "type": "ui_chart", 836 | "z": "cb7e17dd.f3a1e8", 837 | "name": "Grafica Sonda 1 24h", 838 | "group": "f171ed8e.140c2", 839 | "order": 1, 840 | "width": 0, 841 | "height": 0, 842 | "label": "Sonda 1 - 24h", 843 | "chartType": "line", 844 | "legend": "true", 845 | "xformat": "HH:mm:ss", 846 | "interpolate": "linear", 847 | "nodata": "", 848 | "dot": false, 849 | "ymin": "", 850 | "ymax": "", 851 | "removeOlder": "1", 852 | "removeOlderPoints": "", 853 | "removeOlderUnit": "86400", 854 | "cutout": 0, 855 | "useOneColor": false, 856 | "colors": [ 857 | "#1f77b4", 858 | "#aec7e8", 859 | "#ff7f0e", 860 | "#2ca02c", 861 | "#98df8a", 862 | "#d62728", 863 | "#ff9896", 864 | "#9467bd", 865 | "#c5b0d5" 866 | ], 867 | "useOldStyle": false, 868 | "x": 440, 869 | "y": 120, 870 | "wires": [ 871 | [], 872 | [] 873 | ] 874 | }, 875 | { 876 | "id": "7958222f.f7a12c", 877 | "type": "ui_chart", 878 | "z": "cb7e17dd.f3a1e8", 879 | "name": "Grafica Sonda 2 24h", 880 | "group": "484d1a65.316dc4", 881 | "order": 1, 882 | "width": 0, 883 | "height": 0, 884 | "label": "Sonda 2 - 24h", 885 | "chartType": "line", 886 | "legend": "true", 887 | "xformat": "HH:mm:ss", 888 | "interpolate": "linear", 889 | "nodata": "", 890 | "dot": false, 891 | "ymin": "", 892 | "ymax": "", 893 | "removeOlder": "1", 894 | "removeOlderPoints": "", 895 | "removeOlderUnit": "86400", 896 | "cutout": 0, 897 | "useOneColor": false, 898 | "colors": [ 899 | "#1f77b4", 900 | "#aec7e8", 901 | "#ff7f0e", 902 | "#2ca02c", 903 | "#98df8a", 904 | "#d62728", 905 | "#ff9896", 906 | "#9467bd", 907 | "#c5b0d5" 908 | ], 909 | "useOldStyle": false, 910 | "x": 440, 911 | "y": 320, 912 | "wires": [ 913 | [], 914 | [] 915 | ] 916 | }, 917 | { 918 | "id": "d7890a40.0ff758", 919 | "type": "mqtt in", 920 | "z": "5aafcc20.2b1944", 921 | "name": "", 922 | "topic": "Temp_1", 923 | "qos": "2", 924 | "broker": "19511945.9ab8d7", 925 | "x": 130, 926 | "y": 340, 927 | "wires": [ 928 | [ 929 | "a7ad4e2b.f683e" 930 | ] 931 | ] 932 | }, 933 | { 934 | "id": "a7ad4e2b.f683e", 935 | "type": "ui_gauge", 936 | "z": "5aafcc20.2b1944", 937 | "name": "", 938 | "group": "4010bd65.8e36e4", 939 | "order": 1, 940 | "width": "3", 941 | "height": "3", 942 | "gtype": "donut", 943 | "title": "Temperatura", 944 | "label": "ºC", 945 | "format": "{{value}}", 946 | "min": "10", 947 | "max": "40", 948 | "colors": [ 949 | "#ff0000", 950 | "#008000", 951 | "#ff0000" 952 | ], 953 | "seg1": "20", 954 | "seg2": "26", 955 | "x": 350, 956 | "y": 340, 957 | "wires": [] 958 | }, 959 | { 960 | "id": "4eb5b6ba.748b38", 961 | "type": "mqtt in", 962 | "z": "5aafcc20.2b1944", 963 | "name": "", 964 | "topic": "Hum_1", 965 | "qos": "2", 966 | "broker": "19511945.9ab8d7", 967 | "x": 130, 968 | "y": 400, 969 | "wires": [ 970 | [ 971 | "3046fe91.be81a2" 972 | ] 973 | ] 974 | }, 975 | { 976 | "id": "3046fe91.be81a2", 977 | "type": "ui_gauge", 978 | "z": "5aafcc20.2b1944", 979 | "name": "", 980 | "group": "4010bd65.8e36e4", 981 | "order": 1, 982 | "width": "3", 983 | "height": "3", 984 | "gtype": "donut", 985 | "title": "Humedad", 986 | "label": "%", 987 | "format": "{{value}}", 988 | "min": "10", 989 | "max": "90", 990 | "colors": [ 991 | "#ff0000", 992 | "#008000", 993 | "#ff0000" 994 | ], 995 | "seg1": "20", 996 | "seg2": "80", 997 | "x": 340, 998 | "y": 400, 999 | "wires": [] 1000 | }, 1001 | { 1002 | "id": "c423564f.c9c2e8", 1003 | "type": "mqtt in", 1004 | "z": "5aafcc20.2b1944", 1005 | "name": "", 1006 | "topic": "Temp_2", 1007 | "qos": "2", 1008 | "broker": "19511945.9ab8d7", 1009 | "x": 130, 1010 | "y": 460, 1011 | "wires": [ 1012 | [ 1013 | "42297dc9.772854" 1014 | ] 1015 | ] 1016 | }, 1017 | { 1018 | "id": "42297dc9.772854", 1019 | "type": "ui_gauge", 1020 | "z": "5aafcc20.2b1944", 1021 | "name": "", 1022 | "group": "2add410e.699e8e", 1023 | "order": 1, 1024 | "width": "3", 1025 | "height": "3", 1026 | "gtype": "donut", 1027 | "title": "Temperatura", 1028 | "label": "ºC", 1029 | "format": "{{value}}", 1030 | "min": "10", 1031 | "max": "40", 1032 | "colors": [ 1033 | "#ff0000", 1034 | "#008000", 1035 | "#ff0000" 1036 | ], 1037 | "seg1": "20", 1038 | "seg2": "26", 1039 | "x": 350, 1040 | "y": 460, 1041 | "wires": [] 1042 | }, 1043 | { 1044 | "id": "b93d4274.24733", 1045 | "type": "mqtt in", 1046 | "z": "5aafcc20.2b1944", 1047 | "name": "", 1048 | "topic": "Hum_2", 1049 | "qos": "2", 1050 | "broker": "19511945.9ab8d7", 1051 | "x": 130, 1052 | "y": 520, 1053 | "wires": [ 1054 | [ 1055 | "a3b6119b.9901d" 1056 | ] 1057 | ] 1058 | }, 1059 | { 1060 | "id": "a3b6119b.9901d", 1061 | "type": "ui_gauge", 1062 | "z": "5aafcc20.2b1944", 1063 | "name": "", 1064 | "group": "2add410e.699e8e", 1065 | "order": 2, 1066 | "width": "3", 1067 | "height": "3", 1068 | "gtype": "donut", 1069 | "title": "Humedad", 1070 | "label": "%", 1071 | "format": "{{value}}", 1072 | "min": "10", 1073 | "max": "90", 1074 | "colors": [ 1075 | "#ff0000", 1076 | "#008000", 1077 | "#ff0000" 1078 | ], 1079 | "seg1": "20", 1080 | "seg2": "80", 1081 | "x": 340, 1082 | "y": 520, 1083 | "wires": [] 1084 | }, 1085 | { 1086 | "id": "e7c72bc8.b347f8", 1087 | "type": "mqtt in", 1088 | "z": "16dd348f.f2594b", 1089 | "name": "Temperatura Sonda 1", 1090 | "topic": "Temp_1", 1091 | "qos": "2", 1092 | "broker": "19511945.9ab8d7", 1093 | "x": 120, 1094 | "y": 160, 1095 | "wires": [ 1096 | [ 1097 | "7f4becd.c677c14", 1098 | "6c669a9a.8346d4" 1099 | ] 1100 | ] 1101 | }, 1102 | { 1103 | "id": "ee9ef39f.c911a", 1104 | "type": "mqtt in", 1105 | "z": "16dd348f.f2594b", 1106 | "name": "Humedad Sonda 1", 1107 | "topic": "Hum_1", 1108 | "qos": "2", 1109 | "broker": "19511945.9ab8d7", 1110 | "x": 110, 1111 | "y": 220, 1112 | "wires": [ 1113 | [ 1114 | "61cdc77e.0febd8" 1115 | ] 1116 | ] 1117 | }, 1118 | { 1119 | "id": "361e81e3.51146e", 1120 | "type": "mqtt in", 1121 | "z": "16dd348f.f2594b", 1122 | "name": "Temperatura Sonda 2", 1123 | "topic": "Temp_2", 1124 | "qos": "2", 1125 | "broker": "19511945.9ab8d7", 1126 | "x": 120, 1127 | "y": 280, 1128 | "wires": [ 1129 | [ 1130 | "c18ed71c.9b2138", 1131 | "d449a35e.fa6ca" 1132 | ] 1133 | ] 1134 | }, 1135 | { 1136 | "id": "9d4ea374.b7bad", 1137 | "type": "mqtt in", 1138 | "z": "16dd348f.f2594b", 1139 | "name": "Humedad Sonda 2", 1140 | "topic": "Hum_2", 1141 | "qos": "2", 1142 | "broker": "19511945.9ab8d7", 1143 | "x": 110, 1144 | "y": 340, 1145 | "wires": [ 1146 | [ 1147 | "e34dafb4.125bb" 1148 | ] 1149 | ] 1150 | }, 1151 | { 1152 | "id": "61cdc77e.0febd8", 1153 | "type": "function", 1154 | "z": "16dd348f.f2594b", 1155 | "name": "Make query", 1156 | "func": "var newMsg = { payload: msg.payload };\nnewMsg.topic=\"insert into Humedad (Sonda,Humedad) values (1,\"+newMsg.payload+\")\";\nreturn newMsg;", 1157 | "outputs": 1, 1158 | "noerr": 0, 1159 | "x": 350, 1160 | "y": 220, 1161 | "wires": [ 1162 | [ 1163 | "1926aa93.c633c5" 1164 | ] 1165 | ] 1166 | }, 1167 | { 1168 | "id": "c18ed71c.9b2138", 1169 | "type": "function", 1170 | "z": "16dd348f.f2594b", 1171 | "name": "Make query", 1172 | "func": "var newMsg = { payload: msg.payload };\nnewMsg.topic=\"insert into Temperatura (Sonda,Temperatura) values (2,\"+newMsg.payload+\")\";\nreturn newMsg;", 1173 | "outputs": 1, 1174 | "noerr": 0, 1175 | "x": 350, 1176 | "y": 280, 1177 | "wires": [ 1178 | [ 1179 | "1926aa93.c633c5" 1180 | ] 1181 | ] 1182 | }, 1183 | { 1184 | "id": "1926aa93.c633c5", 1185 | "type": "mysql", 1186 | "z": "16dd348f.f2594b", 1187 | "mydb": "b49deb9b.d50248", 1188 | "name": "", 1189 | "x": 610, 1190 | "y": 240, 1191 | "wires": [ 1192 | [] 1193 | ] 1194 | }, 1195 | { 1196 | "id": "e34dafb4.125bb", 1197 | "type": "function", 1198 | "z": "16dd348f.f2594b", 1199 | "name": "Make query", 1200 | "func": "var newMsg = { payload: msg.payload };\nnewMsg.topic=\"insert into Humedad (Sonda,Humedad) values (2,\"+newMsg.payload+\")\";\nreturn newMsg;", 1201 | "outputs": 1, 1202 | "noerr": 0, 1203 | "x": 350, 1204 | "y": 340, 1205 | "wires": [ 1206 | [ 1207 | "1926aa93.c633c5" 1208 | ] 1209 | ] 1210 | }, 1211 | { 1212 | "id": "7f4becd.c677c14", 1213 | "type": "function", 1214 | "z": "16dd348f.f2594b", 1215 | "name": "Make query", 1216 | "func": "var newMsg = { payload: msg.payload };\nnewMsg.topic=\"insert into Temperatura (Sonda,Temperatura) values (1,\"+newMsg.payload+\")\";\nreturn newMsg;", 1217 | "outputs": 1, 1218 | "noerr": 0, 1219 | "x": 350, 1220 | "y": 160, 1221 | "wires": [ 1222 | [ 1223 | "1926aa93.c633c5" 1224 | ] 1225 | ] 1226 | }, 1227 | { 1228 | "id": "7dedb6c7.65d848", 1229 | "type": "moment", 1230 | "z": "5aafcc20.2b1944", 1231 | "name": "", 1232 | "topic": "", 1233 | "input": "", 1234 | "inputType": "msg", 1235 | "inTz": "Etc/UTC", 1236 | "adjAmount": "0", 1237 | "adjType": "hours", 1238 | "adjDir": "add", 1239 | "format": "DD-MM-YYYY HH:mm:ss", 1240 | "locale": "POSIX", 1241 | "output": "", 1242 | "outputType": "msg", 1243 | "outTz": "Europe/Madrid", 1244 | "x": 380, 1245 | "y": 40, 1246 | "wires": [ 1247 | [ 1248 | "502f2788.1923a8", 1249 | "50beea13.f7dbb4" 1250 | ] 1251 | ] 1252 | }, 1253 | { 1254 | "id": "50beea13.f7dbb4", 1255 | "type": "mqtt out", 1256 | "z": "5aafcc20.2b1944", 1257 | "name": "", 1258 | "topic": "Hora", 1259 | "qos": "", 1260 | "retain": "", 1261 | "broker": "19511945.9ab8d7", 1262 | "x": 570, 1263 | "y": 80, 1264 | "wires": [] 1265 | }, 1266 | { 1267 | "id": "6c669a9a.8346d4", 1268 | "type": "function", 1269 | "z": "16dd348f.f2594b", 1270 | "name": "Comprueba Umbral Sonda 1", 1271 | "func": "if (msg.payload > 26) {\n msg.payload = true;\n}\nelse {\n msg.payload = false;\n}\nreturn msg;", 1272 | "outputs": 1, 1273 | "noerr": 0, 1274 | "x": 420, 1275 | "y": 400, 1276 | "wires": [ 1277 | [ 1278 | "ffc3bb30.3e7f28" 1279 | ] 1280 | ] 1281 | }, 1282 | { 1283 | "id": "d449a35e.fa6ca", 1284 | "type": "function", 1285 | "z": "16dd348f.f2594b", 1286 | "name": "Comprueba Umbral Sonda 2", 1287 | "func": "if (msg.payload > 26) {\n msg.payload = true;\n}\nelse {\n msg.payload = false;\n}\nreturn msg;", 1288 | "outputs": 1, 1289 | "noerr": 0, 1290 | "x": 420, 1291 | "y": 460, 1292 | "wires": [ 1293 | [ 1294 | "6e84612e.4377d" 1295 | ] 1296 | ] 1297 | }, 1298 | { 1299 | "id": "ffc3bb30.3e7f28", 1300 | "type": "mqtt out", 1301 | "z": "16dd348f.f2594b", 1302 | "name": "Alarma Sonda 1", 1303 | "topic": "Alarma_1", 1304 | "qos": "", 1305 | "retain": "", 1306 | "broker": "19511945.9ab8d7", 1307 | "x": 660, 1308 | "y": 400, 1309 | "wires": [] 1310 | }, 1311 | { 1312 | "id": "6e84612e.4377d", 1313 | "type": "mqtt out", 1314 | "z": "16dd348f.f2594b", 1315 | "name": "Alarma Sonda 2", 1316 | "topic": "Alarma_2", 1317 | "qos": "", 1318 | "retain": "", 1319 | "broker": "19511945.9ab8d7", 1320 | "x": 660, 1321 | "y": 460, 1322 | "wires": [] 1323 | }, 1324 | { 1325 | "id": "9516e652.72e128", 1326 | "type": "mqtt in", 1327 | "z": "5aafcc20.2b1944", 1328 | "name": "", 1329 | "topic": "Alarma_1", 1330 | "qos": "2", 1331 | "broker": "19511945.9ab8d7", 1332 | "x": 140, 1333 | "y": 620, 1334 | "wires": [ 1335 | [ 1336 | "67d34329.92021c" 1337 | ] 1338 | ] 1339 | }, 1340 | { 1341 | "id": "ff47ade.9d5835", 1342 | "type": "mqtt in", 1343 | "z": "5aafcc20.2b1944", 1344 | "name": "", 1345 | "topic": "Alarma_2", 1346 | "qos": "2", 1347 | "broker": "19511945.9ab8d7", 1348 | "x": 140, 1349 | "y": 680, 1350 | "wires": [ 1351 | [ 1352 | "c3231cb.230ebe" 1353 | ] 1354 | ] 1355 | }, 1356 | { 1357 | "id": "a2306180.a6064", 1358 | "type": "ui_text", 1359 | "z": "5aafcc20.2b1944", 1360 | "group": "14a44092.e1d76f", 1361 | "order": 0, 1362 | "width": 0, 1363 | "height": 0, 1364 | "name": "", 1365 | "label": "LED 1", 1366 | "format": "", 1367 | "layout": "row-left", 1368 | "x": 510, 1369 | "y": 620, 1370 | "wires": [] 1371 | }, 1372 | { 1373 | "id": "1a6765f1.f2457a", 1374 | "type": "ui_text", 1375 | "z": "5aafcc20.2b1944", 1376 | "group": "14a44092.e1d76f", 1377 | "order": 0, 1378 | "width": 0, 1379 | "height": 0, 1380 | "name": "", 1381 | "label": "LED 2", 1382 | "format": "", 1383 | "layout": "row-left", 1384 | "x": 510, 1385 | "y": 680, 1386 | "wires": [] 1387 | }, 1388 | { 1389 | "id": "67d34329.92021c", 1390 | "type": "function", 1391 | "z": "5aafcc20.2b1944", 1392 | "name": "Color LED 1", 1393 | "func": "if (msg.payload == 'true'){\n msg.color = 'red';\n}\nelse{\n msg.color = 'green';\n}\n\nreturn msg;", 1394 | "outputs": 1, 1395 | "noerr": 0, 1396 | "x": 350, 1397 | "y": 620, 1398 | "wires": [ 1399 | [ 1400 | "a2306180.a6064" 1401 | ] 1402 | ] 1403 | }, 1404 | { 1405 | "id": "c3231cb.230ebe", 1406 | "type": "function", 1407 | "z": "5aafcc20.2b1944", 1408 | "name": "Color LED 2", 1409 | "func": "if (msg.payload == 'true'){\n msg.color = 'red';\n}\nelse{\n msg.color = 'green';\n}\n\nreturn msg;", 1410 | "outputs": 1, 1411 | "noerr": 0, 1412 | "x": 350, 1413 | "y": 680, 1414 | "wires": [ 1415 | [ 1416 | "1a6765f1.f2457a" 1417 | ] 1418 | ] 1419 | }, 1420 | { 1421 | "id": "17e103ae.840d9c", 1422 | "type": "ui_button", 1423 | "z": "5aafcc20.2b1944", 1424 | "name": "", 1425 | "group": "14a44092.e1d76f", 1426 | "order": 0, 1427 | "width": "2", 1428 | "height": "1", 1429 | "passthru": false, 1430 | "label": "{{msg.payload}}", 1431 | "color": "", 1432 | "bgcolor": "{{msg.background}}", 1433 | "icon": "", 1434 | "payload": "", 1435 | "payloadType": "str", 1436 | "topic": "", 1437 | "x": 130, 1438 | "y": 740, 1439 | "wires": [ 1440 | [ 1441 | "275bb50.be46e4c" 1442 | ] 1443 | ] 1444 | }, 1445 | { 1446 | "id": "275bb50.be46e4c", 1447 | "type": "function", 1448 | "z": "5aafcc20.2b1944", 1449 | "name": "ON-OFF", 1450 | "func": "var myCount = flow.get(\"estado\")||\"OFF\";\n\nif (myCount == 'ON'){\n flow.set(\"estado\",\"OFF\");\n msg.payload = 'OFF';\n msg.background = 'red';\n}\nelse{\n flow.set(\"estado\",\"ON\");\n msg.payload = 'ON';\n msg.background = 'green';\n}\n\nreturn msg;", 1451 | "outputs": 1, 1452 | "noerr": 0, 1453 | "x": 340, 1454 | "y": 740, 1455 | "wires": [ 1456 | [ 1457 | "6135627e.db2f5c", 1458 | "17e103ae.840d9c" 1459 | ] 1460 | ] 1461 | }, 1462 | { 1463 | "id": "6135627e.db2f5c", 1464 | "type": "mqtt out", 1465 | "z": "5aafcc20.2b1944", 1466 | "name": "", 1467 | "topic": "Aviso", 1468 | "qos": "", 1469 | "retain": "", 1470 | "broker": "19511945.9ab8d7", 1471 | "x": 510, 1472 | "y": 740, 1473 | "wires": [] 1474 | } 1475 | ] 1476 | -------------------------------------------------------------------------------- /publish_cuenta_atras/publish_cuenta_atras.ino: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | // Direccion MAC 7 | byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xYY }; //Sustituir YY por el número de kit 8 | 9 | // IP del servidor 10 | IPAddress mqtt_server(192, 168, X, X); //poner la IP de mosquitto al que conectarse 11 | 12 | // Topic con el que trabajamos 13 | const char* topicName = "countdown"; 14 | 15 | EthernetClient ethClient; 16 | PubSubClient client(ethClient); 17 | 18 | void setup() 19 | { 20 | Serial.begin(9600); 21 | if (Ethernet.begin(mac) == 0) { 22 | Serial.println("Failed to configure Ethernet using DHCP"); 23 | } 24 | client.setServer(mqtt_server, 1883); 25 | } 26 | 27 | void loop() 28 | { 29 | if (client.connected()) { 30 | Serial.print("Connecting ...\n"); 31 | client.connect("arduinoClient21", "curso_iot", "raspberry"); //Sustituir XX por número de puesto 32 | // Envio la cuenta atras 33 | for (int i = 10; i >= 0; i--) { 34 | char buffer[5]; 35 | sprintf(buffer, "%i", i); 36 | Serial.print("Envio la cadena de caracteres: "); 37 | Serial.println(buffer); 38 | client.publish(topicName, buffer); 39 | delay(1000); 40 | } 41 | } 42 | else { 43 | Serial.print("Connecting ...\n"); 44 | client.connect("arduinoClient21", "curso_iot", "raspberry"); //Sustituir XX por número de puesto 45 | } 46 | 47 | // Tiempo entre envios (en ms) 48 | delay(10000); 49 | } 50 | --------------------------------------------------------------------------------