Advertisement
pleasedontcode

**Payment Control** rev_01

Nov 6th, 2024
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: **Payment Control**
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-11-06 13:45:32
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* A Paygo mini solar energy kit.Kit aims at */
  21.     /* providing solar energy from a battery to a */
  22.     /* consumer if he pays via SMS or Card to receive a */
  23.     /* token code that he then enters into the kit via */
  24.     /* keypad. Once codes match, energy is provided for */
  25.     /* certain time. */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /* START CODE */
  29.  
  30. /****** DEFINITION OF LIBRARIES *****/
  31. #include <SoftwareSerial.h>  // Include this for GSM communication
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36. void checkForPaymentCode();
  37. void activateSystem();
  38.  
  39. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  40. SoftwareSerial gsmModule(16, 17); // RX, TX pins for GSM module (Compatible with ESP32)
  41. const int LED_PIN = 2; // LED light connected to pin 2 (Compatible with ESP32)
  42. bool isSystemActive = false;
  43. long unlockTime = 0;
  44.  
  45. void setup(void)
  46. {
  47.     Serial.begin(9600);
  48.     gsmModule.begin(9600); // Initialize GSM module
  49.     pinMode(LED_PIN, OUTPUT);
  50.     digitalWrite(LED_PIN, LOW); // System starts locked
  51. }
  52.  
  53. void loop(void)
  54. {
  55.     checkForPaymentCode(); // Check for an SMS code
  56.     if (isSystemActive) {
  57.         // Turn on LED or enable charging if system is unlocked
  58.         digitalWrite(LED_PIN, HIGH);
  59.        
  60.         // Check if time to deactivate
  61.         if (millis() - unlockTime >= 86400000) { // 24 hours in milliseconds
  62.             isSystemActive = false;
  63.             digitalWrite(LED_PIN, LOW);
  64.         }
  65.     }
  66. }
  67.  
  68. void checkForPaymentCode() {
  69.     if (gsmModule.available()) {
  70.         String message = gsmModule.readString();
  71.        
  72.         // Verify the code received
  73.         if (message.indexOf("PAYGO_CODE") >= 0) {
  74.             activateSystem();
  75.         }
  76.     }
  77. }
  78.  
  79. void activateSystem() {
  80.     isSystemActive = true;
  81.     unlockTime = millis(); // Start the timer
  82.     Serial.println("System activated for 24 hours.");
  83. }
  84.  
  85. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement