1

I'm exploring the ESP8266 for a home automation project.

I setup a server in WiFi mode 1 using these commands:

(AT+CIPMUX=1,AT+CIPSERVER=1,80.)

I assigned a static IP for the MAC address in my router settings.

I managed to send a get request from HTML page using jQuery $get() to the ESP module. I'm only using AT commands via serial monitor.

I hooked it with Arduino and using serial monitor to send AT commands.

+IPD,0,314:GET /?pin=10000 HTTP/1.1
Host: 192.168.0.100
Connection: keep-alive
Accept: */*
User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Mobile Safari/537.36
Origin: null
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9

This is the part in the HTML page that sends this request. It is supposed to give an alert after receiving data from server:

<script>
      $(".button").click(function(){
        $.get("http://192.168.0.100:80/", {pin: 10000} , function(data, status){
    alert("Data: " + data + "\nStatus: " + status);
  });    
        });  


    </script>

I used AT+CIPSEND=clientid,length and entered the data I wanted to send

AT+CIPSEND=0,8


OK
> 

busy s...

Recv 8 bytes

SEND OK
AT+CIPCLOSE=0

0,CLOSED

OK

This error is displayed in console:

Access to XMLHttpRequest at 'http://192.168.0.100/?pin=10000' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

GET http://192.168.0.100/?pin=10000 net::ERR_FAILED

I want to send a response for the request and I'm totally new to HTTP requests.

6
  • 1
    You have to send a full valid HTTP response, including any cross-site scripting security information. Just throwing random data down an IP connection will not work. – Majenko May 24 at 10:16
  • it is not possible to send http response from Serial Monitor, because you can't enter the response lines fast enough. Arduino WiFi libraries exist for esp8266 with AT firmware – Juraj May 24 at 11:24
  • you might also run into a newer chrome restriction where 192.xxx is blocked from most domains unless https is used, but then you get a mixed zone since the ESP uses HTTP responses. – dandavis May 25 at 7:08
  • Have you tried using another browser? – sa_leinad Jun 6 at 6:05
  • Thanks @Majenko♦ it worked – user453237 Jun 7 at 13:51

Your Answer

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

Browse other questions tagged or ask your own question.