Sending data from Arduino to my website

Hi guys,
I want to send data from my arduino to my website but I can only enter the hostname and the uri. I tried to use hostname= mysite.com (example) and uri=/post.php but it didn’t work. I tried also with hostname=files.000webhost.com but if I can’t enter the username and pw it seems useless…
Someone could please help me?

hostname is localhost
Also, can you provide some screenshots of your code?

Doesn’t work with localhost… here’s the code (Just the important part) :

String server="localhost";
String uri="/post.php";
data = "card=" +codiceLetto;
httppost();
void httppost () {
while(true){
esp8266.println("AT+CIPSTART=\"TCP\",\"" + server + "\",80");//start a TCP connection.
delay(1000);
if( esp8266.find("OK")) {
  Serial.println("TCP connection ready");
}
String postRequest =
"POST /post.php?"+data+" HTTP/1.0\r\n" +
"Host: "+server+"\r\n" +
//"Accept: *" + "/" + "*\r\n" +
//"Content-Length: " +data.length()+ "\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n";
String sendCmd = "AT+CIPSEND=";//determine the number of caracters to be sent.
delay(500);
esp8266.print(sendCmd);
delay(500);
esp8266.println(postRequest.length() );
delay(500);
if(esp8266.find(">")) { 
  Serial.println("Sending.."); 
  delay(500);
  esp8266.print(postRequest);
  delay(500);
  if( esp8266.find("SEND OK")) { 
    Serial.println("Packet sent");
    while(esp8266.available()) {
      Serial.write(esp8266.read());
    }
    while (esp8266.available()) {
      delay(500);
      String tmpResp = esp8266.readString();
      delay(500);
      Serial.println(tmpResp);
    }
    delay(500);
    esp8266.println("AT+CIPCLOSE"); //close the connection  
    break;
  }
}
else{
    Serial.println("Problemi con l'invio dei dati. Riprovo...");
}
}
}

So you want to connect to the database through arduino? Or to your files?

First to my files, into a php file, then to the database using the same php file.
Do you think I’d better send the data directly to the database?
Here’s my php file:

<?php
include("config2.php"); //connection to the database and select the database
$card = $_POST['card'];
$card = mysqli_real_escape_string($card);
$cc=0;
mysqli_query($db,"INSERT INTO usage (id,card_code) VALUES ($cc,$card)");
?>

Wait, let me do some research… :slight_smile:
You’d better do that with ftp, because in order to connect externally to the database, you’ll need a premium account

1 Like

Have a look at this:
https://forum.arduino.cc/index.php?topic=182382.0

Can I use the http protocol instead? I just need to send a string to the server, which will then send it to the database
FTP implementation is complicated…

@streba [quote=“streba, post:8, topic:71965”]
Can I use the http protocol instead? I just need to send a string to the server, which will then send it to the database
[/quote]

Give it a try :slight_smile:

Maybe set uri to /post.php?data=somedata
And then get the data in the php file:

  if(!empty($_GET['data'])){
    $data = $_GET['data'];
}

The problem is where the data goes. Should I use as server=mysite.com and uri=/post.php?

Give it a try :smiley: