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/06/19 07:35] – kz | personas:johnny:proyectos:indoor_diy_autosostenible [2019/09/25 05:04] – kz |
---|
dht.begin(); | dht.begin(); |
// nombre del wifi y clave del wifi al cual se va a conectar el esp | // nombre del wifi y clave del wifi al cual se va a conectar el esp |
WiFi.begin("RAMIREZ_BO", "10101973"); | WiFi.begin("name wifi", "wifi password"); |
| |
while (WiFi.status() != WL_CONNECTED) { | while (WiFi.status() != WL_CONNECTED) { |
Se intenta manipular relays, mosttar datos en pantallay enviar datos a una base de datos influxdb | Se intenta manipular relays, mosttar datos en pantallay enviar datos a una base de datos influxdb |
| |
// A ESTE CÖDIGO FALTA IMPLEMENTAR ENVIO DE DATOS AL INFLUX CON WEBSOCKETS | A ESTE CÖDIGO FALTA IMPLEMENTAR ENVIO DE DATOS AL INFLUX CON WEBSOCKETS. |
| |
| [[https://gist.github.com/Kaziuz/d00f4e2e29e292fd1009cc028dc4aecd|Gist al código]] |
| |
| |
| ==== Construcción física del indoor ==== |
| |
| [[https://www.taringa.net/+hazlo_tu_mismo/como-hacer-armario-cultivo-indoor-sensillo-barato-y-discreto_twzl4|versión barata y sencilla]] |
| |
| [[https://www.how-to-marijuana.com/beginners-growing-marijuana-indoors.html|la opción cara y vacana]] |
| |
| [[https://www.taringa.net/+cannabis/aporte-todo-para-tu-indoor-desde-cero-thc-n-84_u5ecv|Un resumen de una revista especializada]] |
| |
| ====== Código para la ventilación usando timeAlarms ====== |
| |
<code c++> | <code c++> |
#include <ESP8266WiFi.h> | |
#include <ESP8266WiFiMulti.h> | |
#include <WebSocketsServer.h> | |
#include <Hash.h> | |
#include <ESP8266WebServer.h> | |
#include <ESP8266mDNS.h> | |
#include <SPI.h> | |
#include <Wire.h> | |
#include <Adafruit_GFX.h> | |
#include <Adafruit_SSD1306.h> | |
//#include <ESP8266HTTPClient.h> | |
#include "DHT.h" | |
| |
#define DHTPIN D6 // Pin que va conectado al sensor | // https://github.com/PaulStoffregen/TimeAlarms |
#define DHTTYPE DHT11 // Tipo de sensor que estamos usando | // Librerias |
#define HTTP_TIMEOUT 1000 * 60 // cada minuto | #include <Time.h> |
DHT dht(DHTPIN, DHTTYPE); | #include <TimeAlarms.h> |
| |
// If using software SPI (the default case): | // pin que controla |
#define OLED_MOSI D7 //D1 | int pin = 13; |
#define OLED_CLK D5 //D0 | |
#define OLED_DC D4 | |
#define OLED_CS D8 | |
#define OLED_RESET D0 | |
| |
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); | int alarma = 900; // cada 15 min |
| |
static const char ssid[] = "d(O_O)b"; | void setup() { |
static const char password[] = "alex1988alex"; | |
MDNSResponder mdns; | Serial.begin(9600); |
| //fijamos el tiempo inicial del esp |
static void writeLED(bool); | // (08:30:00 25/05/17) |
| setTime(8,10,0,28,5,19); |
ESP8266WiFiMulti WiFiMulti; | |
| //Creamos las alarmas |
ESP8266WebServer server(80); | //Alarm.alarmRepeat(8,init15,0,EveningAlarm); Alarma que se inicia cada día |
WebSocketsServer webSocket = WebSocketsServer(81); | //Alarm.alarmRepeat(8,end15,0,apagarVentilador); Alarma que termina cada día |
| |
static const char PROGMEM INDEX_HTML[] = R"rawliteral( | Alarm.timerRepeat(alarma, Repeats); // Timer cada 15 segundos |
<!DOCTYPE html> | |
<html> | //Alarm.alarmRepeat(17,45,0,EveningAlarm); 5:45pm cada día |
<head> | //Alarm.alarmRepeat(dowSaturday,8,30,30,WeeklyAlarm); 8:30:30 cada sabado |
<meta name = "viewport" content = "width = device-width, initial-scale = 1.0, maximum-scale = 1.0, user-scalable=0"> | //Alarm.timerRepeat(alarma, Repeats); Timer cada 15 segundos |
<title>ESP8266 WebSocket Demo</title> | //Alarm.timerOnce(10, OnceOnly); Llamado una vez despues de 10 segundos |
<style> | |
"body { background-color: #808080; font-family: Arial, Helvetica, Sans-Serif; Color: #000000; }" | pinMode(pin, OUTPUT); |
</style> | |
<script> | |
var websock; | |
var webSockInflux; // se tiene que mandar los datos por un websocket | |
function start() { | |
websock = new WebSocket('ws://' + window.location.hostname + ':81/'); | |
websock.onopen = function(evt) { console.log('websock open'); }; | |
websock.onclose = function(evt) { console.log('websock close'); }; | |
websock.onerror = function(evt) { console.log(evt); }; | |
websock.onmessage = function(evt) { | |
console.log(evt); | |
| |
var e = document.getElementById('ledstatus'); | |
var f = document.getElementById('ledstatus2'); | |
| |
if (evt.data === 'ledon') { | |
e.style.color = 'red'; | |
} | |
else if (evt.data === 'ledoff') { | |
e.style.color = 'black'; | |
} | |
else if (evt.data === 'ledon1') { | |
f.style.color = 'red'; | |
} | |
else if (evt.data === 'ledoff1') { | |
f.style.color = 'black'; | |
} | |
else { | |
console.log('unknown event'); | |
} | |
}; | |
} | } |
| |
function buttonclick(e) { | void loop() { |
websock.send(e.id); | digitalClockDisplay(); |
| Alarm.delay(1000); |
} | } |
| |
</script> | // encender ventilador |
</head> | void prenderVentilador(){ |
<body onload="javascript:start();"> | Serial.println("Ventilando"); |
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxMTEhUSEBISFhUXFhcWFxcXFhAXGxoYFx0XFxUVGBgZHigiGRolGxUVIjEhJyktLi4uGB8zOTMtNyguLisBCgoKDg0NFQ8QFysdHR0rKy0tLS0tKy0tLS0tKy0tLSstLS0tLi0rLS0tLSstLTctLS0tNy03LS0tNzc3Ny0tLf/AABEIANAA8gMBIgACEQEDEQH/xAAcAAEAAgMBAQEAAAAAAAAAAAAABQYBAwQCBwj/xABKEAACAQIDAggLBQUGBgMBAAABAgMAEQQSIQUxEyIyQVFxcrEGBxczVGGBkZOh0hQjNUKzFVJigrJzkqKjwcIkNENkg/BTdNEW/8QAFgEBAQEAAAAAAAAAAAAAAAAAAAEC/8QAGBEBAQEBAQAAAAAAAAAAAAAAABEBQTH/2gAMAwEAAhEDEQA/AL/t7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9JPwsT9FBb6VUPKZsz0k/CxP0U8pmzPST8LE/RQW+lVDymbM9JPwsT9FPKZsz0k/CxP0UFvpVQ8pmzPST8LE/RTymbM9JPwsT9FBb64NvYxYcNNK5sqRux9gNh1k6e2q83jM2d+SZ3bmVYcQST0AFRrXDLBidrOonhfDYBWDmOTSXEFdVDL+SO/N37wVTdkeAOJkgikAFnjRxe+5lBHN66V9uVbCw3ClSLX/9k=" width="140px"/> | digitalWrite(pin, HIGH); |
<h4>Automatic grow garden</h4> | } |
<div id="ledstatus"><b>RELAY 1</b></div> | |
<button id="ledon" type="button" onclick="buttonclick(this);">On</button> | |
<button id="ledoff" type="button" onclick="buttonclick(this);">Off</button> | |
<br /> | |
<br /> | |
| |
<div id="ledstatus2"><b>Relay 2</b></div> | |
<button id="ledon1" type="button" onclick="buttonclick(this);">On</button> | |
<button id="ledoff1" type="button" onclick="buttonclick(this);">Off</button> | |
| |
</body> | // encender ventilador |
</html> | void apagarVentilador(){ |
)rawliteral"; | Serial.println("apagando ventilador"); |
| digitalWrite(pin, LOW); |
// GPIO#0 is for Adafruit ESP8266 HUZZAH board. Your board LED might be on 13. | } |
const int LEDPIN = D1; | |
const int LEDPIN1 = D3; | |
// Current LED status | |
bool LEDStatus; | |
bool LEDStatus1; | |
| |
// Commands sent through Web Socket | |
const char LEDON[] = "ledon"; | |
const char LEDOFF[] = "ledoff"; | |
| |
// Commands sent through Web Socket | // función que enciende el riego |
const char LEDON1[] = "ledon1"; | void prenderSensorRiegoManana(){ |
const char LEDOFF1[] = "ledoff1"; | Serial.println("Alarm: - Sensor encendido y regando"); |
| digitalWrite(pin, HIGH); |
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) | |
{ | |
Serial.printf("webSocketEvent(%d, %d, ...)\r\n", num, type); | |
switch(type) { | |
case WStype_DISCONNECTED: | |
Serial.printf("[%u] Disconnected!\r\n", num); | |
break; | |
case WStype_CONNECTED: | |
{ | |
IPAddress ip = webSocket.remoteIP(num); | |
Serial.printf("[%u] Connected from %d.%d.%d.%d url: %s\r\n", num, ip[0], ip[1], ip[2], ip[3], payload); | |
// Send the current LED status | |
if (LEDStatus) { | |
webSocket.sendTXT(num, LEDON, strlen(LEDON)); | |
} | |
else { | |
webSocket.sendTXT(num, LEDOFF, strlen(LEDOFF)); | |
} | |
| |
// Send the current LED status | |
if (LEDStatus1) { | |
webSocket.sendTXT(num, LEDON1, strlen(LEDON1)); | |
} | |
else { | |
webSocket.sendTXT(num, LEDOFF1, strlen(LEDOFF1)); | |
} | |
} | |
break; | |
case WStype_TEXT: | |
Serial.printf("[%u] get Text: %s\r\n", num, payload); | |
| |
if (strcmp(LEDON, (const char *)payload) == 0) { | |
writeLED(true); | |
} | |
else if (strcmp(LEDOFF, (const char *)payload) == 0) { | |
writeLED(false); | |
} | |
else if (strcmp(LEDON1, (const char *)payload) == 0) { | |
writeLED1(true); | |
} | |
else if (strcmp(LEDOFF1, (const char *)payload) == 0) { | |
writeLED1(false); | |
} | |
else { | |
Serial.println("Unknown command"); | |
} | |
// send data to all connected clients | |
webSocket.broadcastTXT(payload, length); | |
break; | |
case WStype_BIN: | |
Serial.printf("[%u] get binary length: %u\r\n", num, length); | |
hexdump(payload, length); | |
| |
// echo data back to browser | |
webSocket.sendBIN(num, payload, length); | |
break; | |
default: | |
Serial.printf("Invalid WStype [%d]\r\n", type); | |
break; | |
} | |
} | } |
| |
void handleRoot() | // función que apaga el riego |
{ | void apagarSensorRiegoManana(){ |
server.send_P(200, "text/html", INDEX_HTML); | Serial.println("Alarm: - Sensor apagado y riego apagado"); |
| digitalWrite(pin, LOW); |
} | } |
| |
void handleNotFound() | void EveningAlarm(){ |
{ | Serial.println("Alarm: - turn lights on"); |
String message = "File Not Found\n\n"; | |
message += "URI: "; | |
message += server.uri(); | |
message += "\nMethod: "; | |
message += (server.method() == HTTP_GET)?"GET":"POST"; | |
message += "\nArguments: "; | |
message += server.args(); | |
message += "\n"; | |
for (uint8_t i=0; i<server.args(); i++){ | |
message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; | |
} | |
server.send(404, "text/plain", message); | |
} | } |
| |
static void writeLED(bool LEDon) | void WeeklyAlarm(){ |
{ | Serial.println("Alarm: - its Monday Morning"); |
LEDStatus = LEDon; | |
// Note inverted logic for Adafruit HUZZAH board | |
if (LEDon) { | |
digitalWrite(LEDPIN, 1); | |
} | |
else { | |
digitalWrite(LEDPIN, 0); | |
} | |
} | } |
| |
static void writeLED1(bool LEDon) | void ExplicitAlarm(){ |
{ | Serial.println("Alarm: - this triggers only at the given date and time"); |
LEDStatus1 = LEDon; | |
// Note inverted logic for Adafruit HUZZAH board | |
if (LEDon) { | |
digitalWrite(LEDPIN1, 1); | |
} | |
else { | |
digitalWrite(LEDPIN1, 0); | |
} | |
} | } |
| |
// función que prepara la trama de datos para hacer un POST a endpoint del influx | void Repeats(){ |
String influxFrame( String dht11_humidity, String dht11_temperature ) { | digitalWrite(pin, HIGH); |
// este es el nombre del sensor | Alarm.delay(60000); |
// Siempre que se quema la primera vez, se debe de cambiar el nombre del sensor | Serial.println("ventilando x un minuto"); |
const String SENSOR_ID = "DHT11_llanadas"; // Nombre del sensor en la plataforma | digitalWrite(pin, LOW); |
| Alarm.delay(1000); |
const String STR_COMMA = ","; | Serial.println("apagando ventilador"); |
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 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 OnceOnly(){ |
void sendDataInflux ( String humidity, String temperature ) { | Serial.println("This timer only triggers once"); |
/* | |
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 | |
*/ | |
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"); | |
| |
String frame = influxFrame(humidity, temperature); // Construimos el request POST | |
| |
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); // cada minuto se envía un POST al influx | |
} | } |
| |
void setup() | void digitalClockDisplay() |
{ | { |
pinMode(LEDPIN, OUTPUT); | // digital clock display of the time |
pinMode(LEDPIN1, OUTPUT); | Serial.print(hour()); |
writeLED(false); | printDigits(minute()); |
writeLED1(false); | printDigits(second()); |
| Serial.println(); |
Serial.begin(115200); | } |
| |
// init pantalla | void printDigits(int digits) |
display.begin(SSD1306_SWITCHCAPVCC); | { |
display.display(); | Serial.print(":"); |
delay(1000); | if(digits < 10) |
display.clearDisplay(); | Serial.print('0'); |
display.setTextSize(1); | Serial.print(digits); |
display.setTextColor(WHITE); | } |
| </code> |
| |
Serial.println(F("DHTxx test!")); | |
dht.begin(); | |
| |
//Serial.setDebugOutput(true); | |
| |
Serial.println(); | |
Serial.println(); | |
Serial.println(); | |
| |
for(uint8_t t = 4; t > 0; t--) { | |
Serial.printf("[SETUP] BOOT WAIT %d...\r\n", t); | |
Serial.flush(); | |
delay(1000); | |
} | |
| |
| ====== Código para el control automatizado de las luces ====== |
| |
WiFiMulti.addAP(ssid, password); | 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 |
| |
while(WiFiMulti.run() != WL_CONNECTED) { | <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 = "TP-LINK_Extender_C464C2"; |
| const char *password = "alex1988alex"; |
| 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("."); |
delay(100); | |
} | } |
| Serial.print("Wifi connected!"); |
Serial.println(""); | Serial.println("IP address: "); |
Serial.print("Connected to "); | Serial.println(WiFi.localIP()); |
Serial.println(ssid); | timeClient.begin(); |
Serial.print("IP address: "); | pinMode(LED_BUILTIN, OUTPUT); |
Serial.println(WiFi.localIP()); | pinMode(ledTrigger, OUTPUT); |
| } |
if (mdns.begin("espWebSock", WiFi.localIP())) { | |
Serial.println("MDNS responder started"); | void statusWIFI() { |
mdns.addService("http", "tcp", 80); | // cuando esta pegado a internet el status es 3 |
mdns.addService("ws", "tcp", 81); | // 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!"); |
} | } |
else { | } |
Serial.println("MDNS.begin failed"); | |
| 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"); |
} | } |
Serial.print("Connect to http://espWebSock.local or http://"); | |
Serial.println(WiFi.localIP()); | |
| |
server.on("/", handleRoot); | |
server.onNotFound(handleNotFound); | |
| |
server.begin(); | |
| |
webSocket.begin(); | |
webSocket.onEvent(webSocketEvent); | |
} | } |
| |
void loop() | |
{ | |
webSocket.loop(); | |
server.handleClient(); | |
| |
// dht11 y pantall | // the loop function runs over and over again forever |
static unsigned int h = 0; | void loop() { |
static unsigned int t = 0; | 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); |
| |
h = dht.readHumidity(); | |
t = dht.readTemperature(); | |
/* | /* |
// Si las lecturas fallan, salimos, no mandamos nada y volvemos a intentarlo | digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)} |
if (isnan(h) || isnan(t)) { | digitalWrite(ledTrigger, HIGH); |
Serial.println(F("Failed to read from DHT sensor!")); | delay(1000); // wait for a second |
return; | digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW |
} | digitalWrite(ledTrigger, LOW); |
| delay(1000); // wait for a second |
*/ | */ |
| |
display.clearDisplay(); | |
display.setCursor(0,0); | |
display.print("UN/LOQUER \n"); | |
display.print("HUM: "); | |
display.print(h); | |
display.print(" % \n"); | |
display.print("TEM: "); | |
display.print(t); | |
display.print(" C \n"); | |
display.print("IP: "); | |
display.print(WiFi.localIP()); | |
display.display(); | |
| |
// sendDataInflux(String(h), String(t)); // se tiene que mandar los datos por websokect + no por protocolo http | |
} | } |
</code> | </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> |
| |
| |
| |