Advertisement
mikroavr

modem_at_command_bluetooth_old

Feb 11th, 2021
1,028
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 PKEY 5
  4. #define RST 4
  5. unsigned long cur_time, old_time;
  6. #define TINY_GSM_MODEM_SIM7600
  7. #include <TinyGsmClient.h>
  8. #define SerialMon Serial
  9. #define TINY_GSM_DEBUG SerialMon
  10. #define SerialAT Serial2
  11.  
  12.  
  13. #ifdef DUMP_AT_COMMANDS
  14.   #include <StreamDebugger.h>
  15.   StreamDebugger debugger(SerialAT, SerialMon);
  16.   TinyGsm modem(debugger);
  17. #else
  18.   TinyGsm modem(SerialAT);
  19. #endif
  20.  
  21. bool hold = 0;
  22.  
  23. #include "BluetoothSerial.h"
  24.  
  25. #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
  26. #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
  27. #endif
  28.  
  29. BluetoothSerial SerialBT;
  30.  
  31. void setup() {
  32.   // put your setup code here, to run once:
  33.   SerialMon.begin(115200);
  34.   SerialAT.begin(9600, SERIAL_8N1, RXD2, TXD2);
  35.   delay(1000);
  36.   Serial.println("test at mulai");
  37.   pinMode(RST, OUTPUT);
  38.   //pinMode(PKEY, OUTPUT);
  39.   //digitalWrite(PKEY, LOW);
  40.   digitalWrite(RST, HIGH);delay(1000);
  41.   digitalWrite(RST, LOW);delay(1000);
  42.   digitalWrite(RST, HIGH);delay(1000);
  43.   delay(1000);
  44.   wRespon(15000);
  45.   /*SerialAT.println("AT");
  46.   wRespon(1000);
  47.   SerialAT.println("AT+IPREX?");
  48.   wRespon(1000);
  49.   SerialAT.println("AT+IPREX=9600");
  50.   wRespon(1000);
  51.   SerialAT.println("AT&W");
  52.   wRespon(1000);
  53.   SerialAT.begin(9600, SERIAL_8N1, RXD2, TXD2);
  54.   */
  55. }
  56.  
  57. void loop() {
  58.   // put your main code here, to run repeatedly:
  59.   Serial.println("SEND AT");
  60.   send_at("AT");
  61.   send_at("ATI");
  62.   send_at("AT+IPR?");
  63.   send_at("AT+CPIN?");
  64.   send_at("AT+CPIN?");
  65.   send_at("AT+CSQ");
  66.   send_at("AT+CREG?");
  67.   send_at("AT+CPSI?");
  68.  
  69.  
  70. }
  71.  
  72. void send_at(char *_command) {
  73.   SerialAT.println(_command);
  74.   wRespon(1000);
  75. }
  76.  
  77. void wRespon(long waktu){
  78.   cur_time = millis();
  79.   old_time = cur_time;
  80.   while(cur_time - old_time < waktu ){
  81.     cur_time = millis();
  82.     while(SerialAT.available()>0){
  83.       //Serial.print(SerialAT.readString());
  84.       SerialBT.println(SerialAT.readString());
  85.     }
  86.   }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement