-1

I'm trying to run get query on arduino.

here are my code.

    #include <RBD_Timer.h> // https://github.com/alextaujenis/RBD_Timer
    
    RBD::Timer timer(500);
    
    int cnt = -1;
    
    const String webURL = "https://webhook.site/457acaa4-ea36-459a-a8c8-b275a21a5df2";
    
    
    void setup(){
      delay(2000);
      Serial.begin(9600);
      Serial.setTimeout(100);
      delay(10);
    
      Serial1.begin(115200);
      delay(10);
    
      issueCommand("ATI");
    }
    
    void loop(){
      String command = "";
      readSerial();
      while(Serial.available())
      {
        command = Serial.readStringUntil('\n');
        issueCommand(command);
      }
      if(timer.onRestart()){cnt++;operation();}
    }
    
    void issueCommand(String msg){
      Serial1.println(msg);
      delay(10);
    }
    
    void readSerial(){
      while (Serial1.available()){
        Serial.write(Serial1.read());
        timer.restart();
      }
    }
    
    void operation()
    {  
      if      (cnt == 0){issueCommand("AT+QIDEACT=1");}
      else if (cnt == 1){issueCommand("AT+QIACT?");}
      else if (cnt == 2){issueCommand("AT+QICSGP=1,1,\"internet\",\"\",\"\" ,3");}
      else if (cnt == 3){issueCommand("AT+QIACT?");}
      else if (cnt == 4){issueCommand("AT+QIACT=1");}
      else if (cnt == 5){issueCommand("AT+QIACT?");}
      else if (cnt == 6){issueCommand("AT+QHTTPURL="+String(webURL.length())+",80");}
      else if (cnt == 7){issueCommand(webURL);} //https://webhook.site/457acaa4-ea36-459a-a8c8-b275a21a5df2
      else if (cnt == 8){issueCommand("AT+QHTTPGET=80");timer.setTimeout(3000);}
      else if (cnt == 9){issueCommand("AT+QHTTPREAD=80");}
    }

I'm running these code in sequence. Each line send the AT codes to QUECTEL from Serial1 at 115200 baudrate. There is a 500ms wait on most of the AT codes but after get I increased it to 3000ms.

Here is my response on Serial monitor

OK
AT+QIDEACT=1

OK
AT+QIACT?

OK
AT+QICSGP=1,1,"internet","","" ,3

OK
AT+QIACT?

OK
AT+QIACT=1

OK
AT+QIACT?

+QIACT: 1,1,1,"172.30.138.99"

OK
AT+QHTTPURL=57,80

CONNECT

OK
AT+QHTTPGET=80

OK

+QHTTPGET: 0,200
AT+QHTTPREAD=80

CONNECT
A1234567890,B1234567890,C1234567890,567890
OK

+QHTTPREAD: 0

As you see on the response line I got;

A1234567890,B1234567890,C1234567890,567890

but it has to be;

A1234567890,B1234567890,C1234567890,D1234567890,E1234567890

Everytime I did the query the response changes. Here it is...

AT+QHTTPGET=80

OK

+QHTTPGET: 0,200
AT+QHTTPREAD=80

CONNECT
A1234567890,B1234567890,C1234567890,4567890,E1234567890
OK

+QHTTPREAD: 0

Here again another...

+QHTTPGET: 0,200
AT+QHTTPREAD=80

CONNECT
A1234567890,B1234567890,C1234567890,90,E1234567890
OK

+QHTTPREAD: 0

If I done the query over PowerShell , there were no problems...

What is the key?

bladekel
  • 13
  • 3
  • You need to provide the code for (at least) `issueCommand` for anyone being able to help with this. – hlovdal Aug 03 '23 at 17:14
  • When you type command over PowerShell, you are sending data limited by the speed you are typing (that is, very slow), when you running some script, you probably sending each of the commands in microsecond (or with insufficient wait for the module to response to your AT command). We have no idea what the `issueCommand` does. – hcheung Aug 04 '23 at 03:44
  • I tidied up code and wrote it all... – bladekel Aug 04 '23 at 06:19
  • Many AT commands return more than just an `OK\n`, For example, a query of `AT+QIACT?` could get a return of `OK\n` or `+QIACT: 1,1,1,"172.30.138.99"\nOK\n`, your code is designed based on upon receiving of first `\n` without parsing what is actually return, so what you received is an imcomplete reply. Parsing AT Commands is more complicated that you thought, I would suggest you use a well-tested library such as [TinyGSM](https://github.com/vshymanskyy/TinyGSM) than trying to write your own parser. – hcheung Aug 04 '23 at 12:23

0 Answers0