Skip to content

Instantly share code, notes, and snippets.

View recyclerobot's full-sized avatar

Thijs Bernolet recyclerobot

View GitHub Profile
while( (sendATcommand("AT+CREG?", "+CREG: 0,1", 500) ||
sendATcommand("AT+CREG?", "+CREG: 0,5", 500)) == 0 );
sendATcommand("AT+CGSOCKCONT=1,\"IP\",\"web.be\"","OK",1000);
sendATcommand("AT+CSOCKAUTH=1,1,,\"web\",\"web\"","OK",1000);
int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout){
uint8_t x=0, answer=0;
char response[100];
unsigned long previous;
memset(response, '\0', 100); // Clean response buffer
delay(100); // Delay to be sure no passed commands interfere
while( Serial.available() > 0) Serial.read(); // Wait for clean input buffer
sendATcommand("AT", "OK", 2000);
while(answer == 0){ // Send AT every two seconds and wait for the answer
answer = sendATcommand("AT", "OK", 2000);
}
sendATcommand("AT+CPIN=1234", "OK", 2000);
answer = sendATcommand("AT+CGPS=1,2","OK",1000);
sendATcommand("AT+CGPSINFO","+CGPSINFO:",1000);
sendATcommand("AT+CHTTPACT=\"yourserver.com\",80", "+CHTTPACT: REQUEST", 60000);
Serial.println("GET /a_random_subdirectory_or_file/index.php HTTP/1.1\r\nHost: www.yourserver.com\r\n\r\n");