Coder Social home page Coder Social logo

coapserver's Introduction

This a constraint implementation of CoAP for Arduino. It can run on a Arduino UNO. Currently the CoAP server implemnt GET, PUT and partially POST (no resource creation). In the example directory, the CoAPServertestlib shows an example of a server using CoAP. A photoresistor in pin A0 increment the value nbFlash after a blink has been detect. The CoAP server is used to propagate this value.

CoAPServer.h constaints the define used in the program and the structure definitions:

  • DUMP_COAP when defined makes the program sending some debuging info on the Serial link. To gain space it is recommended not to use it
  • COAP_SERVER_ETHERNET when defined also the servur to run on the Ethernet port. Currently this value is not used, but in the furtur COAP_SERVER_WIFI and COAP_SERVER_I2C will be used to allow communication on other media.
  • MAX_OBSERVE specifies how many simultaneous Observe can be processed by the server, the more are defined, the more memory it will take. By default the value is 2
  • URI_LENGTH specifies the size of the URI path the server can process. By default the size is 20 characters including /.

An EthernetUdp handler is created as usual on port 5683 (default port for CoAP). When the Udp object handler is created, a CoAP server object (CS) is initialized with this handler throught the begin method.

Resources are then associated with this server. In the example a resource for the /flash resource is created through the addRes method. This method has 3 syntax:

  • addRes(String, function_get)
  • addRes(String, function_put)
  • addRes(String, function_get, function_put)

String contains the resource name, function_get and function_put are two functions called when the CoAP server will receive a request on that resource. Note that if function_get is not defined, then the server will answer a error message when a get request is received, same thing for the put. The method return an handler on the resource. It will be useful in the rest of the program to identify the resource whitout string comparison.

Function_get has the following syntax:

String function_get (CoAPResource* res, uint8_t format)

res is the handler of the resource and format is the MIME type in CoAP representation (COAP_FORMAT_TEXT, COAP_FORMAT_XML and COAP_FORMAT_JSON are currently defined, but other values can be used as well). This function returns a string which will be sent to the client.

Function_put has the following syntax:

uint8_t function_put (CoAPResource res, uint8_t format, uint8_t method, String input)

The first two parameters are the same as function_get, method allows to distinguish between PUT and POST. The current library does not allow dynamic resource creation, but two behaviors can be defined. In this example a POST will set the flash counter to 0 and PUT will set it to a specific value.

In the loop the method incoming has to be called. This method returns after processing requests, it also manage periodic sending of observe messages.

coapserver's People

Contributors

ltn22 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.