/* _____________________________________
* / __ __ /
* / ___ / / ____ _/ /_ ____ /
* / / _ \/ / / __ `/ __ \/_ / /
* / / __/ /___/ /_/ / /_/ / / /_ /
* / \___/_____/\__,_/_.___/ /___/ /
* /____________________________________/
* ~ Embedded Labz :: eLabz.Net ~
*/
#define Project "PirDoorBellMQTT" // ESP32 Base DoorBell & Alarm System
/*
* Description: Uses PIR sensors connected via optocouplers for alert
* system, push buttons & relay modules for doorbell,
* and MQTT for remote notification system.
*
* Author: Andre Santana [eLabz.Net/Santana]
*
*/
#define Version "0.50" // Version number
#define RelDate "2023-02-25" // Release date
/*
* Releases: x.xx: 2023-02-xx
* xxxx
*
* 0.40: 2023-02-22
* Initial "Buggy" release
*/
#define Sketch "PirDoorBellMQTT.ino" // Main project file
#define SketchURL "[github.com/e-Labz/xxxxxx]" // Source code download URL
/*
* Hardware: Uses optocouples to connect PIR sensor and relay
* modules for doorbell and alert system
*
* Interface:
* /---------------------\ Push Button Pinout:
* |*A0 _ _ __ D0*| ---------------------
* |*RSV | | | | | D1*| 1 ==> Data
* |*RSV | |_| |_| ~D2*| 2 ==> GND
* |*SD3 D3*| 3/4 ==> N.C.
* |*SD2 +---------+ D4*|-->
* |*SD1 | NodeMCU | 3V3*|
* |*CMD | ESP8266 | GND*| /---------\
* |*SD0 +---------+ ~D5*| --| # # # # |--
* |*CLK ~D6*| | # # # # |
* |*GND ~ PWM D7*| --| # # # # |--
* |*3V3 ~D8*| \---------/
* |*EN RX*|
* |*RST TX*|
* |*GND +-----+ GND*|-->
* |*Vin | USB | 3V3*|-->
* \-------+-----+-------/
*/
#define License "GPL-3.0-or-later" // License Version
/*
* This is free software. Please donate for support our beer ;-)
* @ [AndreSantana.NET/donate] Thank you!
*
* PirDoorBellMQTT is distributed under the GNU General Public License
* Version 3.0 as described below. This is free to use, as long as its
* source and author are kept.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* The Software is provided "AS IS" and "WITH ALL FAULTS,"
* without warranty of any kind, including without limitation
* the warranties of merchantability, fitness for a particular
* purpose and non-infringement.
*
* NOT FOR USE TO CONTROL PRODUCTION EQUIPMENT OR HEAVY MACHINES.
* SERIOUS INJURY COULD RESULT. Make good use of it.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Copyright (C) 2023 by Andre Santana
*
*****************************************************************************************/
/* -------------------- Identify MPU Archeture ----------------- */
#ifdef ESP8266 // check for ESP8266 MCU
#include <ESP8266WiFi.h> // ESP8266 WiFi Library
#define MPU_Arch "ESP8266" // define ESP8266 Arch
#elif defined(ESP32) // check for ESP32 MCU
#include <WiFi.h> // ESP32 WiFi Library
#define MPU_Arch "ESP32" // define ESP32 Arch
#else // if not supported
#error "Supported MCUs ESP8266 or ESP32" // publish error msg
#endif
/* ----------------------- Library Imports --------------------- */
//#include "freertos/FreeRTOS.h" // FreeRTOS library
//#include "freertos/task.h" // task library
#include <PubSubClient.h> // MQTT Library
/* --------------------- Define Declarations -------------------- */
#define WiFiSSID "Wokwi-GUEST" // WiFi SSID
#define WiFiPass "" // WiFi Password
#define BrokerAddr "broker.hivemq.com" // MQTT Broker IP Addr
#define BrokerPort 1883 // MQTT Broker Port Addr
#define DevID "ESP32C3-0272" // just a name to identify this client
#define TopcSub "casa-teste/topic-teste/sub" // Sub Topic
#define TopcPub "casa-teste/topic-teste/pub" // Pub Topic
#define pubTime 300 // Publish time in seconds
#define pirSen1 3 // pirSensor entrance
#define pirSen2 1 // pirSensor garden
#define pirSen3 10 // pirSensor hall
#define pshBtn1 18 // doorbell switch
#define relayMod1 9 // buzzer alarm relay
#define relayMod2 8 // doorbell relay
#define bellTime 5 // bell time in secs
#define alertTime 10 // alert time in secs
/* -------------------- Variable Declarations ------------------- */
TaskHandle_t vTskPirISR1, vTskPirISR2, vTskPirISR3, vTskPshISR1; // task handle variables
const unsigned char pir1 = 1, pir2 = 2, pir3 = 3; // set pirTsks parammeters
/* ---------------------- Initialize Setup ---------------------- */
void setup() {
vInitHW(); // initialize hardware
//vInitNet(); // initialize network
vInitRTOS(); // init & create FreeRTOS tasks
}
/* --------------- Main (Infinite) Loop Function ---------------- */
void loop() {} // do nothing forever ;-)
//////////////////////////////////////////////////////////////////////////////
// This is free software. Please donate for support our coffe or beer ;-) //
// @ [AndreSantana.NET/donate] - Thank you! //
//////////////////////////////////////////////////////////////////////////////