Advertisement
pleasedontcode

GSM Management rev_17

Jun 13th, 2024
256
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: GSM Management
  13.     - Source Code NOT compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-06-13 11:01:08
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* if it is received an sms from +390123456, so call */
  21.     /* it after 1 minute. */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <SoftwareSerial.h> //https://github.com/plerup/espsoftwareserial
  26. #include <Sim800L.h>    //https://github.com/vittorioexp/Sim800L-Arduino-Library-revised
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31. void updateOutputs(void);
  32. void handleIncomingSms(void);
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t gsm_SIM800L_RING_PIN_D3 = 3;
  36.  
  37. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  38. const uint8_t gsm_SIM800L_RST_PIN_D2 = 2;
  39. const uint8_t gsm_SIM800L_DTR_PIN_D4 = 4;
  40.  
  41. /***** DEFINITION OF Software Serial *****/
  42. const uint8_t gsm_SIM800L_Serial_PIN_SERIAL_TX_A0 = A0;
  43. const uint8_t gsm_SIM800L_Serial_PIN_SERIAL_RX_A1 = A1;
  44. EspSoftwareSerial::UART gsm_SIM800L_Serial(gsm_SIM800L_Serial_PIN_SERIAL_RX_A1, gsm_SIM800L_Serial_PIN_SERIAL_TX_A0);
  45.  
  46. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  47. /***** used to store raw data *****/
  48. bool gsm_SIM800L_RST_PIN_D2_rawData = 0;
  49. bool gsm_SIM800L_DTR_PIN_D4_rawData = 0;
  50.  
  51. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  52. /***** used to store data after characteristic curve transformation *****/
  53. float gsm_SIM800L_RST_PIN_D2_phyData = 0.0;
  54. float gsm_SIM800L_DTR_PIN_D4_phyData = 0.0;
  55.  
  56. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  57. Sim800L GSM(gsm_SIM800L_Serial_PIN_SERIAL_RX_A1, gsm_SIM800L_Serial_PIN_SERIAL_TX_A0, gsm_SIM800L_RST_PIN_D2);
  58.  
  59. void setup(void)
  60. {
  61.     // put your setup code here, to run once:
  62.  
  63.     pinMode(gsm_SIM800L_RING_PIN_D3, INPUT_PULLUP);
  64.  
  65.     pinMode(gsm_SIM800L_RST_PIN_D2, OUTPUT);
  66.     pinMode(gsm_SIM800L_DTR_PIN_D4, OUTPUT);
  67.  
  68.     gsm_SIM800L_Serial.begin(9600, SWSERIAL_8N1, gsm_SIM800L_Serial_PIN_SERIAL_RX_A1, gsm_SIM800L_Serial_PIN_SERIAL_TX_A0, false);
  69.  
  70.     GSM.begin(); // Initialize the GSM module
  71.     GSM.reset(); // Reset the GSM module
  72. }
  73.  
  74. void loop(void)
  75. {
  76.     // put your main code here, to run repeatedly:
  77.  
  78.     updateOutputs(); // Refresh output data
  79.     handleIncomingSms(); // Handle incoming SMS
  80. }
  81.  
  82. void updateOutputs()
  83. {
  84.     digitalWrite(gsm_SIM800L_RST_PIN_D2, gsm_SIM800L_RST_PIN_D2_rawData);
  85.     digitalWrite(gsm_SIM800L_DTR_PIN_D4, gsm_SIM800L_DTR_PIN_D4_rawData);
  86. }
  87.  
  88. void handleIncomingSms()
  89. {
  90.     String textSms = GSM.readSms(1); // Read the first SMS
  91.  
  92.     if (textSms.length() > 0) { // Check if the message is not empty
  93.         String numberSms = GSM.getNumberSms(1); // Get the sender's number
  94.         Serial.println(numberSms); // Debugging
  95.  
  96.         if (numberSms == "+390123456") {
  97.             delay(60000); // Wait for 1 minute
  98.             GSM.callNumber(numberSms); // Call the number
  99.         }
  100.  
  101.         GSM.delAllSms(); // Delete all SMS
  102.     }
  103. }
  104.  
  105. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement