EDIT: Found the answer
Ive got a PHP file which i call to enter some data with a HTTP GET request. It inserts some data into a database, and works fine for that. But i'd like to read what the website posts and print it in Serial.
Heres the code:
The function used to call AT commands:
void ModemCommand(String command)
{
//Send command to modem
mySerial.println(command);
Serial.println(command);
delay(100);
while (!mySerial.available())
{ //Wait for Response from modem
Serial.println(F("No response yet"));
delay(1000);
}
while (mySerial.available())
{
Serial.write(mySerial.read()); //Print response from modem
}
//Serial.println(""); //Linefeed after reponse
delay(1000);
}
ModemDataEnd:
void ModemDataEnd()
{
mySerial.write(0x1A); // sends ctrl+z end of message //0X1a=Ctrl-Z, 0x0a=LF, 0x0D=CR
delay(3000);
while (!mySerial.available())
{ //Wait for Response from modem
Serial.println(F("No response yet"));
delay(1000);
}
while (mySerial.available())
{
Serial.write(mySerial.read()); //Print response from modem
}
Serial.println(""); //Linefeed after reponse
delay(1000);
}
The function called to do the actual sending:
void ModemConnectSend()
{
File sendFile = SD.open("send.txt", FILE_READ);
String modemResponse;
//Todo: Pack reset and startup in IF
Serial.println("-------------------------");
//Reset modem
pinMode(ModemReset, OUTPUT);
Serial.print("Reset modem pin: 0...");
digitalWrite(ModemReset, LOW);
waitSec(1, "emptying capacitors");
digitalWrite(ModemReset, HIGH);
Serial.println(millis());
Serial.println("SoftwareSerial Modem test");
waitSec(2, "modem booting up");
ModemCommand("AT"); //Wake modem
//DebugModem();
ModemCommand(F("ATE0")); //Turn on echo
ModemCommand(F("AT+CFUN=1")); //Turn modem functions on
ModemCommand(F("AT+CSTT=\"internet\"")); //Set APN
while (modemResponse.indexOf("OK") < 0 )
{
ModemCommand(F("ATE0"));
ModemCommand(F("AT+CIPSHUT")); //Close GPRS connection
delay(100);
ModemCommand(F("AT+CSTT=\"internet\"")); //Set APN
delay(100);
modemResponse = ModemCommandResponse("AT+CIICR",1000); //Gemmer response i en streng.
Serial.print(" IndexOf: ");
Serial.println(modemResponse.indexOf("OK"));
delay(1000);
}
ModemCommand(F("AT+CIFSR")); //Get IP
//---- Send GET request -----
ModemCommand(F("AT+CIPSTART=\"TCP\",\"domain.com\",\"80\"")); //Connect to TCP Server
//Wait for OK
//waitSec(8,F("connecting to TCP Server")); //Todo: Wait for connect response
ModemCommand(F("AT+CIPSTATUS")); //Connection status
//Read Signal and Temperature
//String getValueFromModem(String commandString, String startSequence, int startOffset, String endSequence, int delayResponse)
String ReadModemSignal = getValueFromModem(F("AT+CSQ"), "CSQ", 5, ",", 1000);
String ReadModemTemp = getValueFromModem(F("AT+CMTE?"), ",", 1, ".", 1000);
String ReadModemSIM = getValueFromModem(F("AT+CCID"), "8", 0, "\n", 1000);
ReadModemSIM = ReadModemSIM.substring(0,19);
ModemCommand(F("AT+CIPSEND")); //TCP data
mySerial.print(F("GET /subdir/somethingElse.php?sim=")); //SEND START
mySerial.print(ReadModemSIM);
mySerial.print(F("&signal="));
if(ReadModemSignal.indexOf("\n") > -1)
{
Serial.print("Signal IndexOf: ");
Serial.println(ReadModemSignal.indexOf("\n"));
Serial.print("NO SIGNAL-");
Serial.print(ReadModemSignal);
Serial.println("-NO SIGNAL");
ReadModemSignal="";
}
mySerial.print(ReadModemSignal);
mySerial.print(F("&temperature="));
mySerial.print(ReadModemTemp);
mySerial.print(F("&data="));
while (sendFile.available())
{
mySerial.print(char(sendFile.read()));
}
mySerial.print(F(" HTTP/1.1"));
ModemDataEnd();
sendFile.close();
ModemCommand(F("AT+CIPCLOSE")); //Close TCP
SD.remove("send.txt");
}
The PHP file just echos the sql command. Ive looked around on the forums and on google, but I cant find a way of doing it without using a library (which our modem doesnt support) so we built our own solution.
As i said it inserts just fine, just need it to print the echo from the PHP file in Serial.
I looked at stuff like this, [SOLVED] How to read http request with AT command TCP - Programming Questions - Arduino Forum
But didnt find a solution ![]()
Any help is much appreciated.