Código de testeo para CO2-100 con el blynk nuevo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

79 lines
1.8 KiB

#define BLYNK_TEMPLATE_ID "TMPLsdSzyUnw"
#define BLYNK_DEVICE_NAME "CO2 100"
#define BLYNK_AUTH_TOKEN "28OeDXtCtS5dnMICcx2LuT3xO0Kt4myz"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
//Comentario hecho desde terminal enviado con git
#include <MHZ19.h>
#include <SoftwareSerial.h>
#include "BlynkEdgent.h"
// Pin RX Arduino conectado al pin TX del MHZ19
#define RX_PIN 16
// Pin TX Arduino conectado al pin RX del MHZ19
#define TX_PIN 17
// Objeto para sensor MHZ19
MHZ19 myMHZ19;
// Serial requerido por el MHZ19
SoftwareSerial mySerial(RX_PIN, TX_PIN);
// Contador para temporizar las mediciones
unsigned long timer = 0;
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
myMHZ19.begin(mySerial);
// Turn auto calibration ON (OFF autoCalibration(false))
myMHZ19.autoCalibration();
BlynkEdgent.begin();
}
void loop() {
BlynkEdgent.run();
Blynk.virtualWrite(V24, WiFi.SSID());
Blynk.virtualWrite(V22, generateChipID());
medicionCO2();
}
void medicionCO2(){
if (millis() - timer >= 10000) {
// Obtener la medición de CO2 actual como ppm
int nivelCO2 = myMHZ19.getCO2();
if(nivelCO2<900){
Blynk.setProperty(V6, "color", "#7cff00");
}else{
Blynk.setProperty(V6, "color", "#ff1e1e");
}
// Mostrar el nivel de CO2 en el monitor serie
Serial.print("CO2 (ppm): ");
Serial.println(nivelCO2);
Blynk.virtualWrite(V6, nivelCO2);
timer = millis();
}
}
String generateChipID()
{
String aux;
uint64_t chipid = ESP.getEfuseMac();
char chip[14];
chip[0] = NULL;
for (int i = 0; i < 6; i++)
sprintf(chip, "%s%02X", chip, (uint8_t)(chipid >> 8 * i));
aux = String(chip);
return aux;
}