SIM808 upload data on server

Hi everybody,
Im trying to use my SIM808 to upload some data on a mySQL server.
I’m trying to use AT command but i get an error that i can’t solve…
That’s the command i’ve used and the response

AT
OK
AT+SAPBR=3,1,"APN","web.omnitel.it"
OK
AT+SAPBR=1,1
OK
AT+HTTPINIT
OK
AT+HTTPPARA="CID",1
OK
AT+HTTPPARA="URL","http://xxxxxxxxx.000webhostapp.com/post-esp-data.php"
OK
AT+HTTPPARA="CONTENT","Content-Type: application/x-www-form-urlencoded"
OK
AT+HTTPDATA=92,10000
DOWNLOAD

api_key=xxxxxxxxx&sensor=BME280&location=Office&value1=24.75&value2=49.54&value3=1005.14

OK
AT+HTTPACTION=1
OK

+HTTPACTION: 1,200,23
AT+HTTPREAD
+HTTPREAD: 23
Wrong API Key provided.
OK

I’ve send the same string through wifi with esp32 an it has worked so the apykey is correct and also the string has worked great…
The wired things is also that it seams transmits only 32 bytes…

What did i do wrong?

Thank you very much
Matteo

This is code is a translation of this code written for esp32…i’ve tried to translate it for
the use of SIM808 becouse i don’t have wifi where i need it…
please help is for register the weight of my beehives :slight_smile:

/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp32-esp8266-mysql-database-php/
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

*/

#ifdef ESP32
  #include <WiFi.h>
  #include <HTTPClient.h>
#else
  #include <ESP32WiFi.h>
  #include <ESP32HTTPClient.h>
  #include <WiFiClient.h>
#endif

#include <Wire.h>
//#include <Adafruit_Sensor.h>
//#include <Adafruit_BME280.h>

// Replace with your network credentials
const char* ssid     = "xxxxx";
const char* password = "xxxxx";

// REPLACE with your Domain name and URL path or IP address with path
const char* serverName = "http://xxxxxapicoltore.000webhostapp.com/post-esp-data.php";

// Keep this API Key value to be compatible with the PHP code provided in the project page. 
// If you change the apiKeyValue value, the PHP file /post-esp-data.php also needs to have the same key 
String apiKeyValue = "xxxxxxxxxx";

String sensorName = "Bilancia";
String sensorLocation = "Brentonico";

/*#include <SPI.h>
#define BME_SCK 18
#define BME_MISO 19
#define BME_MOSI 23
#define BME_CS 5*/

#define SEALEVELPRESSURE_HPA (1013.25)

//Adafruit_BME280 bme;  // I2C
//Adafruit_BME280 bme(BME_CS);  // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);  // software SPI

void setup() {
  Serial.begin(115200);
  
  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while(WiFi.status() != WL_CONNECTED) { 
delay(500);
Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());

  // (you can also pass in a Wire library object like &Wire2)
  //bool status = bme.begin(0x76);
  //if (!status) {
//Serial.println("Could not find a valid BME280 sensor, check wiring or change I2C address!");
//while (1);
  //}
}

void loop() {
  //Check WiFi connection status
  if(WiFi.status()== WL_CONNECTED){
HTTPClient http;

// Your Domain name with URL path or IP address with path
http.begin(serverName);

// Specify content-type header
http.addHeader("Content-Type", "application/x-www-form-urlencoded");

// Prepare your HTTP POST request data
String httpRequestData = "api_key=" + apiKeyValue + "&sensor=" + sensorName
                      + "&location=" + sensorLocation + "&value1=" + String("500")
                      + "&value2=" + String("200") + "&value3=" + String("300") + "";
Serial.print("httpRequestData: ");
Serial.println(httpRequestData);

// You can comment the httpRequestData variable above
// then, use the httpRequestData variable below (for testing purposes without the BME280 sensor)
//String httpRequestData = "api_key=tPmAT5Ab3j7F9&sensor=BME280&location=Office&value1=24.75&value2=49.54&value3=1005.14";

// Send HTTP POST request
int httpResponseCode = http.POST(httpRequestData);
 
// If you need an HTTP request with a content type: text/plain
//http.addHeader("Content-Type", "text/plain");
//int httpResponseCode = http.POST("Hello, World!");

// If you need an HTTP request with a content type: application/json, use the following:
//http.addHeader("Content-Type", "application/json");
//int httpResponseCode = http.POST("{\"value1\":\"19\",\"value2\":\"67\",\"value3\":\"78\"}");
    
if (httpResponseCode>0) {
  Serial.print("HTTP Response code: ");
  Serial.println(httpResponseCode);
}
else {
  Serial.print("Error code: ");
  Serial.println(httpResponseCode);
}
// Free resources
http.end();
  }
  else {
Serial.println("WiFi Disconnected");
  }
  //Send an HTTP POST request every 30 seconds
  delay(30000);  
}

This was written for read a BME280 sensor…i will use a load cell tu mesure the weight and transmit it but is just for try the transmission a server before i build my beehive scale…

Thank you very much

Hello and welcome!

You need to remove “Content-Type: ” from this line, as this command would add it for you. As you have it written, it’ll send to the server something like Content-Type: Content-Type: application/x-www-form-urlencoded

1 Like

Thankyou very much :slight_smile: i’ve solved modifyng php code…now i just visit the web page (with all data like this .php?value1=100&value2=200 and it adds data to my database… :slight_smile: ) thank you very much!

1 Like