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/11/13 06:38] – [Actualización nov 12 2019] kz
Línea 502: Línea 502:
 Sensor totalmente humedo: 482 Sensor totalmente humedo: 482
 </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|}}
 +
 +<code c++>
 + /* Librerias usadas
 + * https://github.com/PaulStoffregen/Time
 + * https://github.com/PaulStoffregen/TimeAlarms
 + * https://learn.adafruit.com/dht/using-a-dhtxx-sensor
 + 
 + * Recursos
 + * https://www.switchdoc.com/2018/11/tutorial-capacitive-moisture-sensor-grove/
 +*/
 +
 +// import libraries
 +#include <DHT.h>
 +#include <DHT_U.h>
 +#include <Time.h>
 +#include <SPI.h>
 +#include <Wire.h>
 +#include <Adafruit_GFX.h>
 +#include <Adafruit_SSD1306.h>
 +#include <ESP8266HTTPClient.h>
 +#include <ESP8266WiFi.h>
 +
 +// defines and variables globals sensors
 +// dth11
 +#define DHTPIN 4 // D2
 +#define DHTTYPE DHT11
 +#define HTTP_TIMEOUT 4000
 +
 +// screen oled
 +#define OLED_MOSI 14  // D5
 +#define OLED_CLK 16   // D0
 +#define OLED_DC 13    // D7
 +#define OLED_RESET 12 // D6
 +#define OLED_CS 15    // D8
 +
 +// lights- relay IN4
 +int lights = 2; 
 +
 +// ventilador - relay IN3
 +int air = 0;
 +
 +// capacitive sensor
 +const int waterValue = 464;
 +int soilMoistureValue = 0;
 +
 +Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
 +DHT dht(DHTPIN, DHTTYPE);
 +
 +void setup() {
 +  Serial.begin(115200);
 +  display.begin(SSD1306_SWITCHCAPVCC);
 +  display.clearDisplay(); 
 +  display.setTextSize(0.5); 
 +  display.setTextColor(WHITE);
 +  display.setCursor(0,0);
 +  Serial.println();
 +  Serial.println();
 +  //
 +  for(uint8_t t = 4; t > 0; t--) {
 +    Serial.printf("[SETUP] BOOT WAIT %d...\r\n", t);
 +    Serial.flush();
 +    delay(1000);
 +  }
 +  //
 +  display.setTextColor(WHITE); 
 +  display.setCursor(0,10); 
 +  
 +  // casa del negro
 +  // WiFi.begin("user", "pass");
 +  
 +  while (WiFi.status() != WL_CONNECTED) {
 +    delay(500);
 +    display.println("UN/LOQUER - cultiva"); 
 +    display.print(".");
 +  }
 +
 +  display.display();
 +  delay(3000);
 +  // H, M, S, D, M, A
 +  setTime(14,6,0,9,11,19);
 +  pinMode(lights, OUTPUT);
 +  pinMode(air, OUTPUT);
 +  dht.begin();
 +}
 +
 +void loop() {
 +  display.clearDisplay();
 +  display.setTextSize(0.5);
 +  display.setTextColor(WHITE);
 +  display.setCursor(0,0);
 +  display.print("time: ");
 +  display.print(hour());
 +  display.print(":");
 +  display.print(minute());
 +  display.print(":");
 +  display.print(second());
 +  display.print(" ");
 +  display.setCursor(0,8); 
 +  // display alarms lights state
 +  lucesFloracion();
 +  // display capacitive himudity  
 +  display.setCursor(0,16);
 +  soilMoistureValue = analogRead(A0);
 +  display.print("Soil moisture: ");
 +  display.println(soilMoistureValue); 
 +  delay(500);
 +  // display dht sensor
 +  display.setCursor(0,24);
 +  int h = dht.readHumidity();
 +  int t = dht.readTemperature();
 +  if (isnan(h) || isnan(t)) {
 +    display.println(F("Failed read dht!"));
 +    return;
 +  }
 +  display.print(F("Hum: "));
 +  display.print(h);
 +  display.print(F(" %  Tem: "));
 +  display.print(t);
 +  display.print(F(" C "));
 +  display.println("");
 +  // run air at inddor
 +  ventilacion();
 +  display.display();
 +  sendDataInflux(String(h), String(t), String(soilMoistureValue));
 +}
 +
 +void lucesVegetativo() {
 +  // 18 horas luz, 6 horas oscuridad
 +  // se prenden a las 6 de la mañana y se apagan a las 12 de la noche
 +  if ( hour() < 6 ) {
 +    digitalWrite(lights, LOW);
 +    display.println("Veget Light OFF!");
 +  } else {
 +    digitalWrite(lights, HIGH);
 +    display.println("Veget Light ONN!");
 +  }
 +}
 +
 +void lucesFloracion() {
 +  // 12 horas luz, 12 horas oscuridad
 +  //  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);
 +    display.println("Flor Light ONN!");
 +  } else {
 +    digitalWrite(lights, LOW);
 +    display.println("Flor Light OFF");
 +  }
 +}
 +
 +void ventilacion() {
 +  // se prende cada 15 min 1 min
 +  if ( (minute() == 1) || (minute() == 16) || (minute() == 46) || (minute() == 31) ) {
 +    digitalWrite(air, HIGH);
 +  } else {
 +    digitalWrite(air, LOW);
 +  }
 +}
 +
 +String influxFrame( String dht11_humidity, String dht11_temperature, String soilCapacitiveSensor) {
 +  const String SENSOR_ID = "DHT11_llanadas"; // Nombre del sensor en la plataforma, la 1 VEZ CAMBIAR !!!!
 +  const String STR_COMMA = ",";
 +  const String STR_SLASH = "/";
 +  const String STR_DOT = ".";
 +  const String STR_COLON = ":";
 +  const String STR_NULL = "NULL";
 +  const String STR_ZERO = "0";
 +  const String STR_SPACE = " ";
 + 
 +  // El primer dato en el squema de la DB es el id del sensor
 +  String frame = SENSOR_ID + STR_COMMA + "id=" + SENSOR_ID +  STR_SPACE;
 + 
 +  // Add GPS data
 +  frame += "lat=";
 +  frame += "6.2563143" + STR_COMMA; // coordenada GSP lat
 +  frame += "lng=";
 +  frame += "-75.5386472" + STR_COMMA; // coordenada lng lat
 +  frame += "altitude=";
 +  frame += STR_ZERO + STR_COMMA;
 +  frame += "course=";
 +  frame += STR_ZERO + STR_COMMA;
 +  frame += "speed=";
 +  frame += STR_ZERO + STR_COMMA;
 + 
 +  //Add DHT11 data
 +  //if
 +    frame += "humidity=";
 +    frame += dht11_humidity + STR_COMMA;
 +    frame += "temperature=";
 +    frame += dht11_temperature + STR_COMMA;
 +  // } else {
 +  //   frame += "humidity=" + STR_NULL + STR_COMMA + "temperature=" + STR_NULL + STR_COMMA;
 +  // }
 +
 +  // ADD capacitive sensor data
 +  frame += "soil_capacitive=";
 +  frame += soilCapacitiveSensor + STR_COMMA;
 +    
 +  // Add Plantower data
 +    // if
 +    frame += "pm1=";
 +    frame += STR_ZERO + STR_COMMA;
 +    frame += "pm25=";
 +    frame += STR_ZERO + STR_COMMA;
 +    frame += "pm10=";
 +    frame += STR_ZERO;
 +  // } else {
 +  //   frame += "pm1=" + STR_NULL + STR_COMMA + "pm25=" + STR_NULL + STR_COMMA + "pm10=" + STR_NULL;
 +  // }
 + 
 +  return frame;
 +}
 + 
 +// función que envía la trama de datos
 +void sendDataInflux ( String humidity, String temperature, String _soilCapacitiveSensor ) {
 +  // El post a la base de datos tiene una trama siguiente:
 +  // volker0001,id=volker0001 lat=6.268115,lng=-75.543407,altitude=1801.1,course=105.55,speed=0.00,humidity=37.00,temperature=25.00,pm1=22,pm25=31,pm10=32
 +  // Para nuestro caso que SOLO es el envío de datos del dht_11 que es humedad y temperatura la trama es la siguiente
 +  // DHT11_llanadas, id=DHT11_llanadas, lat=6.2563143, lng=-75.5386472, altitude=0, course=0, speed=0, humidity=37.00, temperature=25.00, pm1=0, pm25=0, pm10=0 1434055562000000000 
 + if(WiFi.status() == 3) {
 +    HTTPClient http; 
 +    // _testsensorhumedad es el nombre de la DB donde se almacenan estos datos
 +    http.begin("http://aqa.unloquer.org:8086/write?db=_testsensorhumedad"); // endPoint final, '_testsensorhumedad' es el nombre de la base de datos
 +    http.setTimeout(HTTP_TIMEOUT);
 +    http.addHeader("Content-Type", "--data-binary");  
 +
 +    // esto se debe de integrar con el soil capacitive sensor
 +    // String frame = influxFrame(humidity, temperature, _soilCapacitiveSensor); // Construimos el request POST
 +    String frame = influxFrame(humidity, temperature, _soilCapacitiveSensor);
 +   
 +    int httpCode = http.POST(frame); // Envíamos los datos haciendo un POST
 +   
 +    if(httpCode > 0) {
 +      String payload = http.getString();
 +      Serial.println(payload);
 +      Serial.println("Envío de datos con exito!");
 +    } else {
 +      Serial.print("[HTTP] failed, error;");
 +      Serial.println(http.errorToString(httpCode).c_str());
 +    }
 +     http.end();
 +  }
 +    delay(60000);
 +}
 +</code>
 +
 +
 +====== 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.
 +
 +**Tareas hechas**
 +
 +  - Enviar trama de datos al influx: HECHO
 +  - En esta imlementación de POST hacia una base de datos, se cae el esp y hace que reinice: HECHO. esto era ocasionado en el #define TIME_OUT
 +
 +
 +**
 +Tareas que faltan por hacer!!!**
 +
 +
 +  - 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
 +
 +
 +
 + 
  
  
personas/johnny/proyectos/indoor_diy_autosostenible.txt · Última modificación: 2020/08/13 06:00 por kz