Advertisement
mikroavr

at_command_esp32

Aug 7th, 2023
1,033
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define RXD2 26
  2. #define TXD2 27
  3.  
  4. #define PKEY 13
  5. #define RST 14
  6.  
  7. #define SerialMon Serial
  8. #define SerialAT Serial2
  9.  
  10. int ledState = LOW;
  11. const int ledPin =  12;
  12. int counter = 0;
  13.  
  14. unsigned long cur_time_led, old_time_led;
  15. unsigned long cur_time, old_time;
  16. bool hold = 0;
  17.  
  18. #define TINY_GSM_MODEM_SIM7600
  19. #if !defined(TINY_GSM_RX_BUFFER)
  20. #define TINY_GSM_RX_BUFFER 650
  21. #endif
  22. #define TINY_GSM_DEBUG SerialMon
  23. // set GSM PIN, if any
  24. #define GSM_PIN ""
  25.  
  26. // Your GPRS credentials, if any
  27. const char apn[]      = "Internet";
  28. const char gprsUser[] = "";
  29. const char gprsPass[] = "";
  30.  
  31. const char server[]   = "vsh.pp.ua";
  32. const char resource[] = "/TinyGSM/logo.txt";
  33. const int  port       = 80;
  34.  
  35. #include <TinyGsmClient.h>
  36. #include <ArduinoHttpClient.h>
  37.  
  38. #ifdef DUMP_AT_COMMANDS
  39. #include <StreamDebugger.h>
  40. StreamDebugger debugger(SerialAT, SerialMon);
  41. TinyGsm        modem(debugger);
  42. #else
  43. TinyGsm        modem(SerialAT);
  44. #endif
  45.  
  46. TinyGsmClient client(modem);
  47. HttpClient    http(client, server, port);
  48.  
  49.  
  50. void setup() {
  51.   // put your setup code here, to run once:
  52.   SerialMon.begin(115200);
  53.   SerialAT.begin(115200, SERIAL_8N1, RXD2, TXD2);
  54.   delay(250);
  55.   SerialMon.println("test at mulai");
  56.   pinMode(ledPin, OUTPUT);
  57.   pinMode(RST, OUTPUT);
  58.   pinMode(PKEY, OUTPUT);
  59.  
  60.   digitalWrite(PKEY, LOW);
  61.   digitalWrite(RST, LOW);
  62.   delay(1000);
  63.   digitalWrite(PKEY, HIGH);
  64.   digitalWrite(RST, HIGH);
  65.   delay(1000);
  66.   digitalWrite(PKEY, LOW);
  67.   digitalWrite(RST, LOW);
  68.   delay(1000);
  69.   SerialMon.println("Initializing modem...");
  70.   modem.restart();
  71.   String modemInfo = modem.getModemInfo();
  72.   SerialMon.print("Modem Info: ");
  73.   SerialMon.println(modemInfo);
  74.   delay(1000);
  75.   /*
  76.     send_at("AT+CMGF=1");
  77.     send_at("AT+IPREX=9600");
  78.     SerialAT.begin(9600, SERIAL_8N1, RXD2, TXD2);
  79.     send_at("AT&W");
  80.     send_at("AT&V");
  81.   */
  82. }
  83.  
  84. void loop() {
  85.   // put your main code here, to run repeatedly:
  86.  
  87.   cur_time_led = millis();
  88.   if (cur_time_led - old_time_led >= 1000) {
  89.     SerialMon.println("SEND AT");
  90.     counter++;
  91.     switch (counter) {
  92.       case 1:
  93.         send_at("ATI");
  94.         break;
  95.       case 2:
  96.         send_at("AT+CPIN?"); // check kartu
  97.         break;
  98.       case 3:
  99.         send_at("AT+CSQ"); //signal ant
  100.         break;
  101.       case 4:
  102.         send_at("AT+CPSI?");
  103.         break;
  104.       case 5:
  105.         send_at("AT+IPR?");
  106.         counter = 0;
  107.         break;
  108.  
  109.     }
  110.  
  111.     if (ledState == LOW) {
  112.       ledState = HIGH;
  113.     } else {
  114.       ledState = LOW;
  115.     }
  116.  
  117.     digitalWrite(ledPin, ledState);
  118.     old_time_led = cur_time_led;
  119.   }
  120.  
  121. }
  122.  
  123. void send_at(char *_command) {
  124.   SerialAT.println(_command);
  125.   wRespon(1000);
  126. }
  127.  
  128. void wRespon(long waktu) {
  129.   cur_time = millis();
  130.   old_time = cur_time;
  131.   while (cur_time - old_time < waktu ) {
  132.     cur_time = millis();
  133.     while (SerialAT.available() > 0) {
  134.       SerialMon.print(SerialAT.readString());
  135.     }
  136.   }
  137. }
  138.  
  139.  
  140. void reset_sim() {
  141.   digitalWrite(RST, HIGH);
  142. }
  143.  
  144. void wakeup_sim() {
  145.   SerialMon.println("wakeup sim7600");
  146.   digitalWrite(PKEY, LOW);
  147.   digitalWrite(RST, LOW);
  148.   delay(1000);
  149.   digitalWrite(PKEY, HIGH);
  150.   digitalWrite(RST, HIGH);
  151.   delay(1000);
  152.   digitalWrite(PKEY, LOW);
  153.   digitalWrite(RST, LOW);
  154.   delay(1000);
  155.   wRespon(15000);
  156. }
  157.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement