Kategorier
Arduino Hemmakodat

EasyWebServer–A lightweight web server for Arduino

This is a library for Arduino that implements a very basic web server.  There are many web servers out there, but the purpose of this library is to be easy to handle.

The basic Webserver example in the Arduino Ethernet library will get you started, but it does not handle different URLs. The web server will send back the same HTML response regardless if what address you specify in the browser.

This web server will help you implement multiple URLs, or ”pages”.

Here is a quick example:

  • The setup() is not different from the basic Arduio web server. Use the normal Ethernet functions to establish a TCP server listening on port 80.
  • The web server is declared after a EthernetCient has been detected. The constructor (line 35) will read the HTTP request and parse the verb, URL and querystring.
  • The serveUrl function will test a URL, and if it is matched it will:
    • Write the HTTP Response Headers.
    • Execute “your” code to write the HTML page (second parameter is a function pointer).
    • Disconnect the client (terminate the TCP session).
  • If none of the URLs where matched, the deconstructor will send back a 404 Not Found message to the client. This will happened when the EasyWebServer object goes out of scope on line 39.

image

Download the EasyWebServer library from Github:

https://github.com/llelundberg/EasyWebServer/

 

 

 

Lämna ett svar

Din e-postadress kommer inte publiceras. Obligatoriska fält är märkta *