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/13 06:38] – [Actualización nov 12 2019] kz | personas:johnny:proyectos:indoor_diy_autosostenible [2019/12/01 07:39] – kz | ||
---|---|---|---|
Línea 524: | Línea 524: | ||
{{: | {{: | ||
- | < | + | [[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 | ||
+ | |||
+ | |||
+ | < | ||
+ | /* Library used | ||
* https:// | * https:// | ||
* https:// | * https:// | ||
* https:// | * https:// | ||
| | ||
- | | + | |
* https:// | * 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; | ||
*/ | */ | ||
- | // import libraries | + | #include < |
+ | #include < | ||
#include < | #include < | ||
- | #include < | ||
#include < | #include < | ||
#include < | #include < | ||
Línea 544: | Línea 589: | ||
#include < | #include < | ||
#include < | #include < | ||
+ | #include < | ||
+ | #include < | ||
- | // defines and variables globals sensors | + | // pin out oled ssd1306 |
- | // dth11 | + | #define OLED_MOSI 14 //D5 |
- | # | + | # |
- | # | + | # |
- | # | + | # |
+ | #define OLED_RESET 12 //D8 | ||
- | // screen oled | + | # |
- | # | + | char stateLights = ' |
- | #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 | + | int time_hours |
+ | 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] = { | ||
+ | " | ||
+ | }; | ||
- | // ventilador | + | const char *ssid = "TP-LINK_Extender_C464C2"; |
- | int air = 0; | + | const char *pass = " |
- | // capacitive sensor | + | // Define NTP client to get time |
- | const int waterValue = 464; | + | WiFiUDP ntpUDP; |
- | int soilMoistureValue = 0; | + | NTPClient timeClient(ntpUDP, |
+ | // config display | ||
Adafruit_SSD1306 display(OLED_MOSI, | Adafruit_SSD1306 display(OLED_MOSI, | ||
- | DHT dht(DHTPIN, DHTTYPE); | + | #if (SSD1306_LCDHEIGHT != 64) |
+ | //# | ||
+ | #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, | ||
+ | WiFi.begin(ssid, | ||
display.begin(SSD1306_SWITCHCAPVCC); | display.begin(SSD1306_SWITCHCAPVCC); | ||
- | display.clearDisplay(); | + | display.clearDisplay(); |
- | display.setTextSize(0.5); | + | |
- | display.setTextColor(WHITE); | + | |
- | display.setCursor(0, | + | |
Serial.println(); | Serial.println(); | ||
Serial.println(); | Serial.println(); | ||
- | | + | |
- | for(uint8_t t = 4; t > 0; t--) { | + | |
- | Serial.printf(" | + | display.setTextColor(WHITE); |
- | | + | display.setCursor(0, |
- | delay(1000); | + | |
- | } | + | |
- | // | + | delay(1000); |
- | display.setTextColor(WHITE); | + | |
- | display.setCursor(0, | + | |
- | | + | |
- | // casa del negro | + | |
- | // WiFi.begin("user", "pass"); | + | |
- | | + | |
while (WiFi.status() != WL_CONNECTED) { | while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | delay(500); | ||
- | display.println(" | + | |
+ | display.setTextSize(1); | ||
+ | display.setCursor(0, | ||
+ | display.setTextColor(BLACK, | ||
+ | | ||
display.print(" | 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(); | display.display(); | ||
- | delay(3000); | + | |
- | // H, M, S, D, M, A | + | |
- | | + | //Serial.print(WiFi.localIP()); |
+ | | ||
pinMode(lights, | pinMode(lights, | ||
- | pinMode(air, | ||
- | dht.begin(); | ||
} | } | ||
Línea 613: | Línea 684: | ||
display.setTextColor(WHITE); | display.setTextColor(WHITE); | ||
display.setCursor(0, | display.setCursor(0, | ||
- | display.print(" | + | |
+ | if (stateLights == ' | ||
+ | | ||
+ | } else { | ||
+ | display.print(" | ||
+ | } | ||
+ | display.println(); | ||
+ | display.setCursor(0, | ||
+ | // time library | ||
+ | display.print(" | ||
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, | + | // time ntp |
- | // display alarms lights state | + | |
- | lucesFloracion(); | + | |
- | // display capacitive himudity | + | |
display.setCursor(0, | display.setCursor(0, | ||
- | | + | |
- | display.print(" | + | display.print(*ntp_hours); |
- | display.println(soilMoistureValue); | + | display.print(":" |
- | | + | display.print(*ntp_minutes); |
- | // display dht sensor | + | |
+ | display.print(*ntp_seconds); | ||
+ | |||
+ | // state lights | ||
display.setCursor(0, | display.setCursor(0, | ||
- | int h = dht.readHumidity(); | + | |
- | | + | |
- | | + | |
- | display.println(F(" | + | |
- | return; | + | |
- | | + | // update display |
- | display.print(F(" | + | |
- | | + | |
- | display.print(F(" | + | |
- | display.print(t); | + | |
- | display.print(F(" | + | |
- | display.println("" | + | |
- | // run air at inddor | + | |
- | ventilacion(); | + | |
display.display(); | display.display(); | ||
- | | + | |
+ | } | ||
+ | |||
+ | 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 lucesVegetativo() { | + | void stateVegetative() { |
- | // 18 horas luz, 6 horas oscuridad | + | // 18 hours lights, 6 hours night |
- | // se prenden a las 6 de la mañana y se apagan a las 12 de la noche | + | // they turn on 6 in the morning and turn off at the 12 last night |
if ( hour() < 6 ) { | if ( hour() < 6 ) { | ||
digitalWrite(lights, | digitalWrite(lights, | ||
- | | + | |
} else { | } else { | ||
digitalWrite(lights, | digitalWrite(lights, | ||
- | | + | |
} | } | ||
} | } | ||
- | 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, | digitalWrite(lights, | ||
- | | + | |
} else { | } else { | ||
digitalWrite(lights, | digitalWrite(lights, | ||
- | | + | |
} | } | ||
} | } | ||
- | void ventilacion() { | ||
- | // se prende cada 15 min 1 min | ||
- | if ( (minute() == 1) || (minute() == 16) || (minute() == 46) || (minute() == 31) ) { | ||
- | digitalWrite(air, | ||
- | } else { | ||
- | digitalWrite(air, | ||
- | } | ||
- | } | ||
- | |||
- | String influxFrame( String dht11_humidity, | ||
- | const String SENSOR_ID = " | ||
- | const String STR_COMMA = ","; | ||
- | const String STR_SLASH = "/"; | ||
- | const String STR_DOT = " | ||
- | const String STR_COLON = ":"; | ||
- | const String STR_NULL = " | ||
- | const String STR_ZERO = " | ||
- | const String STR_SPACE = " "; | ||
- | |||
- | // El primer dato en el squema de la DB es el id del sensor | ||
- | String frame = SENSOR_ID + STR_COMMA + " | ||
- | |||
- | // Add GPS data | ||
- | frame += " | ||
- | frame += " | ||
- | frame += " | ||
- | frame += " | ||
- | frame += " | ||
- | frame += STR_ZERO + STR_COMMA; | ||
- | frame += " | ||
- | frame += STR_ZERO + STR_COMMA; | ||
- | frame += " | ||
- | frame += STR_ZERO + STR_COMMA; | ||
- | |||
- | //Add DHT11 data | ||
- | //if | ||
- | frame += " | ||
- | frame += dht11_humidity + STR_COMMA; | ||
- | frame += " | ||
- | frame += dht11_temperature + STR_COMMA; | ||
- | // } else { | ||
- | // frame += " | ||
- | // } | ||
- | |||
- | // ADD capacitive sensor data | ||
- | frame += " | ||
- | frame += soilCapacitiveSensor + STR_COMMA; | ||
- | | ||
- | // Add Plantower data | ||
- | // if | ||
- | frame += " | ||
- | frame += STR_ZERO + STR_COMMA; | ||
- | frame += " | ||
- | frame += STR_ZERO + STR_COMMA; | ||
- | frame += " | ||
- | frame += STR_ZERO; | ||
- | // } else { | ||
- | // frame += " | ||
- | // } | ||
- | |||
- | return frame; | ||
- | } | ||
- | |||
- | // función que envía la trama de datos | ||
- | void sendDataInflux ( String humidity, String temperature, | ||
- | // El post a la base de datos tiene una trama siguiente: | ||
- | // volker0001, | ||
- | // 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, | ||
- | | ||
- | HTTPClient http; | ||
- | // _testsensorhumedad es el nombre de la DB donde se almacenan estos datos | ||
- | http.begin(" | ||
- | http.setTimeout(HTTP_TIMEOUT); | ||
- | http.addHeader(" | ||
- | |||
- | // esto se debe de integrar con el soil capacitive sensor | ||
- | // String frame = influxFrame(humidity, | ||
- | String frame = influxFrame(humidity, | ||
- | |||
- | int httpCode = http.POST(frame); | ||
- | |||
- | if(httpCode > 0) { | ||
- | String payload = http.getString(); | ||
- | Serial.println(payload); | ||
- | Serial.println(" | ||
- | } else { | ||
- | Serial.print(" | ||
- | Serial.println(http.errorToString(httpCode).c_str()); | ||
- | } | ||
- | | ||
- | } | ||
- | delay(60000); | ||
- | } | ||
</ | </ | ||
- | |||
- | |||
- | ====== 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. | ||
- | |||
- | **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, | ||
- | - 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