28 #include <FlowScanner.h>
37 static const uint8_t
CS_PIN = 10;
43 static const uint8_t MAX_CLIENTS = 2;
48 static const uint8_t ACTION_DIGITALREAD = 1;
49 static const uint8_t ACTION_ANALOGREAD = 2;
53 ACTRACE(
"Requested URL:%s", queryString);
61 write(F(
"Use a GET request"));
67 if (strcmp_P(queryString, PSTR(
"/")) == 0)
72 String title(F(
"Arduino Pin Monitor"));
74 write(F(
"<html><head><title>%</title></head><body><h1>%</h1><h2>Select pin to monitor:</h2><h3>digital</h3><ul>"), &title, &title);
76 for (uint8_t pin = 2; pin < 13; pin++)
79 write(F(
"<li><a href=\"/digitalRead/%\">Pin %</a></li>"), &pinStr, &pinStr);
82 write(F(
"</ul><h3>Analog</h3><ul>"));
84 for (uint8_t pin = A0; pin <= A7; pin++)
87 String APinStr(pin - A0);
88 write(F(
"<li><a href=\"/analogRead/%\">Pin A%</a></li>"), &pinStr, &APinStr);
91 write(F(
"</ul></html>"));
96 if (strcmp_P(queryString, PSTR(
"/favicon.ico")) == 0)
106 p = strtok(queryString,
"/");
111 if (strcmp_P(p, PSTR(
"digitalRead")) == 0)
112 action = ACTION_DIGITALREAD;
115 if (strcmp_P(p, PSTR(
"analogRead")) == 0)
116 action = ACTION_ANALOGREAD;
122 p = strtok(NULL,
"/");
132 uint16_t val = (action == ACTION_ANALOGREAD) ? analogRead(pin) : digitalRead(pin);
135 write(F(
"<html><head><meta http-equiv=\"refresh\" content=\"10\" /></head><body><h1>pin%=%</h1></body></html>"), &strPin, &strVal);
141 write(F(
"<html><body><h1>404 not found!</h1></body></html>"));
152 ACTRACE(
"HTTP Header: %s = '%s'", headerName, headerValue);
157 ACTRACE(
"onBodyBegin: Content-Length = %d", contentLength);
162 ACTRACE(
"Request ended");
178 Serial.begin(115200);
180 #ifdef ACROSS_ARDUINO
181 ACross::printf_serial_init();
184 printf(PSTR(
"Multiple client HTTP Server EtherDune sample\n"));
185 Serial.print(F(
"Free RAM: ")); Serial.println(ACross::getFreeRam());
186 printf(PSTR(
"Press any key to start...\n"));
188 while (!Serial.available());
196 ACERROR(
"failed to start EtherDune");
198 ACINFO(
"waiting for link...");
202 ACINFO(
"link is up");
207 Serial.print(
"HTTP Server listening on ");
static const char HTTP_RESPONSE_METHOD_NOT_ALLOWED_STR[]
nint16_t localPort
local TCP or UDP port
void writeHeader(const String &headerName, const String &headerValue)
Writes an HTTP header to the ongoing response stream.
void beginResponse(uint16_t statusCode, const String &message="")
Sends out the response line, e.g.
void listen(uint16_t port)
Starts to listen on the specified TCP port.
#define IPAddress_P
helper macro to store an IP address in PROGMEM
virtual void onBodyBegin()
Called when all HTTP headers have been received and the body of the request is about to arrive...
uint16_t write(uint16_t len, const byte *data)
In the case of TCP, writes the given data buffer to the socket.
static IPAddress_P gatewayIP
void beginResponse_P(uint16_t statusCode, PGM_P message)
Sends out the response line, e.g.
static const uint8_t HTTP_METHOD_GET
static bool begin(uint8_t cspin)
Initializes EtherDune and the underlying hardware
static const char HTTP_RESPONSE_FOUND_STR[]
static IPAddress netmask
Subnet mask.
static IPAddress gatewayIP
IP address of the gateway in this network.
static const uint8_t CS_PIN
virtual void onHeaderReceived(const char *headerName, const char *headerValue)
Called once for each header in the request, as they arrive.
static const uint16_t HTTP_RESPONSE_FOUND
This response code means that URI of requested resource has been changed temporarily.
void beginResponseBody()
Indicates to the client that all headers have been written and that the response body follows...
static MACAddress_P mymac
static const char HTTP_RESPONSE_NOT_FOUND_STR[]
Maintains a list of available sockets, also listening and spawning sockets to serve multiple clients ...
static bool isLinkUp()
Determines whether the network link is ready
static const uint16_t HTTP_RESPONSE_OK
The request has succeeded.
void writeContentTypeHeader_P(PGM_P contentType)
Convenient function to write the Content-Type header.
static const char HTTP_RESPONSE_OK_STR[]
static MACAddress localMAC
Ethernet MAC address.
Base data structures for Internet communication.
Provides an easy way to build a web server.
virtual void onRequestEnd()
Called after all the body has been received
void endResponse()
Ends the connection and finalizes the response.
static const uint16_t HTTP_RESPONSE_NOT_FOUND
Server can not find requested resource.
static void loop()
Gives processing time to EtherDune so that it can check for incoming packets or send queued packets...
virtual void onRequest(char *queryString)
Called immediately after the first line that contains the HTTP method and query string is received ...
static IPAddress localIP
IP address of this application.
static const uint16_t HTTP_RESPONSE_METHOD_NOT_ALLOWED
The request method is known by the server but has been disabled and cannot be used.
static IPAddress_P netmask
static const char CONTENT_TYPE_TEXT_HTML[]