I am using the following SIM800L library:
I am attempting to GET a field in a MySQL database.
I am using the "HTTPS_GET_HardwareSerial" example from the library.
The example has:
const char URL[] = "https://postman-echo.com/get?foo1=bar1&foo2=bar2";
Which I have edited to:
const char URL[] = "197.xxx.xxx.xx:3306/get?SELECT track FROM inv.devices"; // My Server IP
Here I attempt to GET field "track" from table "devices" in MySQL database "inv".
However, this does not work.
My complete code:
/********************************************************************************
* Example of HTTPS GET with Serial1 (Mega2560) and Arduino-SIM800L-driver *
* *
* Author: Olivier Staquet *
* Last version available on https://github.com/ostaquet/Arduino-SIM800L-driver *
********************************************************************************
* MIT License
*
* Copyright (c) 2019 Olivier Staquet
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*******************************************************************************/
#include "SIM800L.h"
#define SIM800_RST_PIN 11
const char APN[] = "flick.";
//const char URL[] = "https://postman-echo.com/get?foo1=bar1&foo2=bar2";
const char URL[] = "197.xxx.xxx.xx:3306/get?SELECT track FROM inv.devices"; // My Server IP
SIM800L* sim800l;
void setup() {
// Initialize Serial Monitor for debugging
Serial.begin(9600);
while(!Serial);
// Initialize the hardware Serial1
Serial1.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 *)&Serial1, 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.print(F("GPRS connected with IP "));
Serial.println(sim800l->getIP());
} else {
Serial.println(F("GPRS not connected !"));
Serial.println(F("Reset the module."));
sim800l->reset();
setupModule();
return;
}
Serial.println(F("Start HTTP GET..."));
// 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"));
}
// 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 suspect that there is some error in my URL GET command syntax.