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:
ESP8266_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!