-
-
Save sivar2311/84d2ee09b6e18d16f2670492dca7f3bc to your computer and use it in GitHub Desktop.
CO2Sensor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <SinricPro.h> | |
#if defined(ESP32) | |
#include <WiFi.h> | |
#elif defined(ESP8266) | |
#include <ESP8266WiFi.h> | |
#endif | |
#include "CSensor.h" | |
#define APP_KEY "" | |
#define APP_SECRET "" | |
#define DEVICE_ID "" | |
#define SSID "" | |
#define PASS "" | |
#define BAUD_RATE 115200 | |
CSensor &cSensor = SinricPro[DEVICE_ID]; | |
int getCO2_level() { | |
// Implement your CO2 Sensor reading here and return the co2 value | |
// For now this function only return a dummy value between 1 and 20000 | |
return random(1, 2000); | |
} | |
void updateCO2Level() { | |
if (SinricPro.isConnected() == false) return; | |
static unsigned long last_millis; | |
unsigned long current_millis = millis(); | |
if (last_millis && current_millis - last_millis < 60000) return; | |
last_millis = current_millis; | |
int CO2_level = getCO2_level(); | |
cSensor.sendRangeValueEvent("level", CO2_level); | |
} | |
void setup() { | |
WiFi.begin(SSID, PASS); | |
Serial.begin(BAUD_RATE); | |
SinricPro.begin(APP_KEY, APP_SECRET); | |
} | |
void loop() { | |
SinricPro.handle(); | |
updateCO2Level(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment