Advertisement
pleasedontcode

GSM Setup rev_01

Aug 26th, 2024
135
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 Setup
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-08-27 02:07:27
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The system shall utilize the SIM800L module for */
  21.     /* GSM communication, ensuring reliable data */
  22.     /* transmission and reception through SoftwareSerial */
  23.     /* on specified TX/RX pins. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <SoftwareSerial.h> //https://github.com/plerup/espsoftwareserial
  28. #include <Sim800L.h>    //https://github.com/vittorioexp/Sim800L-Arduino-Library-revised
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t GSM1_SIM800L_RING_PIN_D16     = 16;
  36.  
  37. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  38. const uint8_t GSM1_SIM800L_RST_PIN_D14      = 14;
  39. const uint8_t GSM1_SIM800L_DTR_PIN_D17      = 17;
  40.  
  41. /***** DEFINITION OF Software Serial *****/
  42. const uint8_t GSM1_SIM800L_Serial_PIN_SERIAL_TX_D4      = 4;
  43. const uint8_t GSM1_SIM800L_Serial_PIN_SERIAL_RX_D13     = 13;
  44. EspSoftwareSerial::UART GSM1_SIM800L_Serial;
  45.  
  46. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  47. /***** used to store raw data *****/
  48. bool    GSM1_SIM800L_RST_PIN_D14_rawData        = 0;
  49. bool    GSM1_SIM800L_DTR_PIN_D17_rawData        = 0;
  50.  
  51. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  52. /***** used to store data after characteristic curve transformation *****/
  53. float   GSM1_SIM800L_RST_PIN_D14_phyData        = 0.0;
  54. float   GSM1_SIM800L_DTR_PIN_D17_phyData        = 0.0;
  55.  
  56. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  57. // Initialize the Sim800L object with RX, TX, and RST pins
  58. Sim800L GSM1_SIM800L(GSM1_SIM800L_Serial_PIN_SERIAL_RX_D13, GSM1_SIM800L_Serial_PIN_SERIAL_TX_D4, GSM1_SIM800L_RST_PIN_D14);
  59.  
  60. void setup(void)
  61. {
  62.     // Set the ring pin as input with pull-up
  63.     pinMode(GSM1_SIM800L_RING_PIN_D16, INPUT_PULLUP);
  64.  
  65.     // Set the RST pin as output
  66.     pinMode(GSM1_SIM800L_RST_PIN_D14, OUTPUT);
  67.     // Set the DTR pin as output
  68.     pinMode(GSM1_SIM800L_DTR_PIN_D17, OUTPUT);
  69.  
  70.     // Start the software serial communication
  71.     GSM1_SIM800L_Serial.begin(9600, SWSERIAL_8N1, GSM1_SIM800L_Serial_PIN_SERIAL_RX_D13, GSM1_SIM800L_Serial_PIN_SERIAL_TX_D4, false);
  72.  
  73.     // Initialize the GSM module with the default baud rate
  74.     GSM1_SIM800L.begin(9600);
  75. }
  76.  
  77. void loop(void)
  78. {
  79.     // Refresh output data
  80.     updateOutputs();
  81.  
  82.     // Example: Sending an SMS (you can modify the number and text)
  83.     char* text = "Testing SMS"; // Message to be sent
  84.     char* number = "+1234567890"; // Replace with the actual number
  85.     bool error = GSM1_SIM800L.sendSms(number, text); // Send SMS
  86. }
  87.  
  88. void updateOutputs()
  89. {
  90.     // Update the state of the output pins based on raw data
  91.     digitalWrite(GSM1_SIM800L_RST_PIN_D14, GSM1_SIM800L_RST_PIN_D14_rawData);
  92.     digitalWrite(GSM1_SIM800L_DTR_PIN_D17, GSM1_SIM800L_DTR_PIN_D17_rawData);
  93. }
  94.  
  95. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement