0

i use a linux machine with a localhost php server installed. Wifi machine is connected to the ESP-01 module (access point mode) and i can send several datas to the Arduino via the ESP-01 set as:

  sendData("AT+RST\r\n",2000,DEBUG); // reset module
  sendData("AT+CWMODE=2\r\n",1000,DEBUG); // configure as access point
  sendData("AT+CIFSR\r\n",1000,DEBUG); // get ip address
  sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections
  sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80

The php server can send data by GET method and Arduino receives pin=11:

 http://192.168.4.1:80/?pin=11

But, now, i would like to send to the php server datas from the Arduino. I tried this configuration but in my sketch but, it returns, error.

sendData("AT+CIPSTART=0,'TCP','http://localhost',80\r\n",1000,DEBUG);

Serial monitor:

   ERROR
   AT+CIPSTART=0,'TCP','http://localhost/test_php',80

   Link type ERROR

So please, how can i send and receive data with my ESP-01 module?

2

"localhost" is a name associated with the loopback interface of your computer. That is, 127.0.0.1.

It is not the address of your computer on the network. The only computer that can talk to "localhost" is the computer itself.

Instead of "localhost" you must use the IP address of your computer (or a FQDN that resolves to the IP address of your computer).

And you cannot open a TCP connection to a URL. You open a TCP connection to an IP or FQDN.

You really should learn the basics of IP networks before trying to write software for them.


Since your PC can communicate with the ESP8266 on 192.168.4.1 I assume that you are running the ESP8266 in SOFTAP mode and you have a WiFi interface connected to that access point. If so that WiFi interface will have a 192.168.4.x address assigned to it. That is the address you must open with a TCP connection on port 80 to connect to your apache server.

For example:

sendData("AT+CIPSTART=0,'TCP','192.168.4.3',80\r\n",1000,DEBUG);

Then you can craft a suitable HTTP request to send the data.

  • i replaced localhot by 127.0.0.1. Terminal returns same error Link type – Teddol Nov 19 '18 at 21:05
  • 1
    I said not localhost. – Majenko Nov 19 '18 at 21:05
  • And you deleted the protocol. – Majenko Nov 19 '18 at 21:06
  • 1
    Do you read? I said do NOT use the localhost address. Use the IP address of your computer on the network. And put back in the protocol that you deleted. – Majenko Nov 19 '18 at 21:08
  • 1
    Sorry, but i'm a beginner with arduino and i try to understand how it works with ESP-01 and distant php server. The ESP is not linked to my house network and i don't want it as. i need more help... – Teddol Nov 19 '18 at 21:18
0

Open command prompt and type ipconfig Under IPv4 Address you can see IP or your PC. That IP address is address of localhost(because your PC is a "server" within your local/home network).

Don't forget to config XAMP/WAMP to listen special addresses. And of course if you want use localhost, your PC must be on.

Yes, pc can send, but how can arduino do the same to the pc

Yes, it can. PC(localhost) is server and Arduino is client, like Stackexchange is host and your PC is a client (to Stackexchange). I hope you get it

 The ESP is not linked to my house network and i don't want it as

You can use public server, but you need to Know IP address of the server.

  • he connects to esp8266 as AP. so not the address on home network, but the address on WiFi interface connected to esp8266 – Juraj Nov 20 '18 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.