initial upload
This commit is contained in:
parent
801316badc
commit
df220072f4
2
examples/osd/arduino-merkurboard/arduino-example.c
Normal file
2
examples/osd/arduino-merkurboard/arduino-example.c
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include <arduino-process.h>
|
||||
AUTOSTART_PROCESSES(&arduino_sketch);
|
82
examples/osd/arduino-merkurboard/resources/res-door.c
Normal file
82
examples/osd/arduino-merkurboard/resources/res-door.c
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Door resource
|
||||
* \author
|
||||
* Harald Pichler <harald@the-develop.net>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
#include <string.h>
|
||||
#include "rest-engine.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
|
||||
|
||||
/* A simple getter example. Returns the reading from the sensor with a simple etag */
|
||||
RESOURCE(res_door,
|
||||
"title=\"Moisture status\";rt=\"Moisture\"",
|
||||
res_get_handler,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
extern uint8_t door_pin;
|
||||
extern uint8_t door_status;
|
||||
|
||||
static void
|
||||
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
|
||||
door_status = digitalRead(door_pin);
|
||||
|
||||
unsigned int accept = -1;
|
||||
REST.get_header_accept(request, &accept);
|
||||
|
||||
if(accept == -1 || accept == REST.type.TEXT_PLAIN) {
|
||||
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d", door_status);
|
||||
|
||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
||||
} else if(accept == REST.type.APPLICATION_JSON) {
|
||||
REST.set_header_content_type(response, REST.type.APPLICATION_JSON);
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'door':%d}", door_status);
|
||||
|
||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
||||
} else {
|
||||
REST.set_response_status(response, REST.status.NOT_ACCEPTABLE);
|
||||
const char *msg = "Supporting content-types text/plain and application/json";
|
||||
REST.set_response_payload(response, msg, strlen(msg));
|
||||
}
|
||||
}
|
37
examples/osd/arduino-merkurboard/sketch.pde
Normal file
37
examples/osd/arduino-merkurboard/sketch.pde
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Sample arduino sketch using contiki features.
|
||||
* We turn the LED off
|
||||
* We allow read the moisture sensor
|
||||
* Unfortunately sleeping for long times in loop() isn't currently
|
||||
* possible, something turns off the CPU (including PWM outputs) if a
|
||||
* Proto-Thread is taking too long. We need to find out how to sleep in
|
||||
* a Contiki-compatible way.
|
||||
* Note that for a normal arduino sketch you won't have to include any
|
||||
* of the contiki-specific files here, the sketch should just work.
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
#include "rest-engine.h"
|
||||
|
||||
extern resource_t res_door, res_battery;
|
||||
uint8_t door_pin = 3;
|
||||
uint8_t door_status = 0;
|
||||
|
||||
#define LED_PIN 4
|
||||
}
|
||||
|
||||
void setup (void)
|
||||
{
|
||||
// switch off the led
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
// init coap resourcen
|
||||
rest_init_engine ();
|
||||
rest_activate_resource (&res_door, "s/door");
|
||||
rest_activate_resource (&res_battery, "s/battery");
|
||||
}
|
||||
|
||||
void loop (void)
|
||||
{
|
||||
|
||||
}
|
76
examples/osd/merkurboard/README
Normal file
76
examples/osd/merkurboard/README
Normal file
|
@ -0,0 +1,76 @@
|
|||
A Quick Introduction to the Erbium (Er) REST Engine
|
||||
===================================================
|
||||
Compile the Example
|
||||
-------------------
|
||||
./run.sh
|
||||
|
||||
OSD-Merkur Board
|
||||
----------------------
|
||||
write the images to the OSD-Merkur Board:
|
||||
|
||||
./flash.sh
|
||||
|
||||
EXAMPLE FILES
|
||||
-------------
|
||||
er-example-server.c: A RESTful server example showing how to use the REST layer to develop server-side applications (at the moment only CoAP is implemented for the REST Engine).
|
||||
er-example-client.c: A CoAP client that polls the /actuators/toggle resource every 10 seconds and cycles through 4 resources on button press (target address is hard-coded).
|
||||
er-plugtest-server.c: The server used for draft compliance testing at ETSI IoT CoAP Plugtest in Paris, France, March 2012 (configured for minimal-net).
|
||||
|
||||
PRELIMINARIES
|
||||
-------------
|
||||
- Make sure rpl-border-router has the same stack and fits into mote memory:
|
||||
You can disable RDC in border-router project-conf.h (not really required as BR keeps radio turned on).
|
||||
#undef NETSTACK_CONF_RDC
|
||||
#define NETSTACK_CONF_RDC nullrdc_driver
|
||||
- For convenience, define the Cooja addresses in /etc/hosts
|
||||
aaaa::0212:7401:0001:0101 cooja1
|
||||
aaaa::0212:7402:0002:0202 cooja2
|
||||
...
|
||||
- Get the Copper (Cu) CoAP user-agent from https://addons.mozilla.org/en-US/firefox/addon/copper-270430/
|
||||
- Optional: Save your target as default target
|
||||
$ make TARGET=sky savetarget
|
||||
|
||||
COOJA HOWTO
|
||||
-----------
|
||||
Server only:
|
||||
1) $ make TARGET=cooja server-only.csc
|
||||
2) Open new terminal
|
||||
3) $ make connect-router-cooja
|
||||
4) Start Copper and discover resources at coap://cooja2:5683/
|
||||
- Choose "Click button on Sky 2" from the context menu of mote 2 (server) after requesting /test/separate
|
||||
- Do the same when observing /test/event
|
||||
|
||||
With client:
|
||||
1) $ make TARGET=cooja server-client.csc
|
||||
2) Open new terminal
|
||||
3) $ make connect-router-cooja
|
||||
4) Wait until red LED toggles on mote 2 (server)
|
||||
5) Choose "Click button on Sky 3" from the context menu of mote 3 (client) and watch serial output
|
||||
|
||||
DETAILS
|
||||
-------
|
||||
Erbium currently implements draft 08 (name "er-coap-07" stems from last technical draft changes).
|
||||
Central features are commented in er-example-server.c.
|
||||
In general, apps/er-coap-07 supports:
|
||||
* All draft 08 header options
|
||||
* CON Retransmissions (note COAP_MAX_OPEN_TRANSACTIONS)
|
||||
* Blockwise Transfers (note REST_MAX_CHUNK_SIZE, see er-plugtest-server.c for Block1 uploads)
|
||||
* Separate Responses (no rest_set_pre_handler() required anymore, note coap_separate_accept(), _reject(), and _resume())
|
||||
* Resource Discovery
|
||||
* Observing Resources (see EVENT_ and PRERIODIC_RESOURCE, note COAP_MAX_OBSERVERS)
|
||||
|
||||
REST IMPLEMENTATIONS
|
||||
--------------------
|
||||
The Makefile uses WITH_COAP to configure different implementations for the Erbium (Er) REST Engine.
|
||||
* WITH_COAP=7 uses Erbium CoAP 08 apps/er-coap-07/.
|
||||
The default port for coap-07/-08 is 5683.
|
||||
* WITH_COAP=3 uses Erbium CoAP 03 apps/er-coap-03/.
|
||||
The default port for coap-03 is 61616.
|
||||
er-coap-03 produces some warnings, as it not fully maintained anymore.
|
||||
* WITH_COAP=0 is a stub to link an Erbium HTTP engine that uses the same resource abstraction (REST.x() functions and RESOURCE macros.
|
||||
|
||||
TODOs
|
||||
-----
|
||||
* Observe client
|
||||
* Multiple If-Match ETags
|
||||
* (Message deduplication)
|
149
examples/osd/merkurboard/README.md
Normal file
149
examples/osd/merkurboard/README.md
Normal file
|
@ -0,0 +1,149 @@
|
|||
A Quick Introduction to the Erbium (Er) REST Engine
|
||||
===================================================
|
||||
|
||||
EXAMPLE FILES
|
||||
-------------
|
||||
|
||||
- er-example-server.c: A RESTful server example showing how to use the REST
|
||||
layer to develop server-side applications (at the moment only CoAP is
|
||||
implemented for the REST Engine).
|
||||
- er-example-client.c: A CoAP client that polls the /actuators/toggle resource
|
||||
every 10 seconds and cycles through 4 resources on button press (target
|
||||
address is hard-coded).
|
||||
- er-plugtest-server.c: The server used for draft compliance testing at ETSI
|
||||
IoT CoAP Plugtests. Erbium (Er) participated in Paris, France, March 2012 and
|
||||
Sophia-Antipolis, France, November 2012 (configured for minimal-net).
|
||||
|
||||
PRELIMINARIES
|
||||
-------------
|
||||
|
||||
- Make sure rpl-border-router has the same stack and fits into mote memory:
|
||||
You can disable RDC in border-router project-conf.h (not really required as BR keeps radio turned on).
|
||||
#undef NETSTACK_CONF_RDC
|
||||
#define NETSTACK_CONF_RDC nullrdc_driver
|
||||
- Alternatively, you can use the native-border-router together with the slip-radio.
|
||||
- For convenience, define the Cooja addresses in /etc/hosts
|
||||
aaaa::0212:7401:0001:0101 cooja1
|
||||
aaaa::0212:7402:0002:0202 cooja2
|
||||
...
|
||||
- Get the Copper (Cu) CoAP user-agent from
|
||||
[https://addons.mozilla.org/en-US/firefox/addon/copper-270430](https://addons.mozilla.org/en-US/firefox/addon/copper-270430)
|
||||
- Optional: Save your target as default target
|
||||
make TARGET=sky savetarget
|
||||
|
||||
COOJA HOWTO
|
||||
-----------
|
||||
|
||||
###Server only:
|
||||
|
||||
make TARGET=cooja server-only.csc
|
||||
|
||||
Open new terminal
|
||||
|
||||
make connect-router-cooja
|
||||
|
||||
- Start Copper and discover resources at coap://cooja2:5683/
|
||||
- Choose "Click button on Sky 2" from the context menu of mote 2 (server) after
|
||||
requesting /test/separate
|
||||
- Do the same when observing /test/event
|
||||
|
||||
###With client:
|
||||
|
||||
make TARGET=cooja server-client.csc
|
||||
|
||||
Open new terminal
|
||||
|
||||
make connect-router-cooja
|
||||
|
||||
- Wait until red LED toggles on mote 2 (server)
|
||||
- Choose "Click button on Sky 3" from the context menu of mote 3 (client) and
|
||||
watch serial output
|
||||
|
||||
TMOTES HOWTO
|
||||
------------
|
||||
|
||||
###Server:
|
||||
|
||||
1. Connect two Tmote Skys (check with $ make TARGET=sky sky-motelist)
|
||||
|
||||
make TARGET=sky er-example-server.upload MOTE=2
|
||||
make TARGET=sky login MOTE=2
|
||||
|
||||
2. Press reset button, get address, abort with Ctrl+C:
|
||||
Line: "Tentative link-local IPv6 address fe80:0000:0000:0000:____:____:____:____"
|
||||
|
||||
cd ../ipv6/rpl-border-router/
|
||||
make TARGET=sky border-router.upload MOTE=1
|
||||
make connect-router
|
||||
|
||||
For a BR tty other than USB0:
|
||||
|
||||
make connect-router-port PORT=X
|
||||
|
||||
3. Start Copper and discover resources at:
|
||||
|
||||
coap://[aaaa::____:____:____:____]:5683/
|
||||
|
||||
### Add a client:
|
||||
|
||||
1. Change the hard-coded server address in er-example-client.c to aaaa::____:____:____:____
|
||||
2. Connect a third Tmote Sky
|
||||
|
||||
make TARGET=sky er-example-client.upload MOTE=3
|
||||
|
||||
MINIMAL-NET HOWTO
|
||||
-----------------
|
||||
|
||||
With the target minimal-net you can test your CoAP applications without
|
||||
constraints, i.e., with large buffers, debug output, memory protection, etc.
|
||||
The er-plugtest-server is thought for the minimal-net platform, as it requires
|
||||
an 1280-byte IP buffer and 1024-byte blocks.
|
||||
|
||||
make TARGET=minimal-net er-plugtest-server
|
||||
sudo ./er-plugtest-server.minimal-net
|
||||
|
||||
Open new terminal
|
||||
|
||||
make connect-minimal
|
||||
|
||||
- Start Copper and discover resources at coap://[fdfd::ff:fe00:10]:5683/
|
||||
- You can enable the ETSI Plugtest menu in Copper's preferences
|
||||
|
||||
Under Windows/Cygwin, WPCAP might need a patch in
|
||||
<cygwin>\usr\include\w32api\in6addr.h:
|
||||
|
||||
21,23c21
|
||||
< #ifdef __INSIDE_CYGWIN__
|
||||
< uint32_t __s6_addr32[4];
|
||||
< #endif
|
||||
---
|
||||
> u_int __s6_addr32[4];
|
||||
36d33
|
||||
< #ifdef __INSIDE_CYGWIN__
|
||||
39d35
|
||||
< #endif
|
||||
|
||||
DETAILS
|
||||
-------
|
||||
|
||||
Erbium implements the Proposed Standard of CoAP. Central features are commented
|
||||
in er-example-server.c. In general, apps/er-coap supports:
|
||||
|
||||
- All draft-18 header options
|
||||
- CON Retransmissions (note COAP_MAX_OPEN_TRANSACTIONS)
|
||||
- Blockwise Transfers (note REST_MAX_CHUNK_SIZE, see er-plugtest-server.c for
|
||||
Block1 uploads)
|
||||
- Separate Responses (no rest_set_pre_handler() required anymore, note
|
||||
coap_separate_accept(), _reject(), and _resume())
|
||||
- Resource Discovery
|
||||
- Observing Resources (see EVENT_ and PRERIODIC_RESOURCE, note
|
||||
COAP_MAX_OBSERVERS)
|
||||
|
||||
TODOs
|
||||
-----
|
||||
|
||||
- Dedicated Observe buffers
|
||||
- Optimize message struct variable access (directly access struct without copying)
|
||||
- Observe client
|
||||
- Multiple If-Match ETags
|
||||
- (Message deduplication)
|
Loading…
Reference in a new issue