Advertisement
mikroavr

at_command_sim7600_en_reg

Apr 24th, 2024
915
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 14
  5. #define RST 12
  6.  
  7. #define pin_en 13
  8.  
  9. #define SerialMon Serial
  10. #define SerialAT Serial2
  11.  
  12. int ledState = LOW;
  13. const int ledPin =  15;
  14. int counter = 0;
  15.  
  16. unsigned long cur_time_led, old_time_led;
  17. unsigned long cur_time, old_time;
  18. bool hold = 0;
  19.  
  20. #define TINY_GSM_MODEM_SIM7600
  21. #if !defined(TINY_GSM_RX_BUFFER)
  22. #define TINY_GSM_RX_BUFFER 650
  23. #endif
  24. #define TINY_GSM_DEBUG SerialMon
  25. // set GSM PIN, if any
  26. #define GSM_PIN ""
  27.  
  28. // Your GPRS credentials, if any
  29. const char apn[]      = "Internet";
  30. const char gprsUser[] = "";
  31. const char gprsPass[] = "";
  32.  
  33. const char server[]   = "vsh.pp.ua";
  34. const char resource[] = "/TinyGSM/logo.txt";
  35. const int  port       = 80;
  36.  
  37. #include <TinyGsmClient.h>
  38. #include <ArduinoHttpClient.h>
  39.  
  40. #ifdef DUMP_AT_COMMANDS
  41. #include <StreamDebugger.h>
  42. StreamDebugger debugger(SerialAT, SerialMon);
  43. TinyGsm        modem(debugger);
  44. #else
  45. TinyGsm        modem(SerialAT);
  46. #endif
  47.  
  48. TinyGsmClient client(modem);
  49. HttpClient    http(client, server, port);
  50.  
  51.  
  52. void setup() {
  53.   // put your setup code here, to run once:
  54.   SerialMon.begin(115200);
  55.   SerialAT.begin(115200, SERIAL_8N1, RXD2, TXD2);
  56.   delay(250);
  57.   SerialMon.println("test at mulai");
  58.   pinMode(ledPin, OUTPUT);
  59.   pinMode(RST, OUTPUT);
  60.   pinMode(PKEY, OUTPUT);
  61.   pinMode(pin_en, OUTPUT);
  62.  
  63.   digitalWrite(PKEY, LOW);
  64.   digitalWrite(RST, LOW);
  65.   delay(1000);
  66.   digitalWrite(PKEY, HIGH);
  67.   digitalWrite(RST, HIGH);
  68.   delay(1000);
  69.   digitalWrite(PKEY, LOW);
  70.   digitalWrite(RST, LOW);
  71.   delay(1000);
  72.  
  73.   SerialMon.println("Initializing modem...");
  74.   modem.restart();
  75.   wRespon(5000);
  76.   if(res_cmd("AT","OK",5000)){
  77.     Serial.println("sim7600 on");
  78.   }else{
  79.     Serial.println("sim7600 nok");
  80.     digitalWrite(pin_en,HIGH);delay(1000);
  81.     digitalWrite(pin_en,LOW); delay(1000);
  82.     ESP.restart();
  83.   }
  84.  
  85.  
  86.  
  87.   //bool res = modem.sendSMS("082165062273", "bismillaah, ini dari saya,monitoring smart farming , testing ya");
  88.   //DBG("SMS:", res ? "OK" : "fail");
  89.   /*SerialAT.println("AT");
  90.     wRespon(1000);
  91.     SerialAT.println("AT+IPREX?");
  92.     wRespon(1000);
  93.     SerialAT.println("AT+IPREX=115200");
  94.     wRespon(1000);
  95.     SerialAT.println("AT&W");
  96.     wRespon(1000);22,21m
  97.     SerialAT.begin(115200, SERIAL_8N1, RXD2, TXD2);
  98.   */
  99. }
  100.  
  101. void loop() {
  102.   // put your main code here, to run repeatedly:
  103.   SerialMon.println("SEND AT");
  104.  
  105.   cur_time_led = millis();
  106.   if (cur_time_led - old_time_led >= 1000) {
  107.     counter++;
  108.     switch (counter) {
  109.       case 1:
  110.         send_at("AT+CPIN?");
  111.         break;
  112.       case 2:
  113.         send_at("AT+CSQ");
  114.         break;
  115.       case 3:
  116.         send_at("AT+CPSI?");
  117.         break;
  118.       case 4:
  119.         send_at("ATI");
  120.         break;
  121.       case 5:
  122.         send_at("AT+IPR?");
  123.         counter = 0;
  124.         break;
  125.     }
  126.  
  127.     if (ledState == LOW) {
  128.       ledState = HIGH;
  129.     } else {
  130.       ledState = LOW;
  131.     }
  132.  
  133.     digitalWrite(ledPin, ledState);
  134.     old_time_led = cur_time_led;
  135.   }
  136. }
  137.  
  138. void send_at(char *_command) {
  139.   SerialAT.println(_command);
  140.   wRespon(1000);
  141. }
  142.  
  143. void wRespon(long waktu) {
  144.   cur_time = millis();
  145.   old_time = cur_time;
  146.   while (cur_time - old_time < waktu ) {
  147.     cur_time = millis();
  148.     while (SerialAT.available() > 0) {
  149.       SerialMon.print(SerialAT.readString());
  150.     }
  151.   }
  152. }
  153.  
  154.  
  155. void reset_sim() {
  156.   digitalWrite(RST, HIGH);
  157. }
  158.  
  159. void wakeup_sim() {
  160.   SerialMon.println("wakeup sim7600");
  161.   digitalWrite(PKEY, LOW);
  162.   digitalWrite(RST, LOW);
  163.   delay(1000);
  164.   digitalWrite(PKEY, HIGH);
  165.   digitalWrite(RST, HIGH);
  166.   delay(1000);
  167.   digitalWrite(PKEY, LOW);
  168.   digitalWrite(RST, LOW);
  169.   delay(1000);
  170.   wRespon(15000);
  171. }
  172.  
  173. int8_t res_cmd(char* ATcommand, char* expected_answer, unsigned int timeout) {
  174.   uint8_t x = 0, answer = 0;
  175.   char response[100];
  176.   unsigned long prevMillis;
  177.   memset(response, '\0', 100);
  178.   delay(100);
  179.  
  180.   while (SerialAT.available() > 0)SerialAT.read();
  181.   SerialAT.println(ATcommand);
  182.   prevMillis = millis();
  183.   do {
  184.     if (SerialAT.available() != 0) {
  185.       response[x] = SerialAT.read();
  186.       x++;
  187.       if (strstr(response, expected_answer) != NULL) {
  188.         answer = 1;
  189.       }
  190.     }
  191.   } while ((answer == 0) && ((millis() - prevMillis) < timeout));
  192.   return answer;
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement