personas:johnny:proyectos:indoor_diy_autosostenible
Diferencias
Muestra las diferencias entre dos versiones de la página.
Ambos lados, revisión anteriorRevisión previaPróxima revisión | Revisión previaPróxima revisiónAmbos lados, revisión siguiente | ||
personas:johnny:proyectos:indoor_diy_autosostenible [2019/06/19 16:16] – [Firmware para el ESP8266] kz | personas:johnny:proyectos:indoor_diy_autosostenible [2019/12/01 07:40] – kz | ||
---|---|---|---|
Línea 213: | Línea 213: | ||
+ | ==== Construcción física del indoor ==== | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | ====== Código para la ventilación usando timeAlarms ====== | ||
+ | |||
+ | <code c++> | ||
+ | |||
+ | // https:// | ||
+ | // Librerias | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | // pin que controla | ||
+ | int pin = 13; | ||
+ | |||
+ | int alarma = 900; // cada 15 min | ||
+ | |||
+ | void setup() { | ||
+ | | ||
+ | Serial.begin(9600); | ||
+ | //fijamos el tiempo inicial del esp | ||
+ | // (08:30:00 25/05/17) | ||
+ | setTime(8, | ||
+ | | ||
+ | //Creamos las alarmas | ||
+ | // | ||
+ | // | ||
+ | | ||
+ | Alarm.timerRepeat(alarma, | ||
+ | | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | | ||
+ | pinMode(pin, | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | digitalClockDisplay(); | ||
+ | Alarm.delay(1000); | ||
+ | } | ||
+ | |||
+ | // encender ventilador | ||
+ | void prenderVentilador(){ | ||
+ | Serial.println(" | ||
+ | digitalWrite(pin, | ||
+ | } | ||
+ | |||
+ | |||
+ | // encender ventilador | ||
+ | void apagarVentilador(){ | ||
+ | Serial.println(" | ||
+ | digitalWrite(pin, | ||
+ | } | ||
+ | |||
+ | // función que enciende el riego | ||
+ | void prenderSensorRiegoManana(){ | ||
+ | Serial.println(" | ||
+ | digitalWrite(pin, | ||
+ | } | ||
+ | |||
+ | // función que apaga el riego | ||
+ | void apagarSensorRiegoManana(){ | ||
+ | Serial.println(" | ||
+ | digitalWrite(pin, | ||
+ | } | ||
+ | |||
+ | void EveningAlarm(){ | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | void WeeklyAlarm(){ | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | void ExplicitAlarm(){ | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | void Repeats(){ | ||
+ | digitalWrite(pin, | ||
+ | Alarm.delay(60000); | ||
+ | Serial.println(" | ||
+ | digitalWrite(pin, | ||
+ | Alarm.delay(1000); | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | void OnceOnly(){ | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | void digitalClockDisplay() | ||
+ | { | ||
+ | // digital clock display of the time | ||
+ | Serial.print(hour()); | ||
+ | printDigits(minute()); | ||
+ | printDigits(second()); | ||
+ | Serial.println(); | ||
+ | } | ||
+ | |||
+ | void printDigits(int digits) | ||
+ | { | ||
+ | Serial.print(":" | ||
+ | if(digits < 10) | ||
+ | Serial.print(' | ||
+ | Serial.print(digits); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====== Código para el control automatizado de las luces ====== | ||
+ | |||
+ | Este código posee dos funciones que segun el estado se la planta se pueden cambiar para vegetativo o floración. Es un proyecto en platformio | ||
+ | |||
+ | <code c++> | ||
+ | /* | ||
+ | Este código toma la hora de internet usando un servidor NTP y | ||
+ | enciende algo. Tomadpo de aqui https:// | ||
+ | |||
+ | !!! importante | ||
+ | You need to adjust the UTC offset for your timezone in milliseconds. | ||
+ | Refer the list of UTC time offsets. | ||
+ | https:// | ||
+ | |||
+ | For UTC -5.00 : -5 * 60 * 60 : -18000 | ||
+ | For UTC +1.00 : 1 * 60 * 60 : 3600 | ||
+ | For UTC +0.00 : 0 * 60 * 60 : 0 | ||
+ | |||
+ | here -> const long utcOffsetInSeconds = 3600; | ||
+ | */ | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | const char *ssid = "el nombre de la red"; | ||
+ | const char *password = "el password de la red"; | ||
+ | const long utcOffsetInSeconds = -18000; // colombia UTC -5 | ||
+ | char daysOfTheWeek[7][12] = { | ||
+ | " | ||
+ | }; | ||
+ | // Define NTP client to get time | ||
+ | WiFiUDP ntpUDP; | ||
+ | NTPClient timeClient(ntpUDP, | ||
+ | int ledTrigger = D6; | ||
+ | |||
+ | void setup() { | ||
+ | Serial.begin(115200); | ||
+ | WiFi.begin(ssid, | ||
+ | while(WiFi.status() != WL_CONNECTED) { | ||
+ | delay(500); | ||
+ | Serial.print(" | ||
+ | } | ||
+ | Serial.print(" | ||
+ | Serial.println(" | ||
+ | Serial.println(WiFi.localIP()); | ||
+ | timeClient.begin(); | ||
+ | pinMode(LED_BUILTIN, | ||
+ | pinMode(ledTrigger, | ||
+ | } | ||
+ | |||
+ | void statusWIFI() { | ||
+ | // cuando esta pegado a internet el status es 3 | ||
+ | // la idea de esto es que mande un color u otro si tiene internet o no | ||
+ | Serial.print(" | ||
+ | Serial.println(WiFi.status()); | ||
+ | } | ||
+ | |||
+ | void lucesVegetativo() { | ||
+ | // 18 horas luz, 6 horas oscuridad | ||
+ | int hours = timeClient.getHours(); | ||
+ | // se prenden a las 6 de la mañana y se apagan a las 12 de la noche | ||
+ | if ( hours < 6 ) { | ||
+ | digitalWrite(ledTrigger, | ||
+ | Serial.println(" | ||
+ | } else { | ||
+ | digitalWrite(ledTrigger, | ||
+ | Serial.println(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void lucesFloracion() { | ||
+ | // 12 horas luz, 12 horas oscuridad | ||
+ | int hours = timeClient.getHours(); | ||
+ | // a las 6 de la mañana se prenden y a las 6 de la tarde se apagan | ||
+ | if ( (hours >= 6) && (hours < 18) ) { | ||
+ | digitalWrite(ledTrigger, | ||
+ | Serial.println(" | ||
+ | } else { | ||
+ | digitalWrite(ledTrigger, | ||
+ | Serial.println(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // the loop function runs over and over again forever | ||
+ | void loop() { | ||
+ | timeClient.update(); | ||
+ | Serial.print(daysOfTheWeek[timeClient.getDay()]); | ||
+ | Serial.print(", | ||
+ | Serial.print(timeClient.getHours()); | ||
+ | Serial.print(":" | ||
+ | Serial.print(timeClient.getMinutes()); | ||
+ | Serial.print(":" | ||
+ | Serial.print(timeClient.getSeconds()); | ||
+ | Serial.println("" | ||
+ | statusWIFI(); | ||
+ | // | ||
+ | lucesFloracion(); | ||
+ | delay(1000); | ||
+ | |||
+ | /* | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | digitalWrite(ledTrigger, | ||
+ | delay(1000); | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | digitalWrite(ledTrigger, | ||
+ | delay(1000); | ||
+ | */ | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | el platformio.ini | ||
+ | <code json> | ||
+ | ;PlatformIO Project Configuration File | ||
+ | ; | ||
+ | ; Build options: build flags, source filter | ||
+ | ; | ||
+ | ; | ||
+ | ; | ||
+ | ; | ||
+ | ; Please visit documentation for the other options and examples | ||
+ | ; https:// | ||
+ | |||
+ | [env: | ||
+ | platform = espressif8266 | ||
+ | board = d1_mini_lite | ||
+ | framework = arduino | ||
+ | lib_deps = NTPClient | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====== control de humedad y temperatura ====== | ||
+ | |||
+ | Se inicia de aqui [[https:// | ||
+ | |||
+ | {{: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | <code c++> | ||
+ | #include < | ||
+ | |||
+ | int sensorPin = A0; // select the input pin for the potentiometer | ||
+ | int ledPin = D4; // select the pin for the LED | ||
+ | int sensorValue = 0; // variable to store the value coming from the sensor | ||
+ | |||
+ | void setup() { | ||
+ | // declare the ledPin as an OUTPUT: | ||
+ | pinMode(ledPin, | ||
+ | Serial.begin(115200); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | // read the value from the sensor: | ||
+ | sensorValue = analogRead(sensorPin); | ||
+ | Serial.println(sensorValue); | ||
+ | // turn the ledPin on | ||
+ | digitalWrite(ledPin, | ||
+ | // stop the program for < | ||
+ | delay(sensorValue); | ||
+ | // turn the ledPin off: | ||
+ | digitalWrite(ledPin, | ||
+ | // stop the program for for < | ||
+ | delay(sensorValue); | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | Sensor totalmente seco: 833 | ||
+ | Sensor totalmente humedo: 482 | ||
+ | </ | ||
+ | |||
+ | ====== actualizacion nov 3 2019 ====== | ||
+ | |||
+ | He creado una nueva versión del modulo que contiene un **capacitive moisture sensor** para medir la humedad en la tierra, un **module relay x 4** para controlar las luces y la ventilación. Para el ciclo solar de las luces estoy usando la libreria **time.h**, me di cuenta que es mejor usar sin el **timeAlarms.h** porque se pueden customizar mejor los ciclos de la luz y es mejor, o hasta ahora me funciona a mi asi. | ||
+ | |||
+ | |||
+ | ---- | ||
+ | {{: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Mi abuelo me ha ayudado en la creación del indoor, una estructura de 90cm x 90cm x 1.5m. En su interior he añadido el DHT11 para " | ||
+ | |||
+ | {{: | ||
+ | {{: | ||
+ | {{: | ||
+ | {{: | ||
+ | {{: | ||
+ | {{: | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | |||
+ | ====== Actualización nov 9 2019 ====== | ||
+ | |||
+ | Hasta ahora la libreria time.h a funcionado muy bien, reemplazandome por completo un rtc. | ||
+ | |||
+ | === Los datos se puede ver en:=== | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | ====== Actualización nov 12 2019 ====== | ||
+ | |||
+ | Logro adjuntar a la trama de datos la humedad en la tierra de un sensor de humedad capacitivo. | ||
+ | |||
+ | ====== Actualización 1 diciembre 2019 ====== | ||
+ | |||
+ | Por alguna razón con el código que tengo aqui ... se presenta el problema de que el modulo funciona bien 5 o 6 dias y despues deja de funcionar bien... no apagando la luz cuando debe de estar apagada o viceversa, dejando la luz prendida cuando debe de estar apagada. El problema es que solo se fija una vez el tiempo | ||
+ | en el esp... si estre se reinicia o se va la energia... esto causa que el tiempo se reinicie... ocacionando que el tiempo de las alarmas de las luces no este sincronizado con el tiempo real. | ||
+ | |||
+ | *Solución: *Se usan las librerias NTP y Time simultaneamente... en resumen se fija al inicio el tiempo local (libreria time) con request al servidor NTP... luego de eso el tiempo local se va actualizando cada 10 miniutos con un request al servidor NTP. | ||
+ | |||
+ | *TODO* | ||
+ | |||
+ | - *RAPIDO*: integrar al código actual al actualizacion con el servidor NTP | ||
+ | - integrar una web en la flash para programar la fecha del rtc digital time.h, | ||
+ | - pensar en una interfaz para pedir al usuario la programacion de la luz sea floración o vegetación o esquejes. | ||
+ | - sacar una tarjetica en fritzing y pasarsela al brol o a uber, con el convertidor de la luz | ||
+ | - actualizar el firmware por medio de ota | ||
+ | |||
+ | |||
+ | <code c++> | ||
+ | /* Library used | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | | ||
+ | * resources from sensor | ||
+ | * https:// | ||
+ | | ||
+ | config NTP | ||
+ | this code take the time from server using NTP | ||
+ | https:// | ||
+ | |||
+ | !!! IMPORTANT | ||
+ | You need to adjust the UTC offset for your timezone in milliseconds. | ||
+ | Refer the list of UTC time offsets. | ||
+ | https:// | ||
+ | |||
+ | For UTC -5.00 : -5 * 60 * 60 : -18000 | ||
+ | For UTC +1.00 : 1 * 60 * 60 : 3600 | ||
+ | For UTC +0.00 : 0 * 60 * 60 : 0 | ||
+ | used -> const long utcOffsetInSeconds = 3600; | ||
+ | */ | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | // pin out oled ssd1306 | ||
+ | #define OLED_MOSI 14 //D5 | ||
+ | #define OLED_CLK 16 //D0 | ||
+ | #define OLED_DC 13 //D7 | ||
+ | #define OLED_CS 15 //D6 | ||
+ | #define OLED_RESET 12 //D8 | ||
+ | |||
+ | #define lights D1 | ||
+ | char stateLights = ' | ||
+ | |||
+ | // config NTP variables | ||
+ | int time_hours = 0; | ||
+ | int time_minutes = 0; | ||
+ | int time_seconds = 0; | ||
+ | const int *ntp_hours, *ntp_minutes, | ||
+ | const long utcOffsetInSeconds = -18000; // colombia UTC -5 | ||
+ | char daysOfTheWeek[7][12] = { | ||
+ | " | ||
+ | }; | ||
+ | |||
+ | const char *ssid = " | ||
+ | const char *pass = " | ||
+ | |||
+ | // Define NTP client to get time | ||
+ | WiFiUDP ntpUDP; | ||
+ | NTPClient timeClient(ntpUDP, | ||
+ | |||
+ | // config display | ||
+ | Adafruit_SSD1306 display(OLED_MOSI, | ||
+ | #if (SSD1306_LCDHEIGHT != 64) | ||
+ | //# | ||
+ | #endif | ||
+ | |||
+ | // define template function | ||
+ | void firstSync(); | ||
+ | void syncNtptoTime(); | ||
+ | void stateVegetative(); | ||
+ | void stateFlowering(); | ||
+ | |||
+ | void setup() { | ||
+ | // display | ||
+ | Serial.begin(115200); | ||
+ | setTime(time_hours, | ||
+ | WiFi.begin(ssid, | ||
+ | display.begin(SSD1306_SWITCHCAPVCC); | ||
+ | display.clearDisplay(); | ||
+ | Serial.println(); | ||
+ | Serial.println(); | ||
+ | delay(1000); | ||
+ | display.setTextSize(1); | ||
+ | display.setTextColor(WHITE); | ||
+ | display.setCursor(0, | ||
+ | display.println(" | ||
+ | display.display(); | ||
+ | delay(1000); | ||
+ | while (WiFi.status() != WL_CONNECTED) { | ||
+ | delay(500); | ||
+ | display.clearDisplay(); | ||
+ | display.setTextSize(1); | ||
+ | display.setCursor(0, | ||
+ | display.setTextColor(BLACK, | ||
+ | display.println(" | ||
+ | display.print(" | ||
+ | display.display(); | ||
+ | } | ||
+ | display.clearDisplay(); | ||
+ | display.setTextSize(1); | ||
+ | display.setCursor(0, | ||
+ | display.setTextColor(WHITE); | ||
+ | display.println(" | ||
+ | display.println(WiFi.localIP()); | ||
+ | display.display(); | ||
+ | timeClient.begin(); | ||
+ | delay(5000); | ||
+ | display.clearDisplay(); | ||
+ | display.setTextSize(1); | ||
+ | display.setTextColor(WHITE); | ||
+ | display.setCursor(0, | ||
+ | display.println(" | ||
+ | display.display(); | ||
+ | firstSync(); | ||
+ | delay(5000); | ||
+ | // | ||
+ | // | ||
+ | pinMode(lights, | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | display.clearDisplay(); | ||
+ | display.setTextSize(0.5); | ||
+ | display.setTextColor(WHITE); | ||
+ | display.setCursor(0, | ||
+ | display.print(daysOfTheWeek[timeClient.getDay()]); | ||
+ | if (stateLights == ' | ||
+ | display.print(" | ||
+ | } else { | ||
+ | display.print(" | ||
+ | } | ||
+ | display.println(); | ||
+ | display.setCursor(0, | ||
+ | // time library | ||
+ | display.print(" | ||
+ | display.print(hour()); | ||
+ | display.print(":" | ||
+ | display.print(minute()); | ||
+ | display.print(":" | ||
+ | display.print(second()); | ||
+ | |||
+ | // time ntp | ||
+ | display.setCursor(0, | ||
+ | display.print(" | ||
+ | display.print(*ntp_hours); | ||
+ | display.print(":" | ||
+ | display.print(*ntp_minutes); | ||
+ | display.print(":" | ||
+ | display.print(*ntp_seconds); | ||
+ | |||
+ | // state lights | ||
+ | display.setCursor(0, | ||
+ | |||
+ | syncNtptoTime(); | ||
+ | // stateFlowering(); | ||
+ | stateVegetative(); | ||
+ | |||
+ | // update display | ||
+ | display.display(); | ||
+ | delay(1000); | ||
+ | } | ||
+ | |||
+ | void firstSync() { | ||
+ | // pointer update with what is in ntp | ||
+ | timeClient.update(); | ||
+ | ntp_hours = & | ||
+ | ntp_minutes = & | ||
+ | ntp_seconds = & | ||
+ | // first update ntp to time variables | ||
+ | time_hours = timeClient.getHours(); | ||
+ | time_minutes = timeClient.getMinutes(); | ||
+ | time_seconds = timeClient.getSeconds(); | ||
+ | // frist sync Ntp time to local time, get values from value pointers | ||
+ | setTime(*ntp_hours, | ||
+ | timeClient.end(); | ||
+ | } | ||
+ | |||
+ | void syncNtptoTime() { | ||
+ | // update local time from NTP server over get minutes and seconds | ||
+ | // from local time hardware | ||
+ | if ( (minute() == 10 && second() == 58) || | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | ) { | ||
+ | timeClient.update(); | ||
+ | time_hours = timeClient.getHours(); | ||
+ | time_minutes = timeClient.getMinutes(); | ||
+ | time_seconds = timeClient.getSeconds(); | ||
+ | timeClient.end(); | ||
+ | // TODO: how to update days, month and year ? | ||
+ | setTime(*ntp_hours, | ||
+ | delay(500); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void stateVegetative() { | ||
+ | // 18 hours lights, 6 hours night | ||
+ | // they turn on 6 in the morning and turn off at the 12 last night | ||
+ | if ( hour() < 6 ) { | ||
+ | digitalWrite(lights, | ||
+ | stateLights = ' | ||
+ | } else { | ||
+ | digitalWrite(lights, | ||
+ | stateLights = ' | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void stateFlowering() { | ||
+ | // 12 hours lights, 12 hours night | ||
+ | // a las 6 de la mañana se prenden y a las 6 de la tarde se apagan | ||
+ | if ( (hour() >= 6) && (hour() < 18) ) { | ||
+ | digitalWrite(lights, | ||
+ | stateLights = ' | ||
+ | } else { | ||
+ | digitalWrite(lights, | ||
+ | stateLights = ' | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </ | ||
personas/johnny/proyectos/indoor_diy_autosostenible.txt · Última modificación: 2020/08/13 06:00 por kz