#include <AM2302-Sensor.h>
uint8_t number;
uint16_t number2;
uint8_t day;
uint8_t month;
uint16_t year;
uint8_t WireSensorTimer[5];
const uint8_t MaxRFsensors PROGMEM = 4;
const char WireSensorName[][18] PROGMEM = { "Dvere", "Zvonek", "Vypadek napajeni", "Obnoveni napajeni", "Teplota" };
const uint8_t RFsensorNameLenght PROGMEM = 18;
struct RFSENSOR {
uint32_t code;
char name[RFsensorNameLenght];
uint8_t timer;
};
RFSENSOR RFsensor[MaxRFsensors];
uint8_t RFsensors = 4;
int8_t i = 0;
char smsBuffer[161];
char TempArray[9];
char text[10];
uint8_t Iteration;
bool SendingSMS = true;
const char PROGMEM Quote = '"';
bool Armed = false;
bool OnAccumulator = true;
void PrintText(int number, char input[] = {""});
constexpr unsigned int SENSOR_PIN{ A12 };
AM2302::AM2302_Sensor am2302{ SENSOR_PIN };
const uint8_t numChars = 31;
char modemNotificationBuffer[numChars];
void setup() {
Serial.begin(115200);
WireSensorTimer[0] = 219;
WireSensorTimer[1] = 4;
WireSensorTimer[2] = 60;
WireSensorTimer[3] = 250;
WireSensorTimer[4] = 196;
strcpy_P(RFsensor[0].name, PSTR("Senzor jedna"));
RFsensor[0].timer = 200;
strcpy_P(RFsensor[1].name, PSTR("Senzor dva"));
RFsensor[1].timer = 30;
strcpy_P(RFsensor[2].name, PSTR("Senzor tri"));
RFsensor[2].timer = 230;
strcpy_P(RFsensor[3].name, PSTR("Senzor ctyri"));
RFsensor[3].timer = 1;
RFsensor[0].code = 12589;
RFsensor[1].code = 12590;
RFsensor[2].code = 12591;
RFsensor[3].code = 12684676;
Serial.println(F("Starting."));
}
void loop() {
// delay(200);
}
/*
void Check_RFsensors(uint32_t RFcode) { // Already modified.
static uint32_t PreviousCode = 0;
static uint32_t Timer1sStart = 0;
const uint16_t Timer1s = 5000;
Serial.print("RFcode: ");
Serial.println(RFcode);
if ((PreviousCode == RFcode && (millis() - Timer1sStart <= Timer1s)) || RFcode < 10000) {
Timer1sStart = millis();
Serial.println("Time control not passed.");
// Serial.print("RFcode: ");
// Serial.println(RFcode);
return;
}
PreviousCode = RFcode;
Timer1sStart = millis();
for (uint8_t i = 0; i < RFsensors; i++) {
if (RFsensor[i].code == RFcode) {
Serial.print(F("Alarm from: "));
Serial.println(RFsensor[i].name);
// Handle Alarm function
return;
}
}
Serial.print(F("Received unknown code: "));
Serial.println(RFcode);
} */
void Check_RFsensors(uint32_t RFcode) { // Copied from source
static uint32_t PreviousCode = 0;
static uint32_t Timer1sStart = 0;
const uint16_t Timer1s = 3000;
// DEBUG_PRINT(F("RFcode: "));
// DEBUG_PRINTLN(RFcode);
Serial.print("RFcode: ");
Serial.println(RFcode);
if ((PreviousCode == RFcode && (millis() - Timer1sStart <= Timer1s)) || RFcode < 10000) {
Timer1sStart = millis();
// DEBUG_PRINT(F("Time control not passed."));
Serial.println("Time control not passed.");
// Serial.print("RFcode: ");
// Serial.println(RFcode);
return;
}
PreviousCode = RFcode;
Timer1sStart = millis();
for (uint8_t i = 0; i < RFsensors; i++) {
if (RFsensor[i].code == RFcode) {
Serial.print(F("Alarm from: "));
Serial.println(RFsensor[i].name);
// DEBUG_PRINT(F("Alarm from: "));
// DEBUG_PRINTLN(RFsensor[i].name);
// Handle Alarm function
// HandleAlarm(i + 5); // Alarms 0 - 4 are from wired sensors.
return;
}
}
Serial.print(F("Received unknown code: "));
Serial.println(RFcode);
// DEBUG_PRINT(F("Received unknown code: "));
// DEBUG_PRINTLN(RFcode);
// char CurTime[18];
// readTime(CurTime);
// file.print(CurTime);
// file.print(F(",\"Přijímač DO\",\"Přijat neznámý kód: "));
// file.print(RFcode);
// file.println(F("\""));
// file.flush();
}
void serialEvent() { // Callback from console
char* ptr;
uint32_t RFcode = 0;
uint8_t bytesRead = Serial.readBytesUntil('\n', modemNotificationBuffer, numChars - 1);
if (bytesRead == 0) return;
modemNotificationBuffer[bytesRead] = 0; // Null-terminate the string
// Serial.print(F("---> "));
// Serial.println(modemNotificationBuffer);
RFcode = strtoul(modemNotificationBuffer, &ptr, 10);
// Serial.print(F("Converted to integer: "));
// Serial.println(RFcode);
Check_RFsensors(RFcode);
}