Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- #define SIM800_RX_PIN 16
- #define SIM800_TX_PIN 17
- SoftwareSerial sim800(SIM800_RX_PIN, SIM800_TX_PIN);
- void setup() {
- Serial.begin(115200);
- sim800.begin(9600);
- Serial.println("Initializing SIM800L...");
- delay(1000);
- sendATCommand("AT");
- sendATCommand("AT+CGMI");
- sendATCommand("AT+CGMM");
- sendATCommand("AT+CGMR");
- sendATCommand("AT+CSQ");
- // Check PIN status
- sendATCommand("AT+CPIN?");
- // Check and set IP status
- checkAndSetIPStatus();
- // Set APN
- sendATCommand("AT+CSTT=\"internet.telekom\"");
- // Try automatic network registration
- sendATCommand("AT+COPS=0");
- delay(10000); // Wait for registration
- sendATCommand("AT+CREG?");
- sendATCommand("AT+COPS?");
- // If automatic fails, try manual registration
- sendATCommand("AT+COPS=1,2,\"21601\"");
- delay(10000);
- sendATCommand("AT+CREG?");
- sendATCommand("AT+COPS?");
- // If still not registered, try alternative codes
- sendATCommand("AT+COPS=1,2,\"01\"");
- delay(10000);
- sendATCommand("AT+CREG?");
- sendATCommand("AT+COPS?");
- sendATCommand("AT+COPS=1,2,\"216F01\"");
- delay(10000);
- sendATCommand("AT+CREG?");
- sendATCommand("AT+COPS?");
- // Try USSD code for balance check
- sendATCommand("AT+CUSD=1,\"*102#\",15");
- }
- void loop() {
- // Your main code here
- }
- void sendATCommand(String command) {
- Serial.println("Sending command: " + command);
- sim800.println(command);
- delay(500);
- while(sim800.available()) {
- String response = sim800.readString();
- Serial.println(response);
- }
- Serial.println(); // Add a blank line for readability
- }
- void checkAndSetIPStatus() {
- Serial.println("SIM800L státusz lekérdezése...");
- sim800.println("AT+CIPSTATUS");
- delay(2000);
- String statusResponse = "";
- while (sim800.available() > 0) {
- char c = sim800.read();
- statusResponse += c;
- }
- Serial.println("SIM800L státusz:");
- Serial.println(statusResponse);
- if (statusResponse.indexOf("STATE: IP START") != -1) {
- Serial.println("Státusz: IP START. Visszaállítás IP INITIAL állapotra...");
- sim800.println("AT+CIPSHUT");
- delay(2000);
- while (sim800.available() > 0) {
- char c = sim800.read();
- Serial.print(c);
- }
- }
- if (statusResponse.indexOf("STATE: IP INITIAL") != -1) {
- Serial.println("Státusz: IP INITIAL. AT+CSTT parancs végrehajtható.");
- sim800.println("AT+CSTT=\"internet\"");
- delay(2000);
- while (sim800.available() > 0) {
- char c = sim800.read();
- Serial.print(c);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement