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/09/15 20:39] – kz | personas:johnny:proyectos:indoor_diy_autosostenible [2019/09/25 05:05] – kz | ||
---|---|---|---|
Línea 327: | Línea 327: | ||
Serial.print(digits); | Serial.print(digits); | ||
} | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====== Código para el control automatizado de las luces ====== | ||
+ | |||
+ | Este código posee dos funciones que segun el estado se la planta se pueden cambiar para vegetativo o floración. Es un proyecto en platformio | ||
+ | |||
+ | <code c++> | ||
+ | /* | ||
+ | Este código toma la hora de internet usando un servidor NTP y | ||
+ | enciende algo. Tomadpo de aqui https:// | ||
+ | |||
+ | !!! importante | ||
+ | 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 | ||
+ | |||
+ | here -> const long utcOffsetInSeconds = 3600; | ||
+ | */ | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | const char *ssid = "el nombre de la red"; | ||
+ | const char *password = "el password de la red"; | ||
+ | const long utcOffsetInSeconds = -18000; // colombia UTC -5 | ||
+ | char daysOfTheWeek[7][12] = { | ||
+ | " | ||
+ | }; | ||
+ | // Define NTP client to get time | ||
+ | WiFiUDP ntpUDP; | ||
+ | NTPClient timeClient(ntpUDP, | ||
+ | int ledTrigger = D6; | ||
+ | |||
+ | void setup() { | ||
+ | Serial.begin(115200); | ||
+ | WiFi.begin(ssid, | ||
+ | while(WiFi.status() != WL_CONNECTED) { | ||
+ | delay(500); | ||
+ | Serial.print(" | ||
+ | } | ||
+ | Serial.print(" | ||
+ | Serial.println(" | ||
+ | Serial.println(WiFi.localIP()); | ||
+ | timeClient.begin(); | ||
+ | pinMode(LED_BUILTIN, | ||
+ | pinMode(ledTrigger, | ||
+ | } | ||
+ | |||
+ | void statusWIFI() { | ||
+ | // cuando esta pegado a internet el status es 3 | ||
+ | // la idea de esto es que mande un color u otro si tiene internet o no | ||
+ | Serial.print(" | ||
+ | Serial.println(WiFi.status()); | ||
+ | } | ||
+ | |||
+ | void lucesVegetativo() { | ||
+ | // 18 horas luz, 6 horas oscuridad | ||
+ | int hours = timeClient.getHours(); | ||
+ | // se prenden a las 6 de la mañana y se apagan a las 12 de la noche | ||
+ | if ( hours < 6 ) { | ||
+ | digitalWrite(ledTrigger, | ||
+ | Serial.println(" | ||
+ | } else { | ||
+ | digitalWrite(ledTrigger, | ||
+ | Serial.println(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void lucesFloracion() { | ||
+ | // 12 horas luz, 12 horas oscuridad | ||
+ | int hours = timeClient.getHours(); | ||
+ | // a las 6 de la mañana se prenden y a las 6 de la tarde se apagan | ||
+ | if ( (hours >= 6) && (hours < 18) ) { | ||
+ | digitalWrite(ledTrigger, | ||
+ | Serial.println(" | ||
+ | } else { | ||
+ | digitalWrite(ledTrigger, | ||
+ | Serial.println(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // the loop function runs over and over again forever | ||
+ | void loop() { | ||
+ | timeClient.update(); | ||
+ | Serial.print(daysOfTheWeek[timeClient.getDay()]); | ||
+ | Serial.print(", | ||
+ | Serial.print(timeClient.getHours()); | ||
+ | Serial.print(":" | ||
+ | Serial.print(timeClient.getMinutes()); | ||
+ | Serial.print(":" | ||
+ | Serial.print(timeClient.getSeconds()); | ||
+ | Serial.println("" | ||
+ | statusWIFI(); | ||
+ | // | ||
+ | lucesFloracion(); | ||
+ | delay(1000); | ||
+ | |||
+ | /* | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | digitalWrite(ledTrigger, | ||
+ | delay(1000); | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | digitalWrite(ledTrigger, | ||
+ | delay(1000); | ||
+ | */ | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | el platformio.ini | ||
+ | <code json> | ||
+ | ;PlatformIO Project Configuration File | ||
+ | ; | ||
+ | ; Build options: build flags, source filter | ||
+ | ; | ||
+ | ; | ||
+ | ; | ||
+ | ; | ||
+ | ; Please visit documentation for the other options and examples | ||
+ | ; https:// | ||
+ | |||
+ | [env: | ||
+ | platform = espressif8266 | ||
+ | board = d1_mini_lite | ||
+ | framework = arduino | ||
+ | lib_deps = NTPClient | ||
+ | |||
</ | </ | ||
personas/johnny/proyectos/indoor_diy_autosostenible.txt · Última modificación: 2020/08/13 06:00 por kz