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/11/13 06:38] – [Actualización nov 12 2019] kzpersonas:johnny:proyectos:indoor_diy_autosostenible [2019/12/01 07:39] kz
Línea 524: Línea 524:
 {{:personas:johnny:proyectos:indoor-build-and-module6.jpg?400|}} {{:personas:johnny:proyectos:indoor-build-and-module6.jpg?400|}}
  
-<code c+++[[https://gist.github.com/Kaziuz/ad3751c3b075d593cda2c111af3b242b|Link hacia el codigo del indoor]] 
- /Librerias usadas+ 
 + 
 +====== 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> 
 +/* Library used
  * https://github.com/PaulStoffregen/Time  * https://github.com/PaulStoffregen/Time
  * https://github.com/PaulStoffregen/TimeAlarms  * https://github.com/PaulStoffregen/TimeAlarms
  * https://learn.adafruit.com/dht/using-a-dhtxx-sensor  * https://learn.adafruit.com/dht/using-a-dhtxx-sensor
    
- Recursos+ resources from sensor
  * https://www.switchdoc.com/2018/11/tutorial-capacitive-moisture-sensor-grove/  * 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;
 */ */
  
-// import libraries+#include <Arduino.h> 
 +#include <NTPClient.h>
 #include <DHT.h> #include <DHT.h>
-#include <DHT_U.h> 
 #include <Time.h> #include <Time.h>
 #include <SPI.h> #include <SPI.h>
Línea 544: Línea 589:
 #include <ESP8266HTTPClient.h> #include <ESP8266HTTPClient.h>
 #include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
 +#include <WiFiUdp.h>
 +#include <string.h>
  
-// defines and variables globals sensors +// pin out oled ssd1306 
-// dth11 +#define OLED_MOSI 14   //D5 
-#define DHTPIN 4 // D2 +#define OLED_CLK 16    //D0 
-#define DHTTYPE DHT11 +#define OLED_DC 13     //D7 
-#define HTTP_TIMEOUT 4000+#define OLED_CS 15     //D6 
 +#define OLED_RESET 12  //D8
  
-// screen oled +#define lights D1 
-#define OLED_MOSI 14  // D5 +char stateLights = 'F';
-#define OLED_CLK 16   // D0 +
-#define OLED_DC 13    // D7 +
-#define OLED_RESET 12 // D6 +
-#define OLED_CS 15    // D8+
  
-// lights- relay IN4 +// config NTP variables 
-int lights 2+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" 
 +};
  
-// ventilador relay IN3 +const char *ssid = "TP-LINK_Extender_C464C2"; 
-int air 0;+const char *pass "alex1988alex";
  
-// capacitive sensor +// Define NTP client to get time 
-const int waterValue = 464+WiFiUDP ntpUDP
-int soilMoistureValue = 0;+NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
  
 +// config display
 Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
-DHT dht(DHTPINDHTTYPE);+#if (SSD1306_LCDHEIGHT != 64) 
 +//#error("Height incorrectplease fix Adafruit_SH1106.h!"); 
 +#endif 
 + 
 +// define template function 
 +void firstSync(); 
 +void syncNtptoTime(); 
 +void stateVegetative(); 
 +void stateFlowering();
  
 void setup() { void setup() {
 +  // display
   Serial.begin(115200);   Serial.begin(115200);
 +  setTime(time_hours,time_minutes,time_seconds,30,11,19);
 +  WiFi.begin(ssid, pass);
   display.begin(SSD1306_SWITCHCAPVCC);   display.begin(SSD1306_SWITCHCAPVCC);
-  display.clearDisplay();  +  display.clearDisplay();
-  display.setTextSize(0.5);  +
-  display.setTextColor(WHITE); +
-  display.setCursor(0,0);+
   Serial.println();   Serial.println();
   Serial.println();   Serial.println();
-  // +  delay(1000); 
-  for(uint8_t t = 4; t > 0; t--) { +  display.setTextSize(1); 
-    Serial.printf("[SETUP] BOOT WAIT %d...\r\n", t); +  display.setTextColor(WHITE); 
-    Serial.flush(); +  display.setCursor(0,10); 
-    delay(1000); +  display.println("Init ... "); 
-  } +  display.display(); 
-  // +  delay(1000);
-  display.setTextColor(WHITE);  +
-  display.setCursor(0,10);  +
-   +
-  // casa del negro +
-  // WiFi.begin("user", "pass"); +
-  +
   while (WiFi.status() != WL_CONNECTED) {   while (WiFi.status() != WL_CONNECTED) {
     delay(500);     delay(500);
-    display.println("UN/LOQUER - cultiva"); +    display.clearDisplay(); 
 +    display.setTextSize(1); 
 +    display.setCursor(0,10); 
 +    display.setTextColor(BLACK, WHITE); 
 +    display.println("connecting wifi ");
     display.print(".");     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();   display.display();
-  delay(3000); +  firstSync(); 
-  // H, M, S, D, M, A +  delay(5000); 
-  setTime(14,6,0,9,11,19);+  //Serial.print(WiFi.localIP());   
 +  //pinMode(ledTriggerOUTPUT);
   pinMode(lights, OUTPUT);   pinMode(lights, OUTPUT);
-  pinMode(air, OUTPUT); 
-  dht.begin(); 
 } }
  
Línea 613: Línea 684:
   display.setTextColor(WHITE);   display.setTextColor(WHITE);
   display.setCursor(0,0);   display.setCursor(0,0);
-  display.print("time: ");+  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(hour());
   display.print(":");   display.print(":");
Línea 619: Línea 699:
   display.print(":");   display.print(":");
   display.print(second());   display.print(second());
-  display.print(" "); + 
-  display.setCursor(0,8);  +  // time ntp
-  // display alarms lights state +
-  lucesFloracion(); +
-  // display capacitive himudity  +
   display.setCursor(0,16);   display.setCursor(0,16);
-  soilMoistureValue = analogRead(A0); +  display.print("last sync: "); 
-  display.print("Soil moisture: "); +  display.print(*ntp_hours); 
-  display.println(soilMoistureValue);  +  display.print(":"); 
-  delay(500); +  display.print(*ntp_minutes); 
-  // display dht sensor+  display.print(":"); 
 +  display.print(*ntp_seconds); 
 + 
 +  // state lights
   display.setCursor(0,24);   display.setCursor(0,24);
-  int h = dht.readHumidity(); + 
-  int t = dht.readTemperature(); +  syncNtptoTime(); 
-  if (isnan(h) || isnan(t)) { +  // stateFlowering(); 
-    display.println(F("Failed read dht!"))+  stateVegetative(); 
-    return+ 
-  +  // update display
-  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();   display.display();
-  sendDataInflux(String(h), String(t), String(soilMoistureValue));+  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 timeget 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 daysmonth and year ? 
 +    setTime(*ntp_hours,*ntp_minutes,*ntp_seconds,30,11,19)
 +    delay(500); 
 +  }
 } }
  
-void lucesVegetativo() { +void stateVegetative() { 
-  // 18 horas luz, 6 horas oscuridad +  // 18 hours lights, 6 hours night 
-  // se prenden a las de la mañana y se apagan a las 12 de la noche+  // they turn on in the morning and turn off at the 12 last night
   if ( hour() < 6 ) {   if ( hour() < 6 ) {
     digitalWrite(lights, LOW);     digitalWrite(lights, LOW);
-    display.println("Veget Light OFF!");+    stateLights = 'F';
   } else {   } else {
     digitalWrite(lights, HIGH);     digitalWrite(lights, HIGH);
-    display.println("Veget Light ONN!");+    stateLights = 'V';
   }   }
 } }
  
-void lucesFloracion() { +void stateFlowering() { 
-  // 12 horas luz, 12 horas oscuridad+  // 12 hours lights, 12 hours night
   //  a las 6 de la mañana se prenden y a las 6 de la tarde se apagan   //  a las 6 de la mañana se prenden y a las 6 de la tarde se apagan
   if ( (hour() >= 6) && (hour() < 18) ) {   if ( (hour() >= 6) && (hour() < 18) ) {
     digitalWrite(lights, HIGH);     digitalWrite(lights, HIGH);
-    display.println("Flor Light ONN!");+    stateLights = 'V';
   } else {   } else {
     digitalWrite(lights, LOW);     digitalWrite(lights, LOW);
-    display.println("Flor Light OFF");+    stateLights = 'F';
   }   }
 } }
  
-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> </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