Hello to everybody,
I'm trying to use this library :GitHub - ostaquet/Arduino-SIM800L-driver: Arduino driver for GSM/GPRS module SIMCom SIM800L to make HTTP/S connections with GET and POST methods with Arduino UNO
I'm using the HTTPS POST with Serial example.
I want to post in my web site the d1 and d2 varilables using follow link:
http://mysite.com/myfile.php?d1=2.3&d2=3.0
The link works if I post it in my browser adding a line in my table created in a mysql server.
This is the example that I'm using:
#include <SoftwareSerial.h>
#include "SIM800L.h"
#define SIM800_TX_PIN 7
#define SIM800_RX_PIN 3
#define SIM800_RST_PIN 9
const char APN[] = "internet.it";
const char URL[] = "http://mysite.com/myfile.php?d1=2.3&d2=3.0";
const char CONTENT_TYPE[] = "application/json";
const char PAYLOAD[] = "{\"name\": \"morpheus\", \"job\": \"leader\"}";
SIM800L* sim800l;
void setup() {
// Initialize Serial Monitor for debugging
Serial.begin(9600);
while(!Serial);
// Initialize a SoftwareSerial
SoftwareSerial* serial = new SoftwareSerial(SIM800_TX_PIN, SIM800_RX_PIN);
serial->begin(9600);
delay(1000);
// Initialize SIM800L driver with an internal buffer of 200 bytes and a reception buffer of 512 bytes, debug disabled
sim800l = new SIM800L((Stream *)serial, SIM800_RST_PIN, 200, 512);
// Equivalent line with the debug enabled on the Serial
// sim800l = new SIM800L((Stream *)&Serial1, SIM800_RST_PIN, 200, 512, (Stream *)&Serial);
// Setup module for GPRS communication
setupModule();
}
void loop() {
// Establish GPRS connectivity (5 trials)
bool connected = false;
for(uint8_t i = 0; i < 5 && !connected; i++) {
delay(1000);
connected = sim800l->connectGPRS();
}
// Check if connected, if not reset the module and setup the config again
if(connected) {
Serial.println(F("GPRS connected !"));
} else {
Serial.println(F("GPRS not connected !"));
Serial.println(F("Reset the module."));
sim800l->reset();
setupModule();
return;
}
Serial.println(F("Start HTTP POST..."));
// Do HTTP POST communication with 10s for the timeout (read and write)
uint16_t rc = sim800l->doPost(URL, CONTENT_TYPE, PAYLOAD, 10000, 10000);
if(rc == 200) {
// Success, output the data received on the serial
Serial.print(F("HTTP POST successful ("));
Serial.print(sim800l->getDataSizeReceived());
Serial.println(F(" bytes)"));
Serial.print(F("Received : "));
Serial.println(sim800l->getDataReceived());
} else {
// Failed...
Serial.print(F("HTTP POST error "));
Serial.println(rc);
}
// Close GPRS connectivity (5 trials)
bool disconnected = sim800l->disconnectGPRS();
for(uint8_t i = 0; i < 5 && !connected; i++) {
delay(1000);
disconnected = sim800l->disconnectGPRS();
}
if(disconnected) {
Serial.println(F("GPRS disconnected !"));
} else {
Serial.println(F("GPRS still connected !"));
}
// Go into low power mode
bool lowPowerMode = sim800l->setPowerMode(MINIMUM);
if(lowPowerMode) {
Serial.println(F("Module in low power mode"));
} else {
Serial.println(F("Failed to switch module to low power mode"));
}
// End of program... wait...
while(1);
}
void setupModule() {
// Wait until the module is ready to accept AT commands
while(!sim800l->isReady()) {
Serial.println(F("Problem to initialize AT command, retry in 1 sec"));
delay(1000);
}
Serial.println(F("Setup Complete!"));
// Wait for the GSM signal
uint8_t signal = sim800l->getSignal();
while(signal <= 0) {
delay(1000);
signal = sim800l->getSignal();
}
Serial.print(F("Signal OK (strenght: "));
Serial.print(signal);
Serial.println(F(")"));
delay(1000);
// Wait for operator network registration (national or roaming network)
NetworkRegistration network = sim800l->getRegistrationStatus();
while(network != REGISTERED_HOME && network != REGISTERED_ROAMING) {
delay(1000);
network = sim800l->getRegistrationStatus();
}
Serial.println(F("Network registration OK"));
delay(1000);
// Setup APN for GPRS configuration
bool success = sim800l->setupGPRS(APN);
while(!success) {
success = sim800l->setupGPRS(APN);
delay(5000);
}
Serial.println(F("GPRS config OK"));
}
I don't know what I have to insert for CONTENT_TYPE[] and PAYLOAD[]. What is the meaning of these two variables?
The results of this code are:
Setup Complete!
Signal OK (strenght: 22)
Network registration OK
GPRS config OK
GPRS connected !
Start HTTP POST...
HTTP POST error 705
GPRS disconnected !
Failed to switch module to low power mode
What is the mistake? Could you help me?