forked from JayaSurya-27/GSM_Module
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_request.txt
More file actions
41 lines (32 loc) · 1 KB
/
get_request.txt
File metadata and controls
41 lines (32 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <SoftwareSerial.h>
SoftwareSerial gsmSerial(17, 16);
const char* SERVER_URL = "https://api.thingspeak.com/update?api_key=NXZ8BW7FX347SMSX&field1=";
void setup() {
Serial.begin(9600);
gsmSerial.begin(9600);
}
bool sendATCommand(String command) {
Serial.println("Sending command: " + command);
gsmSerial.println(command);
delay(1000);
while (gsmSerial.available()) {
Serial.write(gsmSerial.read());
}
String response = gsmSerial.readStringUntil('\n');
Serial.println("Response: " + response);
return response.startsWith("OK");
}
void loop() {
float latitude = 15.483404;
float longitude = 74.939025;
String url = String(SERVER_URL) + String(latitude, 6) + "&field2=" + String(longitude, 6);
if (sendATCommand("AT+HTTPINIT") &&
sendATCommand("AT+HTTPPARA=\"URL\",\"" + url + "\"") &&
sendATCommand("AT+HTTPACTION=0")) {
delay(10000);
sendATCommand("AT+HTTPTERM");
} else {
Serial.println("Failed to perform HTTP request.");
}
delay(5000);
}