Hello everyone,
I encounter 2 little impediments in my GSM quest
So, the first one is about HTTP. I'm trying to configure some HTTP functionalities but nothing really work.
Here is my serial monitor :
>
> OK
> AT+CMGF=1
> OK
>
> Call Ready //Boring URC
> AT+HTTPINIT
> OK
>
> SMS Ready //Boring URC
> AT+HTTPPARA="CID",1
> OK
> AT+HTTPPARA="URL","http:\\www.google.com"
> OK
> AT+HTTPACT //truncated answer...
> OK
>
> +CPIN: READY //Boring URC
AT+HTTPINITAT+HTTPPARA="CID",1 //wtf
> AT+HAT+HTTPACTION=0 //well
> OK //I doubt
So before I try anything with HTTP I must solve my second problem : How can I get better reading results ?
I tryed to follow this nice tutorial : Serial Input Basics - updated - Introductory Tutorials - Arduino Forum
Here is my code :
#define SIM800_RESET_PIN 77
#define PWKEY 6
const byte nbChars = 64;
char receivedChars[nbChars];
boolean newData = false;
String commandStringGSM;
String url = "http:\\\\www.google.com";
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
pinMode(SIM800_RESET_PIN, OUTPUT);
pinMode(PWKEY, OUTPUT);
digitalWrite(PWKEY, HIGH);
delay(1000);
digitalWrite(SIM800_RESET_PIN, LOW);
delay(100);
digitalWrite(SIM800_RESET_PIN, HIGH);
delay(2000);
}
void loop() {
delay(2000);
// Network registration
commandStringGSM = "AT+CREG=1";
Serial1.println(commandStringGSM);
delay(50);
readFromGsm();
showNewData();
delay(500);
// Set text mode
commandStringGSM = "AT+CMGF=1";
Serial1.println(commandStringGSM);
delay(50);
readFromGsm();
showNewData();
delay(500);
// Init HTTP service
commandStringGSM = "AT+HTTPINIT";
Serial1.println(commandStringGSM);
delay(50);
readFromGsm();
showNewData();
delay(500);
// Init HTTP service
commandStringGSM = "AT+HTTPPARA=\"CID\",1";
Serial1.println(commandStringGSM);
delay(50);
readFromGsm();
showNewData();
delay(500);
// Init HTTP service
commandStringGSM = "AT+HTTPPARA=\"URL\",\"" + url + "\"";
delay(100);
Serial1.println(commandStringGSM);
delay(100);
readFromGsm();
showNewData();
delay(500);
// Start the session
commandStringGSM = "AT+HTTPACTION=0";
Serial1.println(commandStringGSM);
delay(50);
readFromGsm();
showNewData();
delay(500);
// Start the session
commandStringGSM = "AT+HTTPREAD";
Serial1.println(commandStringGSM);
delay(50);
readFromGsm();
showNewData();
delay(500);
// Read HTTP status
commandStringGSM = "AT+HTTPSTATUS";
delay(100);
Serial1.println(commandStringGSM);
delay(100);
readFromGsm();
showNewData();
delay(500);
}
void readFromGsm(){
static byte ndx = 0;
char endMarker = '\n';
char rc;
delay(200);
while(Serial1.available() > 0 && newData == false && (receivedChars[ndx] != '\n' || receivedChars[ndx] != '\r')){
rc = Serial1.read();
if (rc != endMarker){
receivedChars[ndx] = rc;
ndx++;
if (ndx >= nbChars) {
ndx = nbChars -1;
}
}else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewData(){
if (newData == true) {
Serial.print("> ");
Serial.println(receivedChars);
newData = false;
}
}
I have no idea what i'm doing wrong in my reading function...
Unfortunately the GSM.h library for GSM shield doesn't work with my arduino DUE and my SIM800h so I guess I have to configure my module alone with some commands... The way i'm trying here ?
Thank you !