Export RSSI to default parent in the CC26xx web demo

The current version of the CC26xx web demo publishes over MQTT the default parent's IPv6 address and the last observed RSSI of this link. This is collected by active probing (periodic ping).

This commit brings the probing functionality to the example's main code module. The MQTT client keeps publishing as previously, but we now also export the same information through CoAP resources. Configuration is still possible through the example's web server.
This commit is contained in:
Jonas Olsson 2015-08-16 17:16:16 +01:00
parent e96b15773a
commit 67045d4012
9 changed files with 280 additions and 95 deletions

View file

@ -5,7 +5,7 @@ all: cc26xx-web-demo
REST_RESOURCES_DIR = ./resources REST_RESOURCES_DIR = ./resources
REST_RESOURCES_FILES += res-leds.c res-toggle-leds.c res-device.c REST_RESOURCES_FILES += res-leds.c res-toggle-leds.c res-device.c
REST_RESOURCES_FILES += res-sensors.c res-ble-advd.c REST_RESOURCES_FILES += res-sensors.c res-ble-advd.c res-net.c
PROJECTDIRS += $(REST_RESOURCES_DIR) PROJECTDIRS += $(REST_RESOURCES_DIR)
PROJECT_SOURCEFILES += $(REST_RESOURCES_FILES) PROJECT_SOURCEFILES += $(REST_RESOURCES_FILES)

View file

@ -44,6 +44,7 @@
#include "lib/sensors.h" #include "lib/sensors.h"
#include "lib/list.h" #include "lib/list.h"
#include "sys/process.h" #include "sys/process.h"
#include "net/ipv6/sicslowpan.h"
#include "button-sensor.h" #include "button-sensor.h"
#include "batmon-sensor.h" #include "batmon-sensor.h"
#include "httpd-simple.h" #include "httpd-simple.h"
@ -77,13 +78,20 @@ struct ctimer bmp_timer, hdc_timer, tmp_timer, opt_timer, mpu_timer;
static struct etimer et; static struct etimer et;
static struct ctimer ct; static struct ctimer ct;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Parent RSSI functionality */
#if CC26XX_WEB_DEMO_READ_PARENT_RSSI
static struct uip_icmp6_echo_reply_notification echo_reply_notification;
static struct etimer echo_request_timer;
int def_rt_rssi = 0;
#endif
/*---------------------------------------------------------------------------*/
process_event_t cc26xx_web_demo_publish_event; process_event_t cc26xx_web_demo_publish_event;
process_event_t cc26xx_web_demo_config_loaded_event; process_event_t cc26xx_web_demo_config_loaded_event;
process_event_t cc26xx_web_demo_load_config_defaults; process_event_t cc26xx_web_demo_load_config_defaults;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Saved settings on flash: store, offset, magic */ /* Saved settings on flash: store, offset, magic */
#define CONFIG_FLASH_OFFSET 0 #define CONFIG_FLASH_OFFSET 0
#define CONFIG_MAGIC 0xCC265001 #define CONFIG_MAGIC 0xCC265002
cc26xx_web_demo_config_t cc26xx_web_demo_config; cc26xx_web_demo_config_t cc26xx_web_demo_config;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -374,8 +382,57 @@ sensor_readings_handler(char *key, int key_len, char *val, int val_len)
return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if CC26XX_WEB_DEMO_READ_PARENT_RSSI
static int
ping_interval_post_handler(char *key, int key_len, char *val, int val_len)
{
int rv = 0;
if(key_len != strlen("ping_interval") ||
strncasecmp(key, "ping_interval", strlen("ping_interval")) != 0) {
/* Not ours */
return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN;
}
rv = atoi(val);
if(rv < CC26XX_WEB_DEMO_RSSI_MEASURE_INTERVAL_MIN ||
rv > CC26XX_WEB_DEMO_RSSI_MEASURE_INTERVAL_MAX) {
return HTTPD_SIMPLE_POST_HANDLER_ERROR;
}
cc26xx_web_demo_config.def_rt_ping_interval = rv * CLOCK_SECOND;
return HTTPD_SIMPLE_POST_HANDLER_OK;
}
#endif
/*---------------------------------------------------------------------------*/
HTTPD_SIMPLE_POST_HANDLER(sensor, sensor_readings_handler); HTTPD_SIMPLE_POST_HANDLER(sensor, sensor_readings_handler);
HTTPD_SIMPLE_POST_HANDLER(defaults, defaults_post_handler); HTTPD_SIMPLE_POST_HANDLER(defaults, defaults_post_handler);
#if CC26XX_WEB_DEMO_READ_PARENT_RSSI
HTTPD_SIMPLE_POST_HANDLER(ping_interval, ping_interval_post_handler);
/*---------------------------------------------------------------------------*/
static void
echo_reply_handler(uip_ipaddr_t *source, uint8_t ttl, uint8_t *data,
uint16_t datalen)
{
if(uip_ip6addr_cmp(source, uip_ds6_defrt_choose())) {
def_rt_rssi = sicslowpan_get_last_rssi();
}
}
/*---------------------------------------------------------------------------*/
static void
ping_parent(void)
{
if(uip_ds6_get_global(ADDR_PREFERRED) == NULL) {
return;
}
uip_icmp6_send(uip_ds6_defrt_choose(), ICMP6_ECHO_REQUEST, 0,
CC26XX_WEB_DEMO_ECHO_REQ_PAYLOAD_LEN);
}
#endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
get_batmon_reading(void *data) get_batmon_reading(void *data)
@ -828,6 +885,8 @@ PROCESS_THREAD(cc26xx_web_demo_process, ev, data)
* own defaults and restore saved config from flash... * own defaults and restore saved config from flash...
*/ */
cc26xx_web_demo_config.sensors_bitmap = 0xFFFFFFFF; /* all on by default */ cc26xx_web_demo_config.sensors_bitmap = 0xFFFFFFFF; /* all on by default */
cc26xx_web_demo_config.def_rt_ping_interval =
CC26XX_WEB_DEMO_DEFAULT_RSSI_MEAS_INTERVAL;
load_config(); load_config();
/* /*
@ -841,6 +900,15 @@ PROCESS_THREAD(cc26xx_web_demo_process, ev, data)
httpd_simple_register_post_handler(&sensor_handler); httpd_simple_register_post_handler(&sensor_handler);
httpd_simple_register_post_handler(&defaults_handler); httpd_simple_register_post_handler(&defaults_handler);
#if CC26XX_WEB_DEMO_READ_PARENT_RSSI
httpd_simple_register_post_handler(&ping_interval_handler);
def_rt_rssi = 0x8000000;
uip_icmp6_echo_reply_callback_add(&echo_reply_notification,
echo_reply_handler);
etimer_set(&echo_request_timer, CC26XX_WEB_DEMO_NET_CONNECT_PERIODIC);
#endif
etimer_set(&et, CC26XX_WEB_DEMO_NET_CONNECT_PERIODIC); etimer_set(&et, CC26XX_WEB_DEMO_NET_CONNECT_PERIODIC);
/* /*
@ -848,6 +916,25 @@ PROCESS_THREAD(cc26xx_web_demo_process, ev, data)
* (e.g a button press / or reed trigger) * (e.g a button press / or reed trigger)
*/ */
while(1) { while(1) {
if(ev == PROCESS_EVENT_TIMER && etimer_expired(&et)) {
if(uip_ds6_get_global(ADDR_PREFERRED) == NULL) {
leds_on(CC26XX_WEB_DEMO_STATUS_LED);
ctimer_set(&ct, NO_NET_LED_DURATION, publish_led_off, NULL);
etimer_set(&et, CC26XX_WEB_DEMO_NET_CONNECT_PERIODIC);
}
}
#if CC26XX_WEB_DEMO_READ_PARENT_RSSI
if(ev == PROCESS_EVENT_TIMER && etimer_expired(&echo_request_timer)) {
if(uip_ds6_get_global(ADDR_PREFERRED) == NULL) {
etimer_set(&echo_request_timer, CC26XX_WEB_DEMO_NET_CONNECT_PERIODIC);
} else {
ping_parent();
etimer_set(&echo_request_timer, cc26xx_web_demo_config.def_rt_ping_interval);
}
}
#endif
if(ev == sensors_event && data == CC26XX_WEB_DEMO_SENSOR_READING_TRIGGER) { if(ev == sensors_event && data == CC26XX_WEB_DEMO_SENSOR_READING_TRIGGER) {
if((CC26XX_WEB_DEMO_SENSOR_READING_TRIGGER)->value( if((CC26XX_WEB_DEMO_SENSOR_READING_TRIGGER)->value(
BUTTON_SENSOR_VALUE_DURATION) > CLOCK_SECOND * 5) { BUTTON_SENSOR_VALUE_DURATION) > CLOCK_SECOND * 5) {
@ -858,12 +945,6 @@ PROCESS_THREAD(cc26xx_web_demo_process, ev, data)
process_post(PROCESS_BROADCAST, cc26xx_web_demo_publish_event, NULL); process_post(PROCESS_BROADCAST, cc26xx_web_demo_publish_event, NULL);
} }
} else if(ev == PROCESS_EVENT_TIMER && etimer_expired(&et)) {
if(uip_ds6_get_global(ADDR_PREFERRED) == NULL) {
leds_on(CC26XX_WEB_DEMO_STATUS_LED);
ctimer_set(&ct, NO_NET_LED_DURATION, publish_led_off, NULL);
etimer_set(&et, CC26XX_WEB_DEMO_NET_CONNECT_PERIODIC);
}
} else if(ev == httpd_simple_event_new_config) { } else if(ev == httpd_simple_event_new_config) {
save_config(); save_config();
#if BOARD_SENSORTAG #if BOARD_SENSORTAG

View file

@ -80,6 +80,16 @@
#define CC26XX_WEB_DEMO_NET_UART 1 #define CC26XX_WEB_DEMO_NET_UART 1
#endif #endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Active probing of RSSI from our preferred parent */
#if (CC26XX_WEB_DEMO_COAP_SERVER || CC26XX_WEB_DEMO_MQTT_CLIENT)
#define CC26XX_WEB_DEMO_READ_PARENT_RSSI 1
#else
#define CC26XX_WEB_DEMO_READ_PARENT_RSSI 0
#endif
#define CC26XX_WEB_DEMO_RSSI_MEASURE_INTERVAL_MAX 86400 /* secs: 1 day */
#define CC26XX_WEB_DEMO_RSSI_MEASURE_INTERVAL_MIN 5 /* secs */
/*---------------------------------------------------------------------------*/
/* User configuration */ /* User configuration */
/* Take a sensor reading on button press */ /* Take a sensor reading on button press */
#define CC26XX_WEB_DEMO_SENSOR_READING_TRIGGER &button_left_sensor #define CC26XX_WEB_DEMO_SENSOR_READING_TRIGGER &button_left_sensor
@ -169,6 +179,7 @@ typedef struct cc26xx_web_demo_config_s {
uint32_t magic; uint32_t magic;
int len; int len;
uint32_t sensors_bitmap; uint32_t sensors_bitmap;
int def_rt_ping_interval;
mqtt_client_config_t mqtt_config; mqtt_client_config_t mqtt_config;
net_uart_config_t net_uart; net_uart_config_t net_uart;
} cc26xx_web_demo_config_t; } cc26xx_web_demo_config_t;

View file

@ -56,6 +56,9 @@ extern resource_t res_device_hw;
extern resource_t res_device_uptime; extern resource_t res_device_uptime;
extern resource_t res_device_cfg_reset; extern resource_t res_device_cfg_reset;
extern resource_t res_parent_rssi;
extern resource_t res_parent_ip;
#if RF_BLE_ENABLED #if RF_BLE_ENABLED
extern resource_t res_ble_advd; extern resource_t res_ble_advd;
#endif #endif
@ -138,6 +141,9 @@ PROCESS_THREAD(coap_server_process, ev, data)
rest_activate_resource(&res_device_uptime, "dev/uptime"); rest_activate_resource(&res_device_uptime, "dev/uptime");
rest_activate_resource(&res_device_cfg_reset, "dev/cfg_reset"); rest_activate_resource(&res_device_cfg_reset, "dev/cfg_reset");
rest_activate_resource(&res_parent_rssi, "net/parent/RSSI");
rest_activate_resource(&res_parent_ip, "net/parent/IPv6");
#if RF_BLE_ENABLED #if RF_BLE_ENABLED
rest_activate_resource(&res_ble_advd, "dev/ble_advd"); rest_activate_resource(&res_ble_advd, "dev/ble_advd");
#endif #endif

View file

@ -93,8 +93,8 @@ static int state;
#define STRINGIFY(x) XSTR(x) #define STRINGIFY(x) XSTR(x)
#define XSTR(x) #x #define XSTR(x) #x
#define RSSI_INT_MAX STRINGIFY(MQTT_CLIENT_RSSI_MEASURE_INTERVAL_MAX) #define RSSI_INT_MAX STRINGIFY(CC26XX_WEB_DEMO_RSSI_MEASURE_INTERVAL_MAX)
#define RSSI_INT_MIN STRINGIFY(MQTT_CLIENT_RSSI_MEASURE_INTERVAL_MIN) #define RSSI_INT_MIN STRINGIFY(CC26XX_WEB_DEMO_RSSI_MEASURE_INTERVAL_MIN)
#define PUB_INT_MAX STRINGIFY(MQTT_CLIENT_PUBLISH_INTERVAL_MAX) #define PUB_INT_MAX STRINGIFY(MQTT_CLIENT_PUBLISH_INTERVAL_MAX)
#define PUB_INT_MIN STRINGIFY(MQTT_CLIENT_PUBLISH_INTERVAL_MIN) #define PUB_INT_MIN STRINGIFY(MQTT_CLIENT_PUBLISH_INTERVAL_MIN)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -568,12 +568,54 @@ PT_THREAD(generate_config(struct httpd_state *s))
s->reading->publish ? "" : " Checked", s->reading->publish ? "" : " Checked",
config_div_close)); config_div_close));
} }
PT_WAIT_THREAD(&s->generate_pt, PT_WAIT_THREAD(&s->generate_pt,
enqueue_chunk(s, 0, enqueue_chunk(s, 0,
"<input type=\"submit\" value=\"Submit\">")); "<input type=\"submit\" value=\"Submit\">"));
PT_WAIT_THREAD(&s->generate_pt, PT_WAIT_THREAD(&s->generate_pt,
enqueue_chunk(s, 0, "</form>")); enqueue_chunk(s, 0, "</form>"));
/* RSSI measurements */
#if CC26XX_WEB_DEMO_READ_PARENT_RSSI
PT_WAIT_THREAD(&s->generate_pt,
enqueue_chunk(s, 0, "<h1>RSSI Probing</h1>"));
PT_WAIT_THREAD(&s->generate_pt,
enqueue_chunk(s, 0,
"<form name=\"input\" action=\"%s\" ",
http_dev_cfg_page.filename));
PT_WAIT_THREAD(&s->generate_pt,
enqueue_chunk(s, 0, "method=\"post\" enctype=\""));
PT_WAIT_THREAD(&s->generate_pt,
enqueue_chunk(s, 0, "application/x-www-form-urlencoded\" "));
PT_WAIT_THREAD(&s->generate_pt,
enqueue_chunk(s, 0, "accept-charset=\"UTF-8\">"));
PT_WAIT_THREAD(&s->generate_pt,
enqueue_chunk(s, 0, "%sPeriod (secs):%s",
config_div_left, config_div_close));
PT_WAIT_THREAD(&s->generate_pt,
enqueue_chunk(s, 0, "%s<input type=\"number\" ",
config_div_right));
PT_WAIT_THREAD(&s->generate_pt,
enqueue_chunk(s, 0, "value=\"%lu\" ",
(clock_time_t)
(cc26xx_web_demo_config.def_rt_ping_interval
/ CLOCK_SECOND)));
PT_WAIT_THREAD(&s->generate_pt,
enqueue_chunk(s, 0,
"min=\"" RSSI_INT_MIN "\" "
"max=\"" RSSI_INT_MAX "\" "
"name=\"ping_interval\">%s",
config_div_close));
PT_WAIT_THREAD(&s->generate_pt,
enqueue_chunk(s, 0,
"<input type=\"submit\" value=\"Submit\">"));
PT_WAIT_THREAD(&s->generate_pt,
enqueue_chunk(s, 0, "</form>"));
#endif
/* Actions */ /* Actions */
PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, "<h1>Actions</h1>")); PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, "<h1>Actions</h1>"));
PT_WAIT_THREAD(&s->generate_pt, PT_WAIT_THREAD(&s->generate_pt,
@ -732,24 +774,6 @@ PT_THREAD(generate_mqtt_config(struct httpd_state *s))
"name=\"broker_port\">%s", "name=\"broker_port\">%s",
config_div_close)); config_div_close));
PT_WAIT_THREAD(&s->generate_pt,
enqueue_chunk(s, 0, "%sRSSI Interval (secs):%s",
config_div_left, config_div_close));
PT_WAIT_THREAD(&s->generate_pt,
enqueue_chunk(s, 0, "%s<input type=\"number\" ",
config_div_right));
PT_WAIT_THREAD(&s->generate_pt,
enqueue_chunk(s, 0, "value=\"%lu\" ",
(clock_time_t)
(cc26xx_web_demo_config.mqtt_config.def_rt_ping_interval
/ CLOCK_SECOND)));
PT_WAIT_THREAD(&s->generate_pt,
enqueue_chunk(s, 0,
"min=\"" RSSI_INT_MIN "\" "
"max=\"" RSSI_INT_MAX "\" "
"name=\"ping_interval\">%s",
config_div_close));
PT_WAIT_THREAD(&s->generate_pt, PT_WAIT_THREAD(&s->generate_pt,
enqueue_chunk(s, 0, enqueue_chunk(s, 0,
"<input type=\"submit\" value=\"Submit\">")); "<input type=\"submit\" value=\"Submit\">"));

View file

@ -48,7 +48,7 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Ideally a multiple of TCP_MSS */ /* Ideally a multiple of TCP_MSS */
#ifdef HTTPD_SIMPLE_CONF_MAIN_BUF_SIZE #ifdef HTTPD_SIMPLE_CONF_MAIN_BUF_SIZE
#define HTTPD_SIMPLE_MAIN_BUF_SIZE HTTPD_SIMPLE_CONF_BUF_SIZE #define HTTPD_SIMPLE_MAIN_BUF_SIZE HTTPD_SIMPLE_CONF_MAIN_BUF_SIZE
#else #else
#define HTTPD_SIMPLE_MAIN_BUF_SIZE UIP_TCP_MSS #define HTTPD_SIMPLE_MAIN_BUF_SIZE UIP_TCP_MSS
#endif #endif

View file

@ -41,7 +41,6 @@
#include "net/rpl/rpl.h" #include "net/rpl/rpl.h"
#include "net/ip/uip.h" #include "net/ip/uip.h"
#include "net/ipv6/uip-icmp6.h" #include "net/ipv6/uip-icmp6.h"
#include "net/ipv6/sicslowpan.h"
#include "sys/etimer.h" #include "sys/etimer.h"
#include "sys/ctimer.h" #include "sys/ctimer.h"
#include "lib/sensors.h" #include "lib/sensors.h"
@ -86,7 +85,7 @@ static const char *broker_ip = "0064:ff9b:0000:0000:0000:0000:b8ac:7cbd";
* Number of times to try reconnecting to the broker. * Number of times to try reconnecting to the broker.
* Can be a limited number (e.g. 3, 10 etc) or can be set to RETRY_FOREVER * Can be a limited number (e.g. 3, 10 etc) or can be set to RETRY_FOREVER
*/ */
#define RECONNECT_ATTEMPTS RETRY_FOREVER #define RECONNECT_ATTEMPTS 5
#define CONNECTION_STABLE_TIME (CLOCK_SECOND * 5) #define CONNECTION_STABLE_TIME (CLOCK_SECOND * 5)
#define NEW_CONFIG_WAIT_INTERVAL (CLOCK_SECOND * 20) #define NEW_CONFIG_WAIT_INTERVAL (CLOCK_SECOND * 20)
static struct timer connection_life; static struct timer connection_life;
@ -139,9 +138,7 @@ static uint16_t seq_nr_value = 0;
static uip_ip6addr_t def_route; static uip_ip6addr_t def_route;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Parent RSSI functionality */ /* Parent RSSI functionality */
static struct uip_icmp6_echo_reply_notification echo_reply_notification; extern int def_rt_rssi;
static struct etimer echo_request_timer;
int def_rt_rssi = 0;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
const static cc26xx_web_demo_sensor_reading_t *reading; const static cc26xx_web_demo_sensor_reading_t *reading;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -388,29 +385,6 @@ reconnect_post_handler(char *key, int key_len, char *val, int val_len)
return HTTPD_SIMPLE_POST_HANDLER_OK; return HTTPD_SIMPLE_POST_HANDLER_OK;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int
ping_interval_post_handler(char *key, int key_len, char *val, int val_len)
{
int rv = 0;
if(key_len != strlen("ping_interval") ||
strncasecmp(key, "ping_interval", strlen("ping_interval")) != 0) {
/* Not ours */
return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN;
}
rv = atoi(val);
if(rv < MQTT_CLIENT_RSSI_MEASURE_INTERVAL_MIN ||
rv > MQTT_CLIENT_RSSI_MEASURE_INTERVAL_MAX) {
return HTTPD_SIMPLE_POST_HANDLER_ERROR;
}
conf->def_rt_ping_interval = rv * CLOCK_SECOND;
return HTTPD_SIMPLE_POST_HANDLER_OK;
}
/*---------------------------------------------------------------------------*/
HTTPD_SIMPLE_POST_HANDLER(org_id, org_id_post_handler); HTTPD_SIMPLE_POST_HANDLER(org_id, org_id_post_handler);
HTTPD_SIMPLE_POST_HANDLER(type_id, type_id_post_handler); HTTPD_SIMPLE_POST_HANDLER(type_id, type_id_post_handler);
HTTPD_SIMPLE_POST_HANDLER(event_type_id, event_type_id_post_handler); HTTPD_SIMPLE_POST_HANDLER(event_type_id, event_type_id_post_handler);
@ -420,16 +394,6 @@ HTTPD_SIMPLE_POST_HANDLER(ip_addr, ip_addr_post_handler);
HTTPD_SIMPLE_POST_HANDLER(port, port_post_handler); HTTPD_SIMPLE_POST_HANDLER(port, port_post_handler);
HTTPD_SIMPLE_POST_HANDLER(interval, interval_post_handler); HTTPD_SIMPLE_POST_HANDLER(interval, interval_post_handler);
HTTPD_SIMPLE_POST_HANDLER(reconnect, reconnect_post_handler); HTTPD_SIMPLE_POST_HANDLER(reconnect, reconnect_post_handler);
HTTPD_SIMPLE_POST_HANDLER(ping_interval, ping_interval_post_handler);
/*---------------------------------------------------------------------------*/
static void
echo_reply_handler(uip_ipaddr_t *source, uint8_t ttl, uint8_t *data,
uint16_t datalen)
{
if(uip_ip6addr_cmp(source, uip_ds6_defrt_choose())) {
def_rt_rssi = sicslowpan_get_last_rssi();
}
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
pub_handler(const char *topic, uint16_t topic_len, const uint8_t *chunk, pub_handler(const char *topic, uint16_t topic_len, const uint8_t *chunk,
@ -624,7 +588,6 @@ init_config()
conf->broker_port = CC26XX_WEB_DEMO_DEFAULT_BROKER_PORT; conf->broker_port = CC26XX_WEB_DEMO_DEFAULT_BROKER_PORT;
conf->pub_interval = CC26XX_WEB_DEMO_DEFAULT_PUBLISH_INTERVAL; conf->pub_interval = CC26XX_WEB_DEMO_DEFAULT_PUBLISH_INTERVAL;
conf->def_rt_ping_interval = CC26XX_WEB_DEMO_DEFAULT_RSSI_MEAS_INTERVAL;
return 1; return 1;
} }
@ -641,7 +604,6 @@ register_http_post_handlers(void)
httpd_simple_register_post_handler(&port_handler); httpd_simple_register_post_handler(&port_handler);
httpd_simple_register_post_handler(&ip_addr_handler); httpd_simple_register_post_handler(&ip_addr_handler);
httpd_simple_register_post_handler(&reconnect_handler); httpd_simple_register_post_handler(&reconnect_handler);
httpd_simple_register_post_handler(&ping_interval_handler);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
@ -664,6 +626,7 @@ publish(void)
/* Publish MQTT topic in IBM quickstart format */ /* Publish MQTT topic in IBM quickstart format */
int len; int len;
int remaining = APP_BUFFER_SIZE; int remaining = APP_BUFFER_SIZE;
char def_rt_str[64];
seq_nr_value++; seq_nr_value++;
@ -686,7 +649,6 @@ publish(void)
buf_ptr += len; buf_ptr += len;
/* Put our Default route's string representation in a buffer */ /* Put our Default route's string representation in a buffer */
char def_rt_str[64];
memset(def_rt_str, 0, sizeof(def_rt_str)); memset(def_rt_str, 0, sizeof(def_rt_str));
cc26xx_web_demo_ipaddr_sprintf(def_rt_str, sizeof(def_rt_str), cc26xx_web_demo_ipaddr_sprintf(def_rt_str, sizeof(def_rt_str),
uip_ds6_defrt_choose()); uip_ds6_defrt_choose());
@ -743,17 +705,6 @@ connect_to_broker(void)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
ping_parent(void)
{
if(uip_ds6_get_global(ADDR_PREFERRED) == NULL) {
return;
}
uip_icmp6_send(uip_ds6_defrt_choose(), ICMP6_ECHO_REQUEST, 0,
CC26XX_WEB_DEMO_ECHO_REQ_PAYLOAD_LEN);
}
/*---------------------------------------------------------------------------*/
static void
state_machine(void) state_machine(void)
{ {
switch(state) { switch(state) {
@ -794,7 +745,6 @@ state_machine(void)
if(uip_ds6_get_global(ADDR_PREFERRED) != NULL) { if(uip_ds6_get_global(ADDR_PREFERRED) != NULL) {
/* Registered and with a public IP. Connect */ /* Registered and with a public IP. Connect */
DBG("Registered. Connect attempt %u\n", connect_attempt); DBG("Registered. Connect attempt %u\n", connect_attempt);
ping_parent();
connect_to_broker(); connect_to_broker();
} }
etimer_set(&publish_periodic_timer, CC26XX_WEB_DEMO_NET_CONNECT_PERIODIC); etimer_set(&publish_periodic_timer, CC26XX_WEB_DEMO_NET_CONNECT_PERIODIC);
@ -923,11 +873,6 @@ PROCESS_THREAD(mqtt_client_process, ev, data)
update_config(); update_config();
def_rt_rssi = 0x8000000;
uip_icmp6_echo_reply_callback_add(&echo_reply_notification,
echo_reply_handler);
etimer_set(&echo_request_timer, conf->def_rt_ping_interval);
/* Main loop */ /* Main loop */
while(1) { while(1) {
@ -956,11 +901,6 @@ PROCESS_THREAD(mqtt_client_process, ev, data)
state_machine(); state_machine();
} }
if(ev == PROCESS_EVENT_TIMER && data == &echo_request_timer) {
ping_parent();
etimer_set(&echo_request_timer, conf->def_rt_ping_interval);
}
if(ev == cc26xx_web_demo_load_config_defaults) { if(ev == cc26xx_web_demo_load_config_defaults) {
init_config(); init_config();
etimer_set(&publish_periodic_timer, NEW_CONFIG_WAIT_INTERVAL); etimer_set(&publish_periodic_timer, NEW_CONFIG_WAIT_INTERVAL);

View file

@ -45,8 +45,6 @@
#define MQTT_CLIENT_CONFIG_CMD_TYPE_LEN 8 #define MQTT_CLIENT_CONFIG_CMD_TYPE_LEN 8
#define MQTT_CLIENT_CONFIG_IP_ADDR_STR_LEN 64 #define MQTT_CLIENT_CONFIG_IP_ADDR_STR_LEN 64
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define MQTT_CLIENT_RSSI_MEASURE_INTERVAL_MAX 86400 /* secs: 1 day */
#define MQTT_CLIENT_RSSI_MEASURE_INTERVAL_MIN 5 /* secs */
#define MQTT_CLIENT_PUBLISH_INTERVAL_MAX 86400 /* secs: 1 day */ #define MQTT_CLIENT_PUBLISH_INTERVAL_MAX 86400 /* secs: 1 day */
#define MQTT_CLIENT_PUBLISH_INTERVAL_MIN 5 /* secs */ #define MQTT_CLIENT_PUBLISH_INTERVAL_MIN 5 /* secs */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -63,7 +61,6 @@ typedef struct mqtt_client_config {
char broker_ip[MQTT_CLIENT_CONFIG_IP_ADDR_STR_LEN]; char broker_ip[MQTT_CLIENT_CONFIG_IP_ADDR_STR_LEN];
char cmd_type[MQTT_CLIENT_CONFIG_CMD_TYPE_LEN]; char cmd_type[MQTT_CLIENT_CONFIG_CMD_TYPE_LEN];
clock_time_t pub_interval; clock_time_t pub_interval;
int def_rt_ping_interval;
uint16_t broker_port; uint16_t broker_port;
} mqtt_client_config_t; } mqtt_client_config_t;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,126 @@
/*
* Copyright (c) 2015, Texas Instruments Incorporated - http://www.ti.com/
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup cc26xx-web-demo
* @{
*
* \file
* CoAP resource handler for network-related resources
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "rest-engine.h"
#include "er-coap.h"
#include "coap-server.h"
#include "cc26xx-web-demo.h"
#include "ti-lib.h"
#include <string.h>
/*---------------------------------------------------------------------------*/
extern int def_rt_rssi;
/*---------------------------------------------------------------------------*/
static void
res_get_handler_parent_rssi(void *request, void *response, uint8_t *buffer,
uint16_t preferred_size, int32_t *offset)
{
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", def_rt_rssi);
REST.set_response_payload(response, (uint8_t *)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, "{\"Parent RSSI\":\"%d\"}",
def_rt_rssi);
REST.set_response_payload(response, buffer, strlen((char *)buffer));
} else if(accept == REST.type.APPLICATION_XML) {
REST.set_header_content_type(response, REST.type.APPLICATION_XML);
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE,
"<parent-rssi val=\"%d\"/>", def_rt_rssi);
REST.set_response_payload(response, buffer, strlen((char *)buffer));
} else {
REST.set_response_status(response, REST.status.NOT_ACCEPTABLE);
REST.set_response_payload(response, coap_server_supported_msg,
strlen(coap_server_supported_msg));
}
}
/*---------------------------------------------------------------------------*/
static void
res_get_handler_pref_parent(void *request, void *response, uint8_t *buffer,
uint16_t preferred_size, int32_t *offset)
{
unsigned int accept = -1;
char def_rt_str[64];
REST.get_header_accept(request, &accept);
memset(def_rt_str, 0, sizeof(def_rt_str));
cc26xx_web_demo_ipaddr_sprintf(def_rt_str, sizeof(def_rt_str),
uip_ds6_defrt_choose());
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, "%s", def_rt_str);
REST.set_response_payload(response, (uint8_t *)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, "{\"Parent\":\"%s\"}",
def_rt_str);
REST.set_response_payload(response, buffer, strlen((char *)buffer));
} else if(accept == REST.type.APPLICATION_XML) {
REST.set_header_content_type(response, REST.type.APPLICATION_XML);
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE,
"<parent=\"%s\"/>", def_rt_str);
REST.set_response_payload(response, buffer, strlen((char *)buffer));
} else {
REST.set_response_status(response, REST.status.NOT_ACCEPTABLE);
REST.set_response_payload(response, coap_server_supported_msg,
strlen(coap_server_supported_msg));
}
}
/*---------------------------------------------------------------------------*/
RESOURCE(res_parent_rssi, "title=\"Parent RSSI\";rt=\"dBm\"",
res_get_handler_parent_rssi, NULL, NULL, NULL);
/*---------------------------------------------------------------------------*/
RESOURCE(res_parent_ip, "title=\"Preferred Parent\";rt=\"IPv6 address\"",
res_get_handler_pref_parent, NULL, NULL, NULL);
/*---------------------------------------------------------------------------*/
/** @} */