mikroavr

at_command_modem

Jan 31st, 2021 (edited)
1,104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define RXD2 17
  2. #define TXD2 16
  3. #define RST 4
  4. unsigned long cur_time, old_time;
  5. #define TINY_GSM_MODEM_SIM7600
  6. #include <TinyGsmClient.h>
  7. #define SerialMon Serial
  8. #define TINY_GSM_DEBUG SerialMon
  9. #define SerialAT Serial2
  10.  
  11.  
  12. #ifdef DUMP_AT_COMMANDS
  13. #include <StreamDebugger.h>
  14. StreamDebugger debugger(SerialAT, SerialMon);
  15. TinyGsm modem(debugger);
  16. #else
  17. TinyGsm modem(SerialAT);
  18. #endif
  19.  
  20. bool hold = 0;
  21.  
  22. void setup() {
  23.   // put your setup code here, to run once:
  24.   SerialMon.begin(115200);
  25.   SerialAT.begin(9600, SERIAL_8N1, RXD2, TXD2);
  26.   delay(1000);
  27.   Serial.println("test at mulai");
  28.   pinMode(RST, OUTPUT);
  29.   //pinMode(PKEY, OUTPUT);
  30.   //digitalWrite(PKEY, LOW);
  31.   digitalWrite(RST, LOW); delay(1000);
  32.   digitalWrite(RST, HIGH); delay(1000);
  33.   wRespon(10000);
  34.  
  35.   //change_baud();
  36.  
  37.  
  38.  
  39. }
  40.  
  41. void loop() {
  42.   // put your main code here, to run repeatedly:
  43.   Serial.println("SEND AT");
  44.   /*SerialAT.println("ATI");
  45.     wRespon(1500);
  46.  
  47.   */
  48.   send_at("AT");
  49.   send_at("ATI");
  50.   send_at("AT+IPR?");
  51.  
  52.   send_at("AT+CFUN?");
  53.   send_at("AT+CPIN?");
  54.   send_at("AT+CSMINS?");
  55.   send_at("AT+COPS?");
  56.   send_at("AT+CSQ");
  57.   send_at("AT+CREG?");
  58.   send_at("AT+CGREG?");
  59. }
  60.  
  61. void send_at(char *_command) {
  62.   SerialAT.println(_command);
  63.   wRespon(1000);
  64. }
  65.  
  66. void wRespon(long waktu) {
  67.   cur_time = millis();
  68.   old_time = cur_time;
  69.   while (cur_time - old_time < waktu ) {
  70.     cur_time = millis();
  71.     while (SerialAT.available() > 0) {
  72.       Serial.print(SerialAT.readString());
  73.     }
  74.   }
  75. }
  76.  
  77. void change_baud(){
  78.   SerialAT.println("AT");
  79.   wRespon(1000);
  80.   SerialAT.println("AT+IPR?");
  81.   wRespon(1000);
  82.   SerialAT.println("AT+IPR=9600");
  83.   wRespon(1000);
  84.   SerialAT.println("AT&W");
  85.   wRespon(1000);
  86.   SerialAT.begin(9600, SERIAL_8N1, RXD2, TXD2);
  87.   while (1) {
  88.     SerialAT.println("AT");
  89.     wRespon(1000);
  90.     SerialAT.println("ATI");
  91.     wRespon(1000);
  92.     SerialAT.println("AT+IPR?");
  93.     wRespon(1000);
  94.   }
  95. }
  96. /*
  97.   */
Add Comment
Please, Sign In to add comment