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/15 20:39] kzpersonas:johnny:proyectos:indoor_diy_autosostenible [2019/09/25 05:05] kz
Línea 327: Línea 327:
   Serial.print(digits);   Serial.print(digits);
 } }
 +</code>
 +
 +
 +====== 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://lastminuteengineers.com/esp8266-ntp-server-date-time-tutorial/
 +
 +  !!! importante
 +  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
 +
 +  here -> const long utcOffsetInSeconds = 3600;
 +*/
 +#include <Arduino.h>
 +#include <NTPClient.h>
 +#include <ESP8266WiFi.h>
 +#include <WiFiUdp.h>
 +
 +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] = {
 +  "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
 +};
 +// Define NTP client to get time
 +WiFiUDP ntpUDP;
 +NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
 +int ledTrigger = D6;
 +
 +void setup() {
 +  Serial.begin(115200);
 +  WiFi.begin(ssid, password);
 +  while(WiFi.status() != WL_CONNECTED) {
 +    delay(500);
 +    Serial.print(".");
 +  }
 +  Serial.print("Wifi connected!");
 +  Serial.println("IP address: ");
 +  Serial.println(WiFi.localIP());  
 +  timeClient.begin();
 +  pinMode(LED_BUILTIN, OUTPUT);
 +  pinMode(ledTrigger, OUTPUT);
 +}
 +
 +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("Estatus wifi is: ");
 +  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, LOW);
 +    Serial.println("Luces OFF!");
 +  } else {
 +    digitalWrite(ledTrigger, HIGH);
 +    Serial.println("Luces ONN!");
 +  }
 +}
 +
 +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, HIGH);
 +    Serial.println("Luces ONN!");
 +  } else {
 +    digitalWrite(ledTrigger, LOW);
 +    Serial.println("Luces OFF");
 +  }
 +}
 +
 +// 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();
 +  //lucesVegetativo();
 +  lucesFloracion();
 +  delay(1000);
 +
 +  /*
 +  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)}
 +  digitalWrite(ledTrigger, HIGH);
 +  delay(1000);                       // wait for a second
 +  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
 +  digitalWrite(ledTrigger, LOW);
 +  delay(1000);                       // wait for a second
 +  */
 +}
 +</code>
 +
 +el platformio.ini
 +<code json>
 +;PlatformIO Project Configuration File
 +;
 +;   Build options: build flags, source filter
 +;   Upload options: custom upload port, speed and extra flags
 +;   Library options: dependencies, extra library storages
 +;   Advanced options: extra scripting
 +;
 +; Please visit documentation for the other options and examples
 +; https://docs.platformio.org/page/projectconf.html
 +
 +[env:d1_mini_lite]
 +platform = espressif8266
 +board = d1_mini_lite
 +framework = arduino
 +lib_deps = NTPClient
 +
 </code> </code>
  
  
  
personas/johnny/proyectos/indoor_diy_autosostenible.txt · Última modificación: 2020/08/13 06:00 por kz