Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2025
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2.  
  3. #define SIM800_RX_PIN 16
  4. #define SIM800_TX_PIN 17
  5.  
  6. SoftwareSerial sim800(SIM800_RX_PIN, SIM800_TX_PIN);
  7.  
  8. void setup() {
  9. Serial.begin(115200);
  10. sim800.begin(9600);
  11.  
  12. Serial.println("Initializing SIM800L...");
  13. delay(1000);
  14.  
  15. sendATCommand("AT");
  16. sendATCommand("AT+CGMI");
  17. sendATCommand("AT+CGMM");
  18. sendATCommand("AT+CGMR");
  19. sendATCommand("AT+CSQ");
  20.  
  21. // Check PIN status
  22. sendATCommand("AT+CPIN?");
  23.  
  24. // Check and set IP status
  25. checkAndSetIPStatus();
  26.  
  27. // Set APN
  28. sendATCommand("AT+CSTT=\"internet.telekom\"");
  29.  
  30. // Try automatic network registration
  31. sendATCommand("AT+COPS=0");
  32. delay(10000); // Wait for registration
  33.  
  34. sendATCommand("AT+CREG?");
  35. sendATCommand("AT+COPS?");
  36.  
  37. // If automatic fails, try manual registration
  38. sendATCommand("AT+COPS=1,2,\"21601\"");
  39. delay(10000);
  40.  
  41. sendATCommand("AT+CREG?");
  42. sendATCommand("AT+COPS?");
  43.  
  44. // If still not registered, try alternative codes
  45. sendATCommand("AT+COPS=1,2,\"01\"");
  46. delay(10000);
  47.  
  48. sendATCommand("AT+CREG?");
  49. sendATCommand("AT+COPS?");
  50.  
  51. sendATCommand("AT+COPS=1,2,\"216F01\"");
  52. delay(10000);
  53.  
  54. sendATCommand("AT+CREG?");
  55. sendATCommand("AT+COPS?");
  56.  
  57. // Try USSD code for balance check
  58. sendATCommand("AT+CUSD=1,\"*102#\",15");
  59. }
  60.  
  61. void loop() {
  62. // Your main code here
  63. }
  64.  
  65. void sendATCommand(String command) {
  66. Serial.println("Sending command: " + command);
  67. sim800.println(command);
  68. delay(500);
  69.  
  70. while(sim800.available()) {
  71. String response = sim800.readString();
  72. Serial.println(response);
  73. }
  74.  
  75. Serial.println(); // Add a blank line for readability
  76. }
  77.  
  78. void checkAndSetIPStatus() {
  79. Serial.println("SIM800L státusz lekérdezése...");
  80. sim800.println("AT+CIPSTATUS");
  81. delay(2000);
  82.  
  83. String statusResponse = "";
  84. while (sim800.available() > 0) {
  85. char c = sim800.read();
  86. statusResponse += c;
  87. }
  88.  
  89. Serial.println("SIM800L státusz:");
  90. Serial.println(statusResponse);
  91.  
  92. if (statusResponse.indexOf("STATE: IP START") != -1) {
  93. Serial.println("Státusz: IP START. Visszaállítás IP INITIAL állapotra...");
  94. sim800.println("AT+CIPSHUT");
  95. delay(2000);
  96.  
  97. while (sim800.available() > 0) {
  98. char c = sim800.read();
  99. Serial.print(c);
  100. }
  101. }
  102.  
  103. if (statusResponse.indexOf("STATE: IP INITIAL") != -1) {
  104. Serial.println("Státusz: IP INITIAL. AT+CSTT parancs végrehajtható.");
  105. sim800.println("AT+CSTT=\"internet\"");
  106. delay(2000);
  107.  
  108. while (sim800.available() > 0) {
  109. char c = sim800.read();
  110. Serial.print(c);
  111. }
  112. }
  113. }
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement