From 2fd23f99edcc814b496bc6c4503ccf5490397ad7 Mon Sep 17 00:00:00 2001 From: Harald Pichler Date: Tue, 20 Sep 2016 21:49:52 +0200 Subject: [PATCH] config as hostnode, add coap client --- examples/osd/triggerbaord/project-conf.h | 3 ++ examples/osd/triggerbaord/sketch.pde | 35 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/examples/osd/triggerbaord/project-conf.h b/examples/osd/triggerbaord/project-conf.h index 62e1d8d2b..230f9ba0b 100644 --- a/examples/osd/triggerbaord/project-conf.h +++ b/examples/osd/triggerbaord/project-conf.h @@ -38,6 +38,9 @@ #define LOOP_INTERVAL (10 * CLOCK_SECOND) +/* Seeping nodes are host nodes without routing features */ +#define UIP_CONF_ROUTER 0 + /* For Debug: Dont allow MCU sleeping between channel checks */ //#undef RDC_CONF_MCU_SLEEP //#define RDC_CONF_MCU_SLEEP 0 diff --git a/examples/osd/triggerbaord/sketch.pde b/examples/osd/triggerbaord/sketch.pde index 0c4845d5b..9c7ce0709 100755 --- a/examples/osd/triggerbaord/sketch.pde +++ b/examples/osd/triggerbaord/sketch.pde @@ -13,6 +13,7 @@ extern "C" { #include "arduino-process.h" #include "rest-engine.h" +#include "er-coap-engine.h" #include "net/netstack.h" #include "dev/button-sensor.h" @@ -31,6 +32,17 @@ uint8_t bled_pin=7; uint8_t bled_status; } +#define REMOTE_PORT UIP_HTONS(COAP_DEFAULT_PORT) +// should be the same :-) +#define UIP_NTOHS(x) UIP_HTONS(x) +#define SERVER_NODE(ip) \ + uip_ip6addr(ip,0xfe80,0,0,0,0,0,0,0x01) + +uip_ipaddr_t server_ipaddr, tmp_addr; +char server_resource [20] = "button"; + +extern int32_t event_counter; + void setup (void) { // switch off the led @@ -45,6 +57,7 @@ void setup (void) SENSORS_ACTIVATE(button_sensor); // init coap resourcen rest_init_engine (); + SERVER_NODE (&server_ipaddr); #pragma GCC diagnostic ignored "-Wwrite-strings" rest_activate_resource (&res_led, "s/led"); rest_activate_resource (&res_bled, "s/bled"); @@ -53,9 +66,31 @@ void setup (void) rest_activate_resource(&res_event, "s/button"); #pragma GCC diagnostic pop +// mcu_sleep_set(64); NETSTACK_MAC.off(1); } +int coap_server_post(void) +{ + static coap_packet_t request [1]; /* Array: treat as pointer */ + char buf [9]; + coap_transaction_t *transaction; + int buttonstate = button_sensor.value(0); + sprintf (buf, "state=%d&event=%lu",buttonstate,event_counter); +// printf ("%s\n", buf); + coap_init_message (request, COAP_TYPE_NON, COAP_PUT, 0); + coap_set_header_uri_path (request, server_resource); + coap_set_header_content_format (request, REST.type.TEXT_PLAIN); + coap_set_payload (request, buf, strlen (buf)); + request->mid = coap_get_mid (); + transaction = coap_new_transaction + (request->mid, &server_ipaddr, REMOTE_PORT); + transaction->packet_len = coap_serialize_message + (request, transaction->packet); + coap_send_transaction (transaction); + return 0; +} + void loop (void) {