Closed sandzsandz closed 4 years ago
Totally agree a POST example would be amazing. Need this right now ;)
try
#include <GPRS_Shield_Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#define PIN_TX 7
#define PIN_RX 8
//make sure that the baud rate of SIM900 is 9600!
//you can use the AT Command(AT+IPR=9600) to set it through SerialDebug
#define BAUDRATE 9600
//example.com/index.php?visor=false&latitude=-6.342597&longitude=107.155583
char http_cmd[100];
char buffer[512];
float long2 = 106.880715;
float lat2 = -6.120140;
char latstr[40];
char longstr[40];
GPRS gprs(PIN_TX, PIN_RX, BAUDRATE);
void setup() {
Serial.begin(9600);
dtostrf(lat2, 7, 6, latstr);
dtostrf(long2, 9, 6, longstr);
sprintf(http_cmd, "GET visor=false&latitude=%s&longitude=%s HTTP/1.0\r\n\r\n", latstr, longstr);
// use DHCP
while (!gprs.init()) {
delay(1000);
Serial.print("init error\r\n");
}
delay(3000);
// attempt DHCP
while (!gprs.join(F("internet"), F("internet"), F("internet"))) {
Serial.println("gprs join network error");
delay(2000);
}
// successful DHCP
Serial.print("IP Address is ");
Serial.println(gprs.getIPAddress());
if (!gprs.connect(TCP, "example.com/index.php?", 80)) {
Serial.println("connect error");
} else {
Serial.println("connect example.com success");
}
Serial.println("waiting to fetch...");
sim900_send_cmd(F("AT+CIPSEND\r\n"));
sim900_send_cmd(http_cmd);
sim900_send_byte(0x1A);
// gprs.send(http_cmd, sizeof(http_cmd) - 1);
// while (true) {
// int ret = gprs.recv(buffer, sizeof(buffer) - 1);
// if (ret <= 0) {
// Serial.println("fetch over...");
// break;
// }
// buffer[ret] = '\0';
// Serial.print("Recv: ");
// Serial.print(ret);
// Serial.print(" bytes: ");
// Serial.println(buffer);
// }
Serial.print(http_cmd);
gprs.close();
gprs.disconnect();
}
void loop() {
}
The hardware modules SIM800 and SIM900 support HTTP natively. Check the command manual: http://www.jechavarria.com/wp-content/uploads/2015/05/SIM900-AT-Commands-Manual_V1.07.pdf
I'm currently working on HTTP GET support for this library. If this is done, adding HTTP Post is not a big deal anymore.
Dear Admin, i hope you can give me refrence for this i've done with manually type that link in my browser web and it's working fine (can input php variable) but i test use POST or PUT im arduino code , it's not working T_T i hope you can explain or give me a some code thx before , i hope you can help me, its important for me [example.com/index.php?visor=false&latitude=-6.342597&longitude=107.155583]