/* Copyright 2014 Greg Stein * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include "Endpoint.h" static EndpointServer *server; static uint8_t value; static void echo_handler(const EndpointResponse &response) { response.respondBytes(response.params, response.params_len); } static void set_handler(const EndpointResponse &response) { if (response.params_len != 1) { // We need/want just a single byte. response.respond400(); } else { // Got it. thanks. value = response.params[0]; response.respond204(); } } static void get_handler(const EndpointResponse &response) { response.respondBytes(&value, 1); } static void incr_handler(const EndpointResponse &response) { ++value; response.respond204(); } static void decr_handler(const EndpointResponse &response) { --value; response.respond204(); } static const EndpointHandler handlers[] = { { 'e', echo_handler, false }, { 's', set_handler, false }, { 'g', get_handler, false }, { 'i', incr_handler, false }, { 'd', decr_handler, false }, { 0 } }; void setup(void) { //Serial.begin(115200); static /*const*/ uint8_t mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x73, 0x9C }; const IPAddress ip = IPAddress(192, 168, 1, 25); Ethernet.begin(mac, ip); //Serial.println("Starting server..."); server = new EndpointServer(handlers, 8080); } void loop(void) { server->process(); }