27 #include <FlowScanner.h>
35 static const uint8_t
CS_PIN = 10;
44 static const uint8_t ACTION_DIGITALREAD = 1;
45 static const uint8_t ACTION_ANALOGREAD = 2;
49 ACTRACE(
"Requested URL:%s", queryString);
57 write(F(
"Use a GET request"));
63 if (strcmp_P(queryString, PSTR(
"/")) == 0)
68 String title(F(
"Arduino Pin Monitor"));
70 write(F(
"<html><head><title>%</title></head><body><h1>%</h1><h2>Select pin to monitor:</h2><h3>digital</h3><ul>"), &title, &title);
72 for (uint8_t pin = 2; pin < 13; pin++)
75 write(F(
"<li><a href=\"/digitalRead/%\">Pin %</a></li>"), &pinStr, &pinStr);
78 write(F(
"</ul><h3>Analog</h3><ul>"));
80 for (uint8_t pin = A0; pin <= A7; pin++)
83 String APinStr(pin - A0);
84 write(F(
"<li><a href=\"/analogRead/%\">Pin A%</a></li>"), &pinStr, &APinStr);
87 write(F(
"</ul></html>"));
92 if (strcmp_P(queryString, PSTR(
"/favicon.ico")) == 0)
102 p = strtok(queryString,
"/");
107 if (strcmp_P(p, PSTR(
"digitalRead")) == 0)
108 action = ACTION_DIGITALREAD;
111 if (strcmp_P(p, PSTR(
"analogRead")) == 0)
112 action = ACTION_ANALOGREAD;
118 p = strtok(NULL,
"/");
128 uint16_t val = (action == ACTION_ANALOGREAD) ? analogRead(pin) : digitalRead(pin);
131 write(F(
"<html><head><meta http-equiv=\"refresh\" content=\"10\" /></head><body><h1>pin%=%</h1></body></html>"), &strPin, &strVal);
137 write(F(
"<html><body><h1>404 not found!</h1></body></html>"));
148 ACTRACE(
"HTTP Header: %s = '%s'", headerName, headerValue);
153 ACTRACE(
"onBodyBegin: Content-Length = %d", contentLength);
158 ACTRACE(
"Request ended");
163 ACTRACE(
"Listening again");
177 Serial.begin(115200);
179 #ifdef ACROSS_ARDUINO
180 ACross::printf_serial_init();
183 printf(PSTR(
"HTTP Server EtherDune sample\n"));
184 Serial.print(F(
"Free RAM: ")); Serial.println(ACross::getFreeRam());
185 printf(PSTR(
"Press any key to start...\n"));
187 while (!Serial.available());
195 ACERROR(
"failed to start EtherDune");
197 ACINFO(
"waiting for link...");
201 ACINFO(
"link is up");
206 Serial.print(
"HTTP Server listening on ");
209 Serial.println(server.localPort);
static const char HTTP_RESPONSE_METHOD_NOT_ALLOWED_STR[]
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.
#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 listen()
Starts listening on the local port indicated by the localPort property.
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[]
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 ...
virtual void onTerminate()
Called when the socket is ready to be reused.
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[]