-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttpRequest.ino
89 lines (77 loc) · 2.14 KB
/
httpRequest.ino
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <SoftwareSerial.h>
//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2
void setup()
{
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
//Begin serial communication with Arduino and SIM800L
mySerial.begin(9600);
Serial.println("Initializing...");
delay(1000);
mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
updateSerial();
mySerial.println("AT+CSQ"); //Signal quality test, value range is 0-31 , 31 is the best
updateSerial();
mySerial.println("AT+CCID"); //Read SIM information to confirm whether the SIM is plugged
updateSerial();
mySerial.println("AT+CREG?"); //Check whether it has registered in the network
updateSerial();
}
void loop()
{
updateSerial();
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(mySerial.available())
{
Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
}
}
void makeHttpsRequest(){
mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
delay(wait);
while (mySerial.available())
{
Serial.write(mySerial.read());
}
mySerial.println("AT+SAPBR=3,1,\"APN\",\"internet\"");
delay(wait);
while (mySerial.available())
{
Serial.write(mySerial.read());
}
mySerial.println("AT+SAPBR=1,1");
delay(10000);
while (mySerial.available())
{
Serial.write(mySerial.read());
}
mySerial.println("AT+SAPBR=2,1");
delay(5000);
while (mySerial.available())
{
Serial.write(mySerial.read());
}
delay(4000);
{
Serial.write(mySerial.read());
}
mySerial.print(("AT+HTTPPARA=\"URL\",\"http://example.com/rest-api?getrequest="));
mySerial.print(server_message);
mySerial.println("\"");
{
Serial.write(mySerial.read());
}
mySerial.println("AT+HTTPACTION=0");
delay(2000);
{
Serial.write(mySerial.read());
}
}