/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: **Payment Control**
- Source Code NOT compiled for: ESP32 DevKit V1
- Source Code created on: 2024-11-06 13:45:32
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* A Paygo mini solar energy kit.Kit aims at */
/* providing solar energy from a battery to a */
/* consumer if he pays via SMS or Card to receive a */
/* token code that he then enters into the kit via */
/* keypad. Once codes match, energy is provided for */
/* certain time. */
/****** END SYSTEM REQUIREMENTS *****/
/* START CODE */
/****** DEFINITION OF LIBRARIES *****/
#include // Include this for GSM communication
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void checkForPaymentCode();
void activateSystem();
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
SoftwareSerial gsmModule(16, 17); // RX, TX pins for GSM module (Compatible with ESP32)
const int LED_PIN = 2; // LED light connected to pin 2 (Compatible with ESP32)
bool isSystemActive = false;
long unlockTime = 0;
void setup(void)
{
Serial.begin(9600);
gsmModule.begin(9600); // Initialize GSM module
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW); // System starts locked
}
void loop(void)
{
checkForPaymentCode(); // Check for an SMS code
if (isSystemActive) {
// Turn on LED or enable charging if system is unlocked
digitalWrite(LED_PIN, HIGH);
// Check if time to deactivate
if (millis() - unlockTime >= 86400000) { // 24 hours in milliseconds
isSystemActive = false;
digitalWrite(LED_PIN, LOW);
}
}
}
void checkForPaymentCode() {
if (gsmModule.available()) {
String message = gsmModule.readString();
// Verify the code received
if (message.indexOf("PAYGO_CODE") >= 0) {
activateSystem();
}
}
}
void activateSystem() {
isSystemActive = true;
unlockTime = millis(); // Start the timer
Serial.println("System activated for 24 hours.");
}
/* END CODE */