Advertisement
mikroavr

at_command_sim800c

Jun 26th, 2023
930
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #define RXD2 26
  3. #define TXD2 25
  4.  
  5. #define PKEY 7
  6. unsigned long cur_time, old_time;
  7.  
  8. bool hold = 0;
  9.  
  10. int baud_rate[] = {1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800};
  11.  
  12. #define TINY_GSM_MODEM_SIM800
  13. #define SerialMon Serial
  14. #define SerialAT Serial3
  15.  
  16. #if !defined(TINY_GSM_RX_BUFFER)
  17. #define TINY_GSM_RX_BUFFER 650
  18. #endif
  19. #define TINY_GSM_DEBUG SerialMon
  20. #define GSM_PIN ""
  21.  
  22. // Your GPRS credentials, if any
  23. const char apn[]      = "Internet";
  24. const char gprsUser[] = "";
  25. const char gprsPass[] = "";
  26.  
  27. // Server details
  28. const char _server[]   = "iotles.com";
  29. const char resource[] = "/TinyGSM/logo.txt";
  30. const int  port       = 80;
  31.  
  32. #include <TinyGsmClient.h>
  33. #include <ArduinoHttpClient.h>
  34.  
  35. #ifdef DUMP_AT_COMMANDS
  36. #include <StreamDebugger.h>
  37. StreamDebugger debugger(SerialAT, SerialMon);
  38. TinyGsm        modem(debugger);
  39. #else
  40. TinyGsm        modem(SerialAT);
  41. #endif
  42.  
  43. TinyGsmClient client(modem);
  44. HttpClient    http(client, _server, port);
  45.  
  46.  
  47. void setup() {
  48.   // put your setup code here, to run once:
  49.   delay(1000);
  50.   SerialMon.begin(115200);
  51.   SerialAT.begin(9600);
  52.   delay(1000);
  53.   Serial.println("test at mulai");
  54.   pinMode(PKEY, OUTPUT);
  55.   pinMode(27, OUTPUT);
  56.   digitalWrite(PKEY, HIGH);
  57.   digitalWrite(27, HIGH);
  58.  
  59.   delay(1100);
  60.  
  61.   digitalWrite(PKEY, LOW);
  62.   delay(1100);
  63.   digitalWrite(PKEY, HIGH);
  64.  
  65.   String modemInfo = modem.getModemInfo();
  66.   SerialMon.print("Modem Info: ");
  67.   SerialMon.println(modemInfo);
  68.   delay(1000);
  69.  
  70.   //change_baud();
  71.   /*
  72.     while (1) {
  73.  
  74.     for (int i = 0; i < 10; i++) {
  75.       Serial.print(i);Serial.print(",");
  76.       Serial.println(baud_rate[i]);
  77.  
  78.       SerialAT.begin(baud_rate[i], SERIAL_8N1, RXD2, TXD2);
  79.       delay(500);
  80.       send_at("AT+IPR?");
  81.       delay(500);
  82.     }
  83.     }
  84.   */
  85. }
  86.  
  87. void loop() {
  88.   // put your main code here, to run repeatedly:
  89.  
  90.  
  91.   send_at("AT+GSN");
  92.   digitalWrite(27, HIGH);
  93.   send_at("AT+IPR?");
  94.   digitalWrite(27, LOW);
  95.   send_at("AT+CPIN?");
  96.   digitalWrite(27, HIGH);
  97.   send_at("AT+COPS?");
  98.   digitalWrite(27, LOW);
  99.   send_at("AT+CSQ");
  100.   digitalWrite(27, HIGH);
  101.   send_at("AT+CREG?");
  102.   digitalWrite(27, LOW);
  103. }
  104.  
  105. void change_baud() {
  106.   send_at("AT");
  107.   send_at("AT+IPR=?");
  108.   Serial.println("change baut rate");
  109.   send_at("AT+IPR=9600");
  110.   send_at("AT&W");
  111.  
  112.   while (1) {
  113.     send_at("AT");
  114.     send_at("AT+IPR?");
  115.     //send_at("AT&V");
  116.     delay(1000);
  117.     send_at("AT+COPS?");
  118.     digitalWrite(27, LOW);
  119.     send_at("AT+CSQ");
  120.     digitalWrite(27, HIGH);
  121.     send_at("AT+GSN");
  122.     digitalWrite(27, HIGH);
  123.   }
  124. }
  125.  
  126. void send_at(char *_command) {
  127.   SerialAT.println(_command);
  128.   wRespon(1000);
  129. }
  130.  
  131. void wRespon(long waktu) {
  132.   cur_time = millis();
  133.   old_time = cur_time;
  134.   while (cur_time - old_time < waktu ) {
  135.     cur_time = millis();
  136.     while (SerialAT.available() > 0) {
  137.       Serial.print(SerialAT.readString());
  138.     }
  139.   }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement