You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.8 KiB
72 lines
1.8 KiB
|
|
void sendRequest() {
|
|
|
|
s = BASE_URL;
|
|
s.concat("windSpeed=");
|
|
s.concat(windSpeed);
|
|
s.concat("&windDirection=");
|
|
s.concat(windDirection);
|
|
s.toCharArray(URL, 100);
|
|
|
|
Serial.println(URL);
|
|
|
|
// 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 GET..."));
|
|
Serial.println(URL);
|
|
|
|
// Do HTTP GET communication with 10s for the timeout (read)
|
|
uint16_t rc = sim800l->doGet(URL, 10000);
|
|
if(rc == 200) {
|
|
// Success, output the data received on the serial
|
|
Serial.print(F("HTTP GET successful ("));
|
|
Serial.print(sim800l->getDataSizeReceived());
|
|
Serial.println(F(" bytes)"));
|
|
Serial.print(F("Received : "));
|
|
Serial.println(sim800l->getDataReceived());
|
|
} else {
|
|
// Failed...
|
|
Serial.print(F("HTTP GET 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"));
|
|
}
|
|
|
|
|
|
windSpeed = 0;
|
|
}
|