-->
Page 1 of 1

Simple HTTP response on AtMega16 *NON ARDUINO*

PostPosted: Sat Dec 17, 2022 4:30 pm
by Andy7
Okay, hitting the noob forum now as I'm just going around in circles and need some advice from the wise ones!
I've built a little board with an AtMega16 on it and a cheapo ESP8622.
I'd like to send it some commands by HTTP requests and also have it return a little web content.

Trouble is that almost EVERY example I've found of a simple web server is in Arduino library, which of course I'm not using - I'm workign in MPLab X. I want to be able to do everything directly by AT commands and incoming data in an interrupt driven buffer filler from the USART.

I've been able to get the NTP time already using the really handy little library-ette from:
https://www.electronicwings.com/avr-atm ... 266-module

... neat little bit of code! Works very nicely.

So, in my server code, I can detect an incoming request but sending out the html seems to go out into the void. I think it's because I'm not connecting to the CLIENT? Do I need to establsh a connection to the client by IP like AT+CIPSTART before sending? If so how do I get the IP of the client?

My code's in a bit of a state, so here's a rough summary of what I'm doing after establishing a connection to the router:

ESP8255_Send is a simple AT+CIPSEND and because I'm in MUX mode I send an ID of 0 before the length..

Code: Select all        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);
        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>
:
some html here... yadda yadda
:
",id)!=ESP8266_RESPONSE_FINISHED) flashError(1);
        if (ESP8266_Send("</body></html>\n",id)!=ESP8266_RESPONSE_FINISHED) flashError(1);

        ESP8266_Close(); // AT+CIPCLOSE=1
   }


Does anyone have a non-arduino solution to returning simple web content or pointers to some examples? Honestly, it's ALL Arduiono out there!!!

Much obliged!

Re: Simple HTTP response on AtMega16 *NON ARDUINO*

PostPosted: Mon Jan 30, 2023 4:40 am
by rooppoorali
You can use Raspberry pi instead. You can run a python script in Raspberry pi. You have to make a web crawler. That will return your desired web content. You have to use the python 'requests' module.

Re: Simple HTTP response on AtMega16 *NON ARDUINO*

PostPosted: Tue May 09, 2023 3:18 pm
by dpat99
I have the same dilemma. I ended up as rooppoorali mentions to use raspberry pi. It works quite well.