uHTTP() - nomadnt-iot/uHTTP GitHub Wiki

uHTTP()

Description

Create a HTTP server that listens on the specified port.

Syntax

uHTTP(port);

Parameters

port: the port to listen on (uint16_t)

Returns

None

Example

#include <SPI.h>
#include <Ethernet.h>
#include <uHTTP.h>

byte macaddr[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
byte ip4addr[4] = {192, 168, 0, 254};

uHTTP server = uHTTP(80);

void setup(){
    Ethernet.begin(macaddr, ip4addr);

    Serial.print(F("Starting uHTTP at "));
    Serial.print(Ethernet.localIP());
    Serial.println(":80");

    server.begin();
}

void loop(){
    EthernetClient response = server.available();
    if(response){
        response.println("HTTP/1.1 200 OK");
        response.println("Content-Type: text/plain");
        response.println();
        response.println("Hello World!");
        response.stop();
    }
}
⚠️ **GitHub.com Fallback** ⚠️