5
5
5diezov2019-01-10 22:14:54
Arduino
5diezov, 2019-01-10 22:14:54

How to use arduino to put data on a remote server by URL?

Task:
To put data into the database on the server, the transfer is by the get method.
But the fact is that everything works fine on the home server, accessing the server by ip,
And manually, like: 192.168.10.21/get.php?data1ard=1.00&data2ard=2.00&...
And the arduina connects normally and transfers data .
Access to the remote server is only by URL.
Manually everything works: site.com.ua/get.php?data1ard=1.00&data2ard=2.00&da...
And the arduino can't reach it in any way.
What could be the problem?

#include <Ethernet.h>
float a=1, b=2, c=3; 
String msg = "GET /get.php?data1ard="+ String(a) + "&data2ard="+String(b) + "&data3ard="+String(c);

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
IPAddress ip(192, 168, 10, 22);
byte server[] = { 192, 168, 10, 21 };
//char server[] = "www.site.com.ua";

void setup()
{
}

void loop()
{
EthernetClient client;
  Ethernet.begin(mac, ip);
    delay(1000);  
      client.connect(server, 80);
      client.println(msg);
      client.println(" HTTP/1.1");
      client.println("Connection: close");
      client.println();
      client.println();
    delay (2000);   
client.stop();   
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vanyamba-electronics, 2019-01-11
@5diezov

Most likely this is the case:

client.println(msg);
client.println(" HTTP/1.1");
client.println("Connection: close");

Try like this:
client.print("GET ");
client.print(msg);
client.println(" HTTP/1.1");
client.println("Host: 192.168.10.21");
client.println("Connection: close");

V
Vladislav, 2019-01-10
@ghostiam

You are trying to connect to a server over a domain, but the connection cannot be established on a domain, only on an IP.
To solve this problem, there are DNS services that convert a domain name into an IP address.
You need to either find a library to work with DNS or write queries manually.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question