/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
Pleasedontcode gives you this package free of charge and you
can use it for your personal projects. We will not be held liable for
any loss or damage of any kind. For all terms and conditions,
please visit pleasedontcode.com/termsandconditions
- Project: ProgrammaLuca
- Source Code created on: 2023-05-01 18:19:20
- Source Code generated by: Alessandro
********* Pleasedontcode.com **********/
/********* User code review feedback **********
#### Feedback 1 ####
- generete code
#### Feedback 2 ####
- usa "WiFiManager" per connetterti al wifi
********* User code review feedback **********/
/****** DEFINITION OF LIBRARIES *****/
#include "Arduino.h"
#include "UniversalTelegramBot.h"
#include "HTTPClient.h"
#include "WiFi.h"
#include "WiFiClientSecure.h"
#include "ESPmDNS.h"
#include "WiFiUdp.h"
#include "WiFiManager.h"
/***** DEFINITION OF DIGITAL INPUT PINS *****/
#define Button_PIN_D5 5
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
#define Led_PIN_D25 25
/***** DEFINITION OF INPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool Button_PIN_D5_rawData = LOW; // Digital Input
/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool Led_PIN_D25_rawData = 0;
/***** DEFINITION OF INPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float Button_PIN_D5_phyData = 0.0;
/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float Led_PIN_D25_phyData = 0.0;
/***** DEFINITION OF VARIABLES FOR MESSAGE SENDING *****/
#define serverName "..." //indirizzo server portalevf
#define Token_server "..." //token per invio selettiva su bot
#define Distaccamento "test"
#define MSG "Attenzione selettiva RADIO ricevuta per Distaccamento, recarsi in caserma!"
unsigned long lastSentTime = 0; // Used to store the time of the last sent message
WiFiManager wifiManager;
void setup()
{
// put your setup code here, to run once:
pinMode(Button_PIN_D5, INPUT_PULLUP);
pinMode(Led_PIN_D25, OUTPUT);
// Connect to WiFi using WiFiManager
wifiManager.autoConnect("AutoConnectAP");
}
void loop()
{
// put your main code here, to run repeatedly:
updateInputs(); // Refresh input data
updateOutputs(); // Refresh output data
pulsantePremuto(); // Check if the button has been pressed for more than 500ms
}
void updateInputs()
{
Button_PIN_D5_rawData = digitalRead(Button_PIN_D5);
}
void updateOutputs()
{
digitalWrite(Led_PIN_D25, Led_PIN_D25_rawData);
}
void InviaMessaggio()
{
/***** REQUIREMENT 1 *****/
/* Quando la funzione è richiamata invia il messaggio */
/* definito MSG (è una define) usando la libreria */
/* UniversalTelegramBot */
/***** REQUIREMENT 2 *****/
/* MSG = "Attenzione selettiva RADIO ricevuta */
/* per " Distaccamento ", recarsi in */
/* caserma!" */
/***** REQUIREMENT 3 *****/
/* usa le seguenti liberie: "UniversalTelegramBot.h", */
/* "HTTPClient.h", "WiFi.h", "WiFiClientSecure.h", */
/* "ESPmDNS.h", "WiFiUdp.h", "WiFiManager.h" */
/***** REQUIREMENT 4 *****/
/* invia su portale web se il messaggio è stato */
/* inviato utilizzando il seguente codice "String url */
/* = String(serverName) + */
/* String(Distaccamento)+".portalevf.it"+ */
/* String(Token_server); HTTPClient http; */
/* http.begin(url); int httpResponseCode = */
/* http.POST(Distaccamento);" */
/***** REQUIREMENT 5 *****/
/* Definisci #define serverName "..." //indirizzo */
/* server portalevf #define Token_server "..." */
/* //token per invio selettiva su bot #define */
/* Distaccamento "test" */
// Check if at least 10 seconds have passed since the last sent message
if (millis() - lastSentTime >= 10000) {
// Send the message using the UniversalTelegramBot library
UniversalTelegramBot bot(Token_server);
bot.sendMessage(Distaccamento, MSG);
// Send the message to the web portal
String url = String(serverName) + String(Distaccamento) + ".portalevf.it" + String(Token_server);
HTTPClient http;
http.begin(url);
int httpResponseCode = http.POST(Distaccamento);
http.end();
// Update the time of the last sent message
lastSentTime = millis();
}
}
void pulsantePremuto()
{
/***** REQUIREMENT 1 *****/
/* usa input Button e definiscilo come INPUT_PULLDOWN */
/***** REQUIREMENT 2 *****/
/* quando il pulsante Button è stato premuto per */
/* almeno 500 millisecondi allora richiama */
/* InviaMessaggio. */
/***** REQUIREMENT 3 *****/
/* Non richiamare InviaMessaggio se non sono passato */
/* almeno 10 secondi dall'ultimo invio. */
/* ### Use (if needed) the following other functions for this function: */
/* ### - InviaMessaggio */
static unsigned long buttonPressStartTime = 0; // Used to store the time when the button was pressed
if (Button_PIN_D5_rawData == LOW) {
// Button is pressed, start counting time
if (buttonPressStartTime == 0) {
buttonPressStartTime = millis();
}
// Button is still pressed, check if at least 500ms have passed
else if (millis() - buttonPressStartTime >= 500) {
// At least 500ms have passed, call the InviaMessaggio function
InviaMessaggio();
// Reset the button press start time
buttonPressStartTime = 0;
}
}
else {
// Button is not pressed, reset the button press start time
buttonPressStartTime = 0;
}
}