0

I have the TEL0124 SIM7600 modem 4G LTE module connected to an Arduino board. will.

While I am able to send AT and get an OK, I would like to use a php to transfer data to the server. I am not able to send any data to the server


void setup()
{
    Serial.begin(115200);
    Serial1.begin(115200);
    sendData("AT+CCID/r", 3000, DEBUG);
    sendData("AT+CREG?/r", 3000, DEBUG);
    sendData("AT+CGATT=1/r", 1000, DEBUG);
    sendData("AT+CGACT=1,1/r", 1000, DEBUG);
    sendData("AT+CGDCONT=1,\"IP\",\"TM\"/r", 1000, DEBUG);
    sendData("AT+CIPSTART=\"TCP\",\"www.sxxxxde/data2mysql.php?key=xxx",80/r", 2000, DEBUG);
    Serial.println("4G HTTP Test Begin!");
}  
void loop()
  string http_str  = "AT+HTTPPARA=\"URL\","HTTPP:www.sxxxxde.de/data2mysql.php?key=xxxx&ID=9999A0200A1300A21024A324A426A510A614A714A828A90A10A110A120"\"\r";
    Serial.println(http_str);
    sendData("AT+HTTPINIT\r", 2000, DEBUG);
    sendData(http_str, 2000, DEBUG);
    sendData("AT+HTTPACTION=0\r", 3000, DEBUG);
    sendData("AT+HTTPTERM\r", 3000, DEBUG);}
String sendData(String command, const int timeout, boolean debug){
  String response = "";
  Serial1.println(command);    
  long int time = millis();
  while ( (time + timeout) > millis())
  {
    while (Serial1.available())
    {
      char c = Serial1.read();
      response += c;
    }
  }
 

This is simply an example (written here), but it somewhat illustrates what I am doing. ,sendingg a string of data tto the server via a PHP call.

I want to send data via 4g but as GSM isn't working anymore for my modems SIM800 SIM900. This is why I opted for the 4G LTE version.

Any idea on how to send a string of data stream to the server on 4G?

Any help is much appreciated!

Updated the code

Zeiti Z
  • 1
  • 2
  • 1
    In general: 1. HTTP is a simple request/response protocol, and is not suitable for continuous streaming. You can hack it in, but it will be overly complicated and fragile. 2. PHP has always been primarily focused on serving this simple request/response protocol, and is not especially well-suited for running continuously. You can make PHP do it, but there are a number of caveats to learn and pitfalls to avoid, and the documentation on these is sparse at best. – Sammitch May 12 '23 at 21:26
  • I had a copy paste error in my question. Not continuous but sending just a string of data – Zeiti Z May 13 '23 at 10:39
  • be more careful about forward slash and backward slash. They are not the same thing. – John Henckel Jul 08 '23 at 16:20

2 Answers2

0

There are several severe issues with your AT command handling.

1a)

The command line should be terminated with \r only and not \r\n. The V.250 specification says:

"A command line is made up of three elements: the prefix, the body, and the termination character. ... The termination character may be selected by a user option (parameter S3), the default being CR"

Notice the language here, "the termination character". ONE, not two characters1.

And just to emphasis how important that document is: Even after working with implementing AT commands in mobile phones in Ericsson for over a decade I and my colleagues still consulted that document regularly!

In fact, stop reading the rest of this answer right now and instead read all of chapter 5 in V.250 first, and then continue reading the rest here.

1b)

The command lines attempted to be invoked in your setup function all lack a termination character and thus will not be recognized as a command line. In other words all the command lines attempted to be executed are ignored by the modem as garbage input.

2)

You should never use waiting a certain amount of time as a substitute for reading and parsing responses from a modem.

You must implement code to read the response sent back from the modem and parse it to properly recognize and wait for Final result codes. Nothing else will work.

Using Serial1.available() (+ time) as a framing mechanism is guarantied not to work. You must buffer modem response data character by character until you have a complete response line, and then you can go ahead and parse/process that line.


1 And you should never change S3 from its default value 13, so in practice you never have to deal with that register.

hlovdal
  • 26,565
  • 10
  • 94
  • 165
  • thanks have made the changes but need now to do the checking of the return values in place of waiting – Zeiti Z May 17 '23 at 15:50
0

In my opinion, the next line is incorrect:

string http_str = "AT+HTTPPARA=\*URL","HTTPP://www.sxxxxde.de/data2mysql.php?key=xxxx&ID=9999A0200A1300A21024A324A426A510A614A714A828A90A10A110A120"\"\r\n";

In C string, if you want use a quotation mark, you must write a backslash + quotation mark combination, around the URL and HTTP.... parameters. (I wrote the corrected line before, but this editor has modified my string to bad.)

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Gyuri
  • 1
  • 1