So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By ErcanCelen
#84630 Hello I am Ercan from Turkey,
I am working with a company works with IOT system as a PCB designer and mcu software developer. So recently I got a job and this is the first time I try something with ESP8266. I have a web service link like:

curl -X POST "http://20.20.20.20./api/be.php" -d "op=get_prof&pass=klmn&email=klm@mail.com"

this link return a json data and I tried to get this json data from esp8266-12f. so do I succeed so far, indeed not really. I do not write any code inside of esp, so I am communication with at commands. Can anyone help me about how I am going to write it truely.
I send it,
AT+CIPSTART=0,"TCP","20.20.20.20",80
and than,
AT+CIPSEND=0,98
and after '>',
curl -X POST "http://20.20.20.20./api/be.php" -d "op=get_prof&pass=klmn&email=klm@mail.com"

so all these steps it returns:
SEND OK

+IPD,0,309:HTTP/1.1 400 Bad Request
Server: nginx/1.16.1
Date: Tue, 19 Nov 2019 14:46:18 GMT
Content-Type: text/html
Content-Length: 157
Connection: close

<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
0,CLOSED


so it is wrong or I am writing wrongly. So anyone help me about this? How should I write? And I am really sorry if I did write it to wrong place.
User avatar
By davydnorris
#84638 If you are going to set up the ESP with a REST API, you would be better off flashing your own program into it and using Arduino or the RTOS SDK (or indeed MicroPython or Lua or any of the programming envionments). Then you have much more control over what is happening.

The AT firmware you are using is really for basic control of the device as a wifi module - it's not really designed for what you want.
User avatar
By ErcanCelen
#84641
davydnorris wrote:If you are going to set up the ESP with a REST API, you would be better off flashing your own program into it and using Arduino or the RTOS SDK (or indeed MicroPython or Lua or any of the programming envionments). Then you have much more control over what is happening.

The AT firmware you are using is really for basic control of the device as a wifi module - it's not really designed for what you want.


So you telling me, there is now way to achieve this data with AT commands. What a pity, I did really not get in ESP through that way.
Are you really sure? may be there is a way? And thank you for your response :)
User avatar
By davydnorris
#84744
ErcanCelen wrote:
davydnorris wrote:If you are going to set up the ESP with a REST API, you would be better off flashing your own program into it and using Arduino or the RTOS SDK (or indeed MicroPython or Lua or any of the programming envionments). Then you have much more control over what is happening.

The AT firmware you are using is really for basic control of the device as a wifi module - it's not really designed for what you want.


So you telling me, there is now way to achieve this data with AT commands. What a pity, I did really not get in ESP through that way.
Are you really sure? may be there is a way? And thank you for your response :)


If you haven't already found this, here's the ESP8266 AT command set:
https://www.espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_en.pdf

As you can see, there is nothing built in that provides any REST API - you would have to issue commands to connect the ESP, start a server listening on a port, wait to catch any incoming data, parse and resolve the raw data into your API call, decide how to respond and then send the data back. All of that would have to be done by some other device connected to the ESP via the UART and talking to it using AT commands.

You would be much better off programming the ESP to do it all, which would not be very difficult using Arduino or something like that.