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

User avatar
By Andy7
#95653 There are lots and lots of code examples of how to respond to an HTTP get request from a client and sending back a web page using the Arduino library. However, I'm developing on an Atmega16 in MPLab and finding it a little tough figuring this out. Hence the resort to the newbie forum!

I've managed to retrieve the NTP time code from first principles using the really nice, compact mini library from:
https://www.electronicwings.com/avr-atm ... 266-module
This works REALLY nicely with a little tweaking through any of the UARTs and brings the input in under interrupt into a circular buffer. I'd highly recommend looking at this if you want to interface with the ESP8266 with minimal code.

So, what's happening for me is that I'm able to detect an incoming HTTP request on the board (I only have 2 leds to indicate what's going on for most of the time!)
I'm trying to send back the HTML response with all the correct response 200, mimetype etc headers that I see in all the tutorials but the web browser doesn't get any data back.

I think this is because I'm not sending the data back to the CLIENT (web browser on my laptop, firefox with debug tools) properly... I'm not even sure how to do that. I presume that its going to be a straightforward CIPSEND, but do I need to specifically connect to the client first with CIPSTART? If so, how do I get the client's IP address?

The code is in a bit of a state as I'm hacking blindly about at the moment but here's a ROUGH SUMMARY of the important bits:

Code: Select allESP8266_WIFIMode(STATION);
     
ESP8266_ConnectionMode(MULTIPLE); // CIPMUX=1
ESP8266_ApplicationMode(NORMAL);

  // Kill old server and connection.
  if (!SendATandExpectResponse("AT+CIPSERVER=0", "\r\nOK\r\n")) flashError(3);
   
  // Connect to the access point (Wifi Router)   
  if(ESP8266_connected() == ESP8266_NOT_CONNECTED_TO_AP){
        connectionState=false;
       returnCode = ESP8266_JoinAccessPoint(SSID, PASSWORD);

        switch (returnCode){
            case ESP8266_WIFI_CONNECTED:
                connectionState = true;               
                break;       
             // omitted for brevity  the post. Deal with various error stated                   
        }
    }
   
    // If connection okay then carry on.
    if (connectionState==true){
        _delay_ms(400);

        if (!SendATandExpectResponse("AT+CWDHCP_CUR=1,1", "\r\nOK\r\n")) flashError(1);
        if (!SendATandExpectResponse("AT+MDNS=1,\"ESP8266\",\"http\",80", "\r\nOK\r\n")) flashError(2);
               
        // Create a TCP server
        if (!SendATandExpectResponse("AT+CIPSERVER=1,80", "\r\nOK\r\n")) flashError(3);
       
        while(1){
          ESP8266_Clear();    // Clear input buffer, ready to receive packet.
          int id=0;
          if (WaitForExpectedResponse("\n")){
          _delay_ms(1000); // We get here when we go to the IP address of the device in a browser.

   // Send response and some HTML.
          if (ESP8266_Send("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n",id)!=ESP8266_RESPONSE_FINISHED) flashError(1);
          if (ESP8266_Send("<!DOCTYPE html><html>
   :
   Html here omitted for brevity.
   :
   </html>\n",id)!=ESP8266_RESPONSE_FINISHED) flashError(1);

          ESP8266_Close();  // CIPCLOSE=1
     
          _delay_ms(400);
       

        }


So, to the crux of my question: Does anyone know of any good NON ARDUINO tutorials or help with setting up a simple web server? (C please!) I've had a bash at reverse engineering the libraries but it's rather obfuscated to say the least!

I'll come back and post my solution once I've got this working.

Thanks folks!
User avatar
By Andy7
#95665 (Note, this is effecfively a re-post of my earlier one from 17-Dec. It was caught up in moderator land but I thought I'd messed up the post and had to try to remember what I'd written and post again, then they both turned up) Ugh. Note to self: Trust the modeators, they'll get there in the end. :D
User avatar
By keble6
#95669 I sympathise - I too am using a not-Arduino controller (a microbit). I think both of us need a high level flow chart of how-to-do-things with ESP8266.
I haven't found it yet, but it must exist (surely?). I have found lists of the AT commands and rather brief descriptions of their parameters. But I'd really like to see more details and what-if comments.
For example, I really don't understand how CIPSTART, CIPSEND and CIPCLOSE work together when sending a GET command. That's what I'd like to see, not the Arduino code.
If I find the appropriate stuff I'll post here!