├── GPRS_Post_Tests └── GPRS_Post_Tests.ino └── README.md /GPRS_Post_Tests/GPRS_Post_Tests.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define DEBUG 1 4 | #define SIM800_TX_PIN 8 5 | #define SIM800_RX_PIN 7 6 | 7 | SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN); 8 | char responseBuffer[256]; 9 | 10 | char *gprsStart[] = { 11 | (char *)"AT+SAPBR=3,1,\"Contype\", \"GPRS\"\r\n", // Configure bearer profile 12 | (char *)"AT+SAPBR=3,1,\"APN\",\"internet\"\r\n", 13 | (char *)"AT+SAPBR=1,1\r\n", // Open a GPRS context 14 | (char *)"AT+SAPBR=2,1\r\n" // Query the GPRS context 15 | }; 16 | char *gprsEnd[] = { (char *)"AT+SAPBR=0,1\r\n" }; // Close a GPRS context 17 | 18 | char *httpStart[] = { 19 | (char *)"AT+HTTPINIT\r\n", // Init HTTP service 20 | (char *)"AT+HTTPPARA=\"CID\",1\r\n", // Set parameters for HTTP session 21 | (char *)"AT+HTTPPARA=\"URL\",\"83.212.82.144:8888/upload\"\r\n", 22 | (char *)"AT+HTTPPARA=\"CONTENT\",\"image\"\r\n", 23 | (char *)"AT+HTTPDATA=5,10000\r\n", // POST the data, params (size as bytes, input latency time ms) 24 | (char *)"DEBUG", // POST Data 25 | (char *)"AT+HTTPACTION=1\r\n", // POST Session start 26 | (char *)"AT+HTTPREAD\r\n" // Read the data 27 | }; 28 | char *httpEnd[] = { (char *)"AT+HTTPTERM\r\n" }; // Terminate HTTP Service 29 | 30 | char *locationQuery[] = { (char *)"AT+CIPGSMLOC=1,1\r\n" }; // Base station Location: 1)type = 1, get longitude and latitude 31 | 32 | 33 | void setup() { 34 | Serial.begin(9600); 35 | while(!Serial); 36 | serialSIM800.begin(9600); 37 | 38 | if(DEBUG) Serial.println("SETUP"); 39 | delay(3000); 40 | setGprs(); 41 | postData(); 42 | terminateHttp(); 43 | getLocation(); 44 | endGprs(); 45 | } 46 | 47 | void loop() { 48 | 49 | } 50 | 51 | void setGprs() { 52 | if(DEBUG) Serial.println("setGprs"); 53 | writeToSim(gprsStart, sizeof(gprsStart)/sizeof(*gprsStart)); 54 | } 55 | 56 | void endGprs() { 57 | if(DEBUG) Serial.println("endGprs"); 58 | writeToSim(gprsEnd, sizeof(gprsEnd)/sizeof(*gprsEnd)); 59 | } 60 | 61 | void postData() { // TODO Insert payload 62 | if(DEBUG) Serial.println("postData"); 63 | writeToSim(httpStart, sizeof(httpStart)/sizeof(*httpStart)); 64 | } 65 | 66 | void terminateHttp() { 67 | if(DEBUG) Serial.println("terminateHttp"); 68 | writeToSim(httpEnd, sizeof(httpEnd)/sizeof(*httpEnd)); 69 | } 70 | 71 | void getLocation() { 72 | if(DEBUG) Serial.println("getLocation"); 73 | writeToSim(locationQuery, sizeof(locationQuery)/sizeof(*locationQuery)); 74 | // TODO Scanf coordinates from responseBuffer 75 | Serial.println(readSim(responseBuffer, 5000)); 76 | } 77 | 78 | void writeToSim(char *commands[], int size) { 79 | for(int i = 0; i < size; i++) { 80 | serialSIM800.write(commands[i]); 81 | if(DEBUG) { Serial.print("Writing: "); Serial.println(commands[i]); } 82 | delay(1000); 83 | } 84 | 85 | while(serialSIM800.available()) serialSIM800.read(); // Ignore written commands 86 | } 87 | 88 | // Read Sim response until timeout 89 | char* readSim(char* buffer, int timeout) { 90 | unsigned long timeStart = millis(); 91 | int charCount = 0; 92 | 93 | while(1) { 94 | if(serialSIM800.available()) buffer[charCount++] = serialSIM800.read(); 95 | 96 | if(millis() - timeStart > timeout) break; 97 | } 98 | buffer[charCount++] = 0; 99 | return buffer; 100 | } 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SIM800L-ESP8266 2 | Setup with GPRS and WiFi connectivity 3 | --------------------------------------------------------------------------------