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/11/03 13:42] – [actualizacion nov 3 2019] kz | personas:johnny:proyectos:indoor_diy_autosostenible [2019/12/01 07:40] – kz | ||
---|---|---|---|
Línea 524: | Línea 524: | ||
{{: | {{: | ||
- | Tareas que faltan por hacer!!! | + | [[https:// |
- | - Íntegrar el envío de datos al influx deñ dth11 + el capasitive sensor PRIORIDAD!!! | ||
- | - integrar una web en la flash para programar la fecha del rtc digital 8-) < | ||
+ | ====== Actualización nov 9 2019 ====== | ||
- | <script c++> | + | Hasta ahora la libreria time.h a funcionado muy bien, reemplazandome por completo un rtc. |
- | / | + | === Los datos se puede ver en:=== |
- | Este ejemplo es para los oled de 128x64 usando SPI y Drivers | + | |
- | SSD1306 o SH1106 ambos con 7 pines de conexión.- | + | |
- | Se utilizan las librerias de Adafruit. | + | |
- | *********************************************************************/ | + | |
+ | [[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 < | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
- | // Definir pines SPI en Arduino | + | // pin out oled ssd1306 |
+ | #define OLED_MOSI 14 // | ||
+ | #define OLED_CLK 16 //D0 | ||
+ | #define OLED_DC 13 // | ||
+ | #define OLED_CS 15 // | ||
+ | #define OLED_RESET 12 //D8 | ||
- | # | + | # |
- | #define OLED_CLK 16 // D0 | + | char stateLights = ' |
- | #define OLED_DC 13 // D7 | + | |
- | #define OLED_RESET 12 // D6 | + | |
- | #define OLED_CS 15 // D8 | + | |
+ | // 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] = { | ||
+ | " | ||
+ | }; | ||
- | // A continuación informamos al soft del driver, | + | const char *ssid = " |
- | // Para SH1106 descomentar siguiente comando | + | const char *pass = " |
- | //Adafruit_SH1106 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); | + | |
- | // Para SSD1306 descomentar siguiente comando | + | // Define NTP client to get time |
+ | WiFiUDP ntpUDP; | ||
+ | NTPClient timeClient(ntpUDP, " | ||
+ | |||
+ | // config display | ||
Adafruit_SSD1306 display(OLED_MOSI, | Adafruit_SSD1306 display(OLED_MOSI, | ||
- | // Para SH1106 descomentar siguiente comando | ||
- | //#if (SH1106_LCDHEIGHT != 64) | ||
- | // Para SSD1306 descomentar siguiente comando | ||
#if (SSD1306_LCDHEIGHT != 64) | #if (SSD1306_LCDHEIGHT != 64) | ||
//# | //# | ||
#endif | #endif | ||
- | void setup() | + | // define template function |
- | { | + | void firstSync(); |
- | | + | void syncNtptoTime(); |
- | // Para SH1106 descomentar siguiente comando | + | void stateVegetative(); |
- | //display.begin(SH1106_SWITCHCAPVCC); // Inicia el display | + | void stateFlowering(); |
- | // Para SSD1306 descomentar siguiente comando | + | |
- | | + | void setup() |
- | | + | // display |
- | | + | |
- | | + | setTime(time_hours,time_minutes, |
- | | + | |
- | | + | display.begin(SSD1306_SWITCHCAPVCC); |
- | | + | |
- | | + | |
+ | | ||
+ | delay(1000); | ||
+ | | ||
+ | | ||
+ | | ||
+ | display.println(" | ||
+ | display.display(); | ||
+ | delay(1000); | ||
+ | while (WiFi.status() != WL_CONNECTED) { | ||
+ | delay(500); | ||
+ | | ||
+ | display.setTextSize(1); | ||
+ | | ||
+ | | ||
+ | display.println(" | ||
+ | | ||
+ | display.display(); | ||
+ | } | ||
+ | display.clearDisplay(); | ||
+ | display.setTextSize(1); | ||
+ | | ||
+ | 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, | ||
+ | display.println(" | ||
+ | display.display(); | ||
+ | | ||
+ | | ||
+ | | ||
+ | // | ||
+ | pinMode(lights, | ||
} | } | ||
void loop() { | 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, | ||
+ | // | ||
+ | display.print(" | ||
+ | display.print(hour()); | ||
+ | display.print(":" | ||
+ | display.print(minute()); | ||
+ | display.print(":" | ||
+ | display.print(second()); | ||
- | // Cuando se quiera mostrar nueva información | + | |
- | display.clearDisplay(); | + | display.setCursor(0,16); |
- | display.setTextSize(0.5); // Definir Tamaño del Texto | + | display.print("last sync: "); |
- | display.setTextColor(WHITE); // Definir color del texto. (mono=> | + | display.print(*ntp_hours); |
- | | + | display.print(":"); |
- | display.setCursor(0,0); // Definir posición inicio texto Columna (0) Fila (0) | + | display.print(*ntp_minutes); |
- | display.println("El gordo es un hp!" | + | display.print(":"); |
- | display.setCursor(0,8); // Definir posición inicio texto Columna (0) Fila (0) | + | display.print(*ntp_seconds); |
- | display.println("golondras!" | + | |
- | display.setCursor(0,16); // Definir posición inicio texto Columna (0) Fila (0) | + | // state lights |
- | | + | display.setCursor(0, |
- | display.setCursor(0, | + | |
- | | + | syncNtptoTime(); |
- | display.display(); | + | |
- | delay(2000); // Demora de 2 segundos. | + | |
+ | |||
+ | | ||
+ | display.display(); | ||
+ | delay(1000); | ||
} | } | ||
- | </script> | + | void firstSync() { |
+ | | ||
+ | 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