Herramientas de usuario

Herramientas del sitio


personas:johnny:proyectos:indoor_diy_autosostenible

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anteriorRevisión previa
Próxima revisión
Revisión previa
Próxima revisiónAmbos lados, revisión siguiente
personas:johnny:proyectos:indoor_diy_autosostenible [2019/09/29 23:56] kzpersonas:johnny:proyectos:indoor_diy_autosostenible [2019/12/01 07:40] kz
Línea 503: Línea 503:
 </WRAP> </WRAP>
  
 +====== 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.
 +
 +
 +----
 +{{:personas:johnny:proyectos:version-indoor-1.jpg?400|}}
 +
 +{{:personas:johnny:proyectos:version-indoor-3.jpg?400|}}
 +
 +{{:personas:johnny:proyectos:version-indoor-4.jpg?400|}}
 +
 +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 "medir" la temperatura y humedad interna del lugar. Y a la planta mas grande he anclado en la tierra el sensor capcitivo.
 +
 +{{:personas:johnny:proyectos:indoor-build-and-module1.jpg?400|}}
 +{{:personas:johnny:proyectos:indoor-build-and-module2.jpg?400|}}
 +{{:personas:johnny:proyectos:indoor-build-and-module3.jpg?400|}}
 +{{:personas:johnny:proyectos:indoor-build-and-module4.jpg?400|}}
 +{{:personas:johnny:proyectos:indoor-build-and-module5.jpg?400|}}
 +{{:personas:johnny:proyectos:indoor-build-and-module6.jpg?400|}}
 +
 +[[https://gist.github.com/Kaziuz/ad3751c3b075d593cda2c111af3b242b|Link hacia el codigo del indoor]]
 +
 +
 +====== 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://aqa.unloquer.org:8888/sources/1/dashboards/2?lower=now%28%29%20-%2015m|Enlace al influx]]
 +
 +====== 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,  (integrar esa parte que necesito de upayakuwasi y las alarmas)
 +  - 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://github.com/PaulStoffregen/Time
 + * https://github.com/PaulStoffregen/TimeAlarms
 + * https://learn.adafruit.com/dht/using-a-dhtxx-sensor
 + 
 + * resources from sensor
 + * https://www.switchdoc.com/2018/11/tutorial-capacitive-moisture-sensor-grove/
 + 
 +  config NTP
 +  this code take the time from server using NTP 
 +  https://lastminuteengineers.com/esp8266-ntp-server-date-time-tutorial/
 +
 +  !!! IMPORTANT
 +  You need to adjust the UTC offset for your timezone in milliseconds. 
 +  Refer the list of UTC time offsets.  Here are some examples for different timezones:
 +  https://upload.wikimedia.org/wikipedia/commons/8/88/World_Time_Zones_Map.png
 +
 +  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 <Arduino.h>
 +#include <NTPClient.h>
 +#include <DHT.h>
 +#include <Time.h>
 +#include <SPI.h>
 +#include <Wire.h>
 +#include <Adafruit_GFX.h>
 +#include <Adafruit_SSD1306.h>
 +#include <ESP8266HTTPClient.h>
 +#include <ESP8266WiFi.h>
 +#include <WiFiUdp.h>
 +#include <string.h>
 +
 +// 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 = 'F';
 +
 +// config NTP variables
 +int time_hours = 0;
 +int time_minutes = 0;
 +int time_seconds = 0;
 +const int *ntp_hours, *ntp_minutes, *ntp_seconds;
 +const long utcOffsetInSeconds = -18000; // colombia UTC -5
 +char daysOfTheWeek[7][12] = {
 +  "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
 +};
 +
 +const char *ssid = "TP-LINK_Extender_C464C2";
 +const char *pass = "alex1988alex";
 +
 +// Define NTP client to get time
 +WiFiUDP ntpUDP;
 +NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
 +
 +// config display
 +Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
 +#if (SSD1306_LCDHEIGHT != 64)
 +//#error("Height incorrect, please fix Adafruit_SH1106.h!");
 +#endif
 +
 +// define template function
 +void firstSync();
 +void syncNtptoTime();
 +void stateVegetative();
 +void stateFlowering();
 +
 +void setup() {
 +  // display
 +  Serial.begin(115200);
 +  setTime(time_hours,time_minutes,time_seconds,30,11,19);
 +  WiFi.begin(ssid, pass);
 +  display.begin(SSD1306_SWITCHCAPVCC);
 +  display.clearDisplay();
 +  Serial.println();
 +  Serial.println();
 +  delay(1000);
 +  display.setTextSize(1);
 +  display.setTextColor(WHITE);
 +  display.setCursor(0,10);
 +  display.println("Init ... ");
 +  display.display();
 +  delay(1000);
 +  while (WiFi.status() != WL_CONNECTED) {
 +    delay(500);
 +    display.clearDisplay();
 +    display.setTextSize(1);
 +    display.setCursor(0,10);
 +    display.setTextColor(BLACK, WHITE);
 +    display.println("connecting wifi ");
 +    display.print(".");
 +    display.display();
 +  }
 +  display.clearDisplay();
 +  display.setTextSize(1);
 +  display.setCursor(0,10);
 +  display.setTextColor(WHITE);
 +  display.println("Wifi connected");
 +  display.println(WiFi.localIP());
 +  display.display();
 +  timeClient.begin();
 +  delay(5000);
 +  display.clearDisplay();
 +  display.setTextSize(1);
 +  display.setTextColor(WHITE);
 +  display.setCursor(0,10);
 +  display.println("first sync NTP to Time hardware...");
 +  display.display();
 +  firstSync();
 +  delay(5000);
 +  //Serial.print(WiFi.localIP());  
 +  //pinMode(ledTrigger, OUTPUT);
 +  pinMode(lights, OUTPUT);
 +}
 +
 +void loop() {
 +  display.clearDisplay();
 +  display.setTextSize(0.5);
 +  display.setTextColor(WHITE);
 +  display.setCursor(0,0);
 +  display.print(daysOfTheWeek[timeClient.getDay()]);
 +  if (stateLights == 'V') {
 +    display.print(" | lights Onn");
 +  } else {
 +    display.print(" | lights Off");
 +  }
 +  display.println();
 +  display.setCursor(0,8);
 +  // time library
 +  display.print("rtc d: ");
 +  display.print(hour());
 +  display.print(":");
 +  display.print(minute());
 +  display.print(":");
 +  display.print(second());
 +
 +  // time ntp
 +  display.setCursor(0,16);
 +  display.print("last sync: ");
 +  display.print(*ntp_hours);
 +  display.print(":");
 +  display.print(*ntp_minutes);
 +  display.print(":");
 +  display.print(*ntp_seconds);
 +
 +  // state lights
 +  display.setCursor(0,24);
 +
 +  syncNtptoTime();
 +  // stateFlowering();
 +  stateVegetative();
 +
 +  // update display
 +  display.display();
 +  delay(1000);
 +
 +
 +void firstSync() {
 +  // pointer update with what is in ntp
 +  timeClient.update();
 +  ntp_hours = &time_hours;
 +  ntp_minutes = &time_minutes;
 +  ntp_seconds = &time_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,*ntp_minutes,*ntp_seconds,30,11,19);
 +  timeClient.end();
 +}
 +
 +void syncNtptoTime() {
 +  // update local time from NTP server over get minutes and seconds
 +  // from local time hardware
 +  if ( (minute() == 10 && second() == 58) || 
 +       (minute() == 20 && second() == 58) ||
 +       (minute() == 30 && second() == 58) ||
 +       (minute() == 40 && second() == 58) ||
 +       (minute() == 50 && 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,*ntp_minutes,*ntp_seconds,30,11,19);
 +    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, LOW);
 +    stateLights = 'F';
 +  } else {
 +    digitalWrite(lights, HIGH);
 +    stateLights = 'V';
 +  }
 +}
 +
 +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, HIGH);
 +    stateLights = 'V';
 +  } else {
 +    digitalWrite(lights, LOW);
 +    stateLights = 'F';
 +  }
 +}
 +
 +</code>
  
  
  
  
personas/johnny/proyectos/indoor_diy_autosostenible.txt · Última modificación: 2020/08/13 06:00 por kz