Merge branch 'contiki' into osd
This commit is contained in:
commit
877bf27f5a
245 changed files with 8117 additions and 6356 deletions
|
@ -69,8 +69,9 @@
|
|||
#include "sys/rtimer.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/uart.h"
|
||||
#include "dev/cc2538-sensors.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/adc-sensor.h"
|
||||
#include "dev/als-sensor.h"
|
||||
#include "dev/watchdog.h"
|
||||
#include "dev/serial-line.h"
|
||||
#include "dev/sys-ctrl.h"
|
||||
|
@ -114,8 +115,6 @@ rt_callback(struct rtimer *t, void *ptr)
|
|||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(cc2538_demo_process, ev, data)
|
||||
{
|
||||
int16_t value;
|
||||
|
||||
PROCESS_EXITHANDLER(broadcast_close(&bc))
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
@ -134,15 +133,13 @@ PROCESS_THREAD(cc2538_demo_process, ev, data)
|
|||
printf("-----------------------------------------\n"
|
||||
"Counter = 0x%08x\n", counter);
|
||||
|
||||
value = adc_sensor.value(ADC_SENSOR_VDD_3);
|
||||
printf("VDD = %d mV\n", value * (3 * 1190) / (2047 << 4));
|
||||
printf("VDD = %d mV\n",
|
||||
vdd3_sensor.value(CC2538_SENSORS_VALUE_TYPE_CONVERTED));
|
||||
|
||||
value = adc_sensor.value(ADC_SENSOR_TEMP);
|
||||
printf("Temperature = %d mC\n",
|
||||
25000 + ((value >> 4) - 1422) * 10000 / 42);
|
||||
cc2538_temp_sensor.value(CC2538_SENSORS_VALUE_TYPE_CONVERTED));
|
||||
|
||||
value = adc_sensor.value(ADC_SENSOR_ALS);
|
||||
printf("Ambient light sensor = %d raw\n", value);
|
||||
printf("Ambient light sensor = %d raw\n", als_sensor.value(0));
|
||||
|
||||
etimer_set(&et, CLOCK_SECOND);
|
||||
rtimer_set(&rt, RTIMER_NOW() + LEDS_OFF_HYSTERISIS, 1,
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
#include "lib/sensors.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/adc-sensor.h"
|
||||
#include "dev/cc2538-sensors.h"
|
||||
|
||||
#include <string.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -450,7 +450,6 @@ publish(void)
|
|||
/* Publish MQTT topic in IBM quickstart format */
|
||||
int len;
|
||||
int remaining = APP_BUFFER_SIZE;
|
||||
int16_t value;
|
||||
|
||||
seq_nr_value++;
|
||||
|
||||
|
@ -487,9 +486,8 @@ publish(void)
|
|||
remaining -= len;
|
||||
buf_ptr += len;
|
||||
|
||||
value = adc_sensor.value(ADC_SENSOR_TEMP);
|
||||
len = snprintf(buf_ptr, remaining, ",\"On-Chip Temp (mC)\":%d",
|
||||
25000 + ((value >> 4) - 1422) * 10000 / 42);
|
||||
cc2538_temp_sensor.value(CC2538_SENSORS_VALUE_TYPE_CONVERTED));
|
||||
|
||||
if(len < 0 || len >= remaining) {
|
||||
printf("Buffer too short. Have %d, need %d + \\0\n", remaining, len);
|
||||
|
@ -498,9 +496,8 @@ publish(void)
|
|||
remaining -= len;
|
||||
buf_ptr += len;
|
||||
|
||||
value = adc_sensor.value(ADC_SENSOR_VDD_3);
|
||||
len = snprintf(buf_ptr, remaining, ",\"VDD3 (mV)\":%d",
|
||||
value * (3 * 1190) / (2047 << 4));
|
||||
vdd3_sensor.value(CC2538_SENSORS_VALUE_TYPE_CONVERTED));
|
||||
|
||||
if(len < 0 || len >= remaining) {
|
||||
printf("Buffer too short. Have %d, need %d + \\0\n", remaining, len);
|
||||
|
|
|
@ -41,5 +41,6 @@ void
|
|||
netstack_init(void)
|
||||
{
|
||||
NETSTACK_RADIO.init();
|
||||
NETSTACK_RADIO.on();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -143,11 +143,11 @@ AUTOSTART_PROCESSES(&cc26xx_demo_process);
|
|||
#define SENSOR_READING_PERIOD (CLOCK_SECOND * 20)
|
||||
#define SENSOR_READING_RANDOM (CLOCK_SECOND << 4)
|
||||
|
||||
static struct ctimer bmp_timer, opt_timer, sht_timer, tmp_timer, mpu_timer;
|
||||
static struct ctimer bmp_timer, opt_timer, hdc_timer, tmp_timer, mpu_timer;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void init_bmp_reading(void *not_used);
|
||||
static void init_opt_reading(void *not_used);
|
||||
static void init_sht_reading(void *not_used);
|
||||
static void init_hdc_reading(void *not_used);
|
||||
static void init_tmp_reading(void *not_used);
|
||||
static void init_mpu_reading(void *not_used);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -214,27 +214,27 @@ get_tmp_reading()
|
|||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
get_sht_reading()
|
||||
get_hdc_reading()
|
||||
{
|
||||
int value;
|
||||
clock_time_t next = SENSOR_READING_PERIOD +
|
||||
(random_rand() % SENSOR_READING_RANDOM);
|
||||
|
||||
value = sht_21_sensor.value(SHT_21_SENSOR_TYPE_TEMP);
|
||||
value = hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_TEMP);
|
||||
if(value != CC26XX_SENSOR_READING_ERROR) {
|
||||
printf("SHT: Temp=%d.%02d C\n", value / 100, value % 100);
|
||||
printf("HDC: Temp=%d.%02d C\n", value / 100, value % 100);
|
||||
} else {
|
||||
printf("SHT: Temp Read Error\n");
|
||||
printf("HDC: Temp Read Error\n");
|
||||
}
|
||||
|
||||
value = sht_21_sensor.value(SHT_21_SENSOR_TYPE_HUMIDITY);
|
||||
value = hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_HUMIDITY);
|
||||
if(value != CC26XX_SENSOR_READING_ERROR) {
|
||||
printf("SHT: Humidity=%d.%02d %%RH\n", value / 100, value % 100);
|
||||
printf("HDC: Humidity=%d.%02d %%RH\n", value / 100, value % 100);
|
||||
} else {
|
||||
printf("SHT: Humidity Read Error\n");
|
||||
printf("HDC: Humidity Read Error\n");
|
||||
}
|
||||
|
||||
ctimer_set(&sht_timer, next, init_sht_reading, NULL);
|
||||
ctimer_set(&hdc_timer, next, init_hdc_reading, NULL);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
|
@ -311,9 +311,9 @@ init_opt_reading(void *not_used)
|
|||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
init_sht_reading(void *not_used)
|
||||
init_hdc_reading(void *not_used)
|
||||
{
|
||||
SENSORS_ACTIVATE(sht_21_sensor);
|
||||
SENSORS_ACTIVATE(hdc_1000_sensor);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
|
@ -360,7 +360,7 @@ static void
|
|||
init_sensor_readings(void)
|
||||
{
|
||||
#if BOARD_SENSORTAG
|
||||
SENSORS_ACTIVATE(sht_21_sensor);
|
||||
SENSORS_ACTIVATE(hdc_1000_sensor);
|
||||
SENSORS_ACTIVATE(tmp_007_sensor);
|
||||
SENSORS_ACTIVATE(opt_3001_sensor);
|
||||
SENSORS_ACTIVATE(bmp_280_sensor);
|
||||
|
@ -450,8 +450,8 @@ PROCESS_THREAD(cc26xx_demo_process, ev, data)
|
|||
get_bmp_reading();
|
||||
} else if(ev == sensors_event && data == &opt_3001_sensor) {
|
||||
get_light_reading();
|
||||
} else if(ev == sensors_event && data == &sht_21_sensor) {
|
||||
get_sht_reading();
|
||||
} else if(ev == sensors_event && data == &hdc_1000_sensor) {
|
||||
get_hdc_reading();
|
||||
} else if(ev == sensors_event && data == &tmp_007_sensor) {
|
||||
get_tmp_reading();
|
||||
} else if(ev == sensors_event && data == &mpu_9250_sensor) {
|
||||
|
|
|
@ -68,7 +68,7 @@ PROCESS(cc26xx_web_demo_process, "CC26XX Web Demo");
|
|||
struct ctimer batmon_timer;
|
||||
|
||||
#if BOARD_SENSORTAG
|
||||
struct ctimer bmp_timer, sht_timer, tmp_timer, opt_timer, mpu_timer;
|
||||
struct ctimer bmp_timer, hdc_timer, tmp_timer, opt_timer, mpu_timer;
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Provide visible feedback via LEDS while searching for a network */
|
||||
|
@ -111,11 +111,11 @@ DEMO_SENSOR(bmp_pres, CC26XX_WEB_DEMO_SENSOR_BMP_PRES,
|
|||
DEMO_SENSOR(bmp_temp, CC26XX_WEB_DEMO_SENSOR_BMP_TEMP,
|
||||
"Air Temp", "air-temp", "bmp_temp",
|
||||
CC26XX_WEB_DEMO_UNIT_TEMP);
|
||||
DEMO_SENSOR(sht_temp, CC26XX_WEB_DEMO_SENSOR_SHT_TEMP,
|
||||
"SHT Temp", "sht-temp", "sht_temp",
|
||||
DEMO_SENSOR(hdc_temp, CC26XX_WEB_DEMO_SENSOR_HDC_TEMP,
|
||||
"HDC Temp", "hdc-temp", "hdc_temp",
|
||||
CC26XX_WEB_DEMO_UNIT_TEMP);
|
||||
DEMO_SENSOR(sht_hum, CC26XX_WEB_DEMO_SENSOR_SHT_HUMIDITY,
|
||||
"SHT Humidity", "sht-humidity", "sht_hum",
|
||||
DEMO_SENSOR(hdc_hum, CC26XX_WEB_DEMO_SENSOR_HDC_HUMIDITY,
|
||||
"HDC Humidity", "hdc-humidity", "hdc_hum",
|
||||
CC26XX_WEB_DEMO_UNIT_HUMIDITY);
|
||||
DEMO_SENSOR(tmp_amb, CC26XX_WEB_DEMO_SENSOR_TMP_AMBIENT,
|
||||
"Ambient Temp", "ambient-temp", "tmp_amb",
|
||||
|
@ -152,7 +152,7 @@ DEMO_SENSOR(mpu_gyro_z, CC26XX_WEB_DEMO_SENSOR_MPU_GYRO_Z,
|
|||
#if BOARD_SENSORTAG
|
||||
static void init_bmp_reading(void *data);
|
||||
static void init_light_reading(void *data);
|
||||
static void init_sht_reading(void *data);
|
||||
static void init_hdc_reading(void *data);
|
||||
static void init_tmp_reading(void *data);
|
||||
static void init_mpu_reading(void *data);
|
||||
#endif
|
||||
|
@ -526,42 +526,42 @@ get_tmp_reading()
|
|||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
get_sht_reading()
|
||||
get_hdc_reading()
|
||||
{
|
||||
int value;
|
||||
char *buf;
|
||||
clock_time_t next = SENSOR_READING_PERIOD +
|
||||
(random_rand() % SENSOR_READING_RANDOM);
|
||||
|
||||
if(sht_temp_reading.publish) {
|
||||
value = sht_21_sensor.value(SHT_21_SENSOR_TYPE_TEMP);
|
||||
if(hdc_temp_reading.publish) {
|
||||
value = hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_TEMP);
|
||||
if(value != CC26XX_SENSOR_READING_ERROR) {
|
||||
sht_temp_reading.raw = value;
|
||||
hdc_temp_reading.raw = value;
|
||||
|
||||
compare_and_update(&sht_temp_reading);
|
||||
compare_and_update(&hdc_temp_reading);
|
||||
|
||||
buf = sht_temp_reading.converted;
|
||||
buf = hdc_temp_reading.converted;
|
||||
memset(buf, 0, CC26XX_WEB_DEMO_CONVERTED_LEN);
|
||||
snprintf(buf, CC26XX_WEB_DEMO_CONVERTED_LEN, "%d.%02d", value / 100,
|
||||
value % 100);
|
||||
}
|
||||
}
|
||||
|
||||
if(sht_hum_reading.publish) {
|
||||
value = sht_21_sensor.value(SHT_21_SENSOR_TYPE_HUMIDITY);
|
||||
if(hdc_hum_reading.publish) {
|
||||
value = hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_HUMIDITY);
|
||||
if(value != CC26XX_SENSOR_READING_ERROR) {
|
||||
sht_hum_reading.raw = value;
|
||||
hdc_hum_reading.raw = value;
|
||||
|
||||
compare_and_update(&sht_hum_reading);
|
||||
compare_and_update(&hdc_hum_reading);
|
||||
|
||||
buf = sht_hum_reading.converted;
|
||||
buf = hdc_hum_reading.converted;
|
||||
memset(buf, 0, CC26XX_WEB_DEMO_CONVERTED_LEN);
|
||||
snprintf(buf, CC26XX_WEB_DEMO_CONVERTED_LEN, "%d.%02d", value / 100,
|
||||
value % 100);
|
||||
}
|
||||
}
|
||||
|
||||
ctimer_set(&sht_timer, next, init_sht_reading, NULL);
|
||||
ctimer_set(&hdc_timer, next, init_hdc_reading, NULL);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
|
@ -702,12 +702,12 @@ init_bmp_reading(void *data)
|
|||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
init_sht_reading(void *data)
|
||||
init_hdc_reading(void *data)
|
||||
{
|
||||
if(sht_hum_reading.publish || sht_temp_reading.publish) {
|
||||
SENSORS_ACTIVATE(sht_21_sensor);
|
||||
if(hdc_hum_reading.publish || hdc_temp_reading.publish) {
|
||||
SENSORS_ACTIVATE(hdc_1000_sensor);
|
||||
} else {
|
||||
ctimer_set(&sht_timer, CLOCK_SECOND, init_sht_reading, NULL);
|
||||
ctimer_set(&hdc_timer, CLOCK_SECOND, init_hdc_reading, NULL);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -756,7 +756,7 @@ init_sensor_readings(void)
|
|||
#if BOARD_SENSORTAG
|
||||
init_bmp_reading(NULL);
|
||||
init_light_reading(NULL);
|
||||
init_sht_reading(NULL);
|
||||
init_hdc_reading(NULL);
|
||||
init_tmp_reading(NULL);
|
||||
init_mpu_reading(NULL);
|
||||
#endif /* BOARD_SENSORTAG */
|
||||
|
@ -781,8 +781,8 @@ init_sensors(void)
|
|||
|
||||
list_add(sensor_list, &opt_reading);
|
||||
|
||||
list_add(sensor_list, &sht_hum_reading);
|
||||
list_add(sensor_list, &sht_temp_reading);
|
||||
list_add(sensor_list, &hdc_hum_reading);
|
||||
list_add(sensor_list, &hdc_temp_reading);
|
||||
|
||||
list_add(sensor_list, &mpu_acc_x_reading);
|
||||
list_add(sensor_list, &mpu_acc_y_reading);
|
||||
|
@ -852,7 +852,7 @@ PROCESS_THREAD(cc26xx_web_demo_process, ev, data)
|
|||
while(1) {
|
||||
if(ev == sensors_event && data == CC26XX_WEB_DEMO_SENSOR_READING_TRIGGER) {
|
||||
if((CC26XX_WEB_DEMO_SENSOR_READING_TRIGGER)->value(
|
||||
BUTTON_SENSOR_VALUE_DURATION) > CLOCK_SECOND * 5) {
|
||||
BUTTON_SENSOR_VALUE_DURATION) > CLOCK_SECOND * 5) {
|
||||
printf("Restoring defaults!\n");
|
||||
cc26xx_web_demo_restore_defaults();
|
||||
} else {
|
||||
|
@ -873,8 +873,8 @@ PROCESS_THREAD(cc26xx_web_demo_process, ev, data)
|
|||
get_bmp_reading();
|
||||
} else if(ev == sensors_event && data == &opt_3001_sensor) {
|
||||
get_light_reading();
|
||||
} else if(ev == sensors_event && data == &sht_21_sensor) {
|
||||
get_sht_reading();
|
||||
} else if(ev == sensors_event && data == &hdc_1000_sensor) {
|
||||
get_hdc_reading();
|
||||
} else if(ev == sensors_event && data == &tmp_007_sensor) {
|
||||
get_tmp_reading();
|
||||
} else if(ev == sensors_event && data == &mpu_9250_sensor) {
|
||||
|
|
|
@ -121,8 +121,8 @@
|
|||
#define CC26XX_WEB_DEMO_SENSOR_BMP_TEMP 3
|
||||
#define CC26XX_WEB_DEMO_SENSOR_TMP_AMBIENT 4
|
||||
#define CC26XX_WEB_DEMO_SENSOR_TMP_OBJECT 5
|
||||
#define CC26XX_WEB_DEMO_SENSOR_SHT_TEMP 6
|
||||
#define CC26XX_WEB_DEMO_SENSOR_SHT_HUMIDITY 7
|
||||
#define CC26XX_WEB_DEMO_SENSOR_HDC_TEMP 6
|
||||
#define CC26XX_WEB_DEMO_SENSOR_HDC_HUMIDITY 7
|
||||
#define CC26XX_WEB_DEMO_SENSOR_OPT_LIGHT 8
|
||||
#define CC26XX_WEB_DEMO_SENSOR_MPU_ACC_X 9
|
||||
#define CC26XX_WEB_DEMO_SENSOR_MPU_ACC_Y 10
|
||||
|
|
|
@ -66,8 +66,8 @@ extern resource_t res_bmp280_temp;
|
|||
extern resource_t res_bmp280_press;
|
||||
extern resource_t res_tmp007_amb;
|
||||
extern resource_t res_tmp007_obj;
|
||||
extern resource_t res_sht21_temp;
|
||||
extern resource_t res_sht21_hum;
|
||||
extern resource_t res_hdc1000_temp;
|
||||
extern resource_t res_hdc1000_hum;
|
||||
extern resource_t res_opt3001_light;
|
||||
extern resource_t res_mpu_acc_x;
|
||||
extern resource_t res_mpu_acc_y;
|
||||
|
@ -98,8 +98,8 @@ start_board_resources(void)
|
|||
rest_activate_resource(&res_bmp280_press, "sen/bar/pres");
|
||||
rest_activate_resource(&res_tmp007_amb, "sen/tmp/amb");
|
||||
rest_activate_resource(&res_tmp007_obj, "sen/tmp/obj");
|
||||
rest_activate_resource(&res_sht21_temp, "sen/sht/t");
|
||||
rest_activate_resource(&res_sht21_hum, "sen/sht/h");
|
||||
rest_activate_resource(&res_hdc1000_temp, "sen/hdc/t");
|
||||
rest_activate_resource(&res_hdc1000_hum, "sen/hdc/h");
|
||||
rest_activate_resource(&res_opt3001_light, "sen/opt/light");
|
||||
rest_activate_resource(&res_mpu_acc_x, "sen/mpu/acc/x");
|
||||
rest_activate_resource(&res_mpu_acc_y, "sen/mpu/acc/y");
|
||||
|
|
|
@ -163,11 +163,6 @@ static const char *http_header_srv_str[] = {
|
|||
NULL
|
||||
};
|
||||
|
||||
static const char *http_header_redir_location[] = {
|
||||
"Location: /config.html\r\n",
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char *http_header_con_close[] = {
|
||||
CONN_CLOSE,
|
||||
NULL
|
||||
|
@ -197,37 +192,49 @@ static const char config_div_left[] = "<div class=\"left\">";
|
|||
static const char config_div_right[] = "<div class=\"right\">";
|
||||
static const char config_div_close[] = "</div>";
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static char generate_index(struct httpd_state *s);
|
||||
static char generate_config(struct httpd_state *s);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
typedef struct page {
|
||||
struct page *next;
|
||||
char *filename;
|
||||
char *title;
|
||||
char (*script)(struct httpd_state *s);
|
||||
} page_t;
|
||||
|
||||
static page_t http_index_page = {
|
||||
NULL,
|
||||
"index.html",
|
||||
"Index",
|
||||
generate_index,
|
||||
};
|
||||
|
||||
static page_t http_dev_cfg_page = {
|
||||
NULL,
|
||||
"config.html",
|
||||
"Device Config",
|
||||
generate_config,
|
||||
};
|
||||
|
||||
#if CC26XX_WEB_DEMO_NET_UART
|
||||
static char generate_net_uart_config(struct httpd_state *s);
|
||||
|
||||
static page_t http_net_cfg_page = {
|
||||
NULL,
|
||||
"net.html",
|
||||
"netu.html",
|
||||
"Net-UART Config",
|
||||
generate_net_uart_config,
|
||||
};
|
||||
#endif
|
||||
|
||||
#if CC26XX_WEB_DEMO_MQTT_CLIENT
|
||||
static char generate_mqtt_config(struct httpd_state *s);
|
||||
|
||||
static page_t http_mqtt_cfg_page = {
|
||||
NULL,
|
||||
"mqtt.html",
|
||||
"MQTT/IBM Cloud Config",
|
||||
generate_mqtt_config,
|
||||
};
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -395,12 +402,12 @@ PT_THREAD(generate_top_matter(struct httpd_state *s, const char *title,
|
|||
|
||||
s->page = list_head(pages_list);
|
||||
PT_WAIT_THREAD(&s->top_matter_pt,
|
||||
enqueue_chunk(s, 0, "<a href=\"%s\">[ %s ]</a>",
|
||||
enqueue_chunk(s, 0, "[ <a href=\"%s\">%s</a> ]",
|
||||
s->page->filename, s->page->title));
|
||||
|
||||
for(s->page = s->page->next; s->page != NULL; s->page = s->page->next) {
|
||||
PT_WAIT_THREAD(&s->top_matter_pt,
|
||||
enqueue_chunk(s, 0, " | <a href=\"%s\">[ %s ]</a>",
|
||||
enqueue_chunk(s, 0, " | [ <a href=\"%s\">%s</a> ]",
|
||||
s->page->filename, s->page->title));
|
||||
}
|
||||
|
||||
|
@ -531,7 +538,8 @@ PT_THREAD(generate_config(struct httpd_state *s))
|
|||
|
||||
PT_WAIT_THREAD(&s->generate_pt,
|
||||
enqueue_chunk(s, 0,
|
||||
"<form name=\"input\" action=\"config\" "));
|
||||
"<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,
|
||||
|
@ -570,7 +578,8 @@ PT_THREAD(generate_config(struct httpd_state *s))
|
|||
PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, "<h1>Actions</h1>"));
|
||||
PT_WAIT_THREAD(&s->generate_pt,
|
||||
enqueue_chunk(s, 0,
|
||||
"<form name=\"input\" action=\"defaults\" "));
|
||||
"<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,
|
||||
|
@ -607,7 +616,8 @@ PT_THREAD(generate_mqtt_config(struct httpd_state *s))
|
|||
|
||||
PT_WAIT_THREAD(&s->generate_pt,
|
||||
enqueue_chunk(s, 0,
|
||||
"<form name=\"input\" action=\"config\" "));
|
||||
"<form name=\"input\" action=\"%s\" ",
|
||||
http_mqtt_cfg_page.filename));
|
||||
PT_WAIT_THREAD(&s->generate_pt,
|
||||
enqueue_chunk(s, 0, "method=\"post\" enctype=\""));
|
||||
PT_WAIT_THREAD(&s->generate_pt,
|
||||
|
@ -747,7 +757,8 @@ PT_THREAD(generate_mqtt_config(struct httpd_state *s))
|
|||
enqueue_chunk(s, 0, "</form>"));
|
||||
PT_WAIT_THREAD(&s->generate_pt,
|
||||
enqueue_chunk(s, 0,
|
||||
"<form name=\"input\" action=\"config\" "));
|
||||
"<form name=\"input\" action=\"%s\" ",
|
||||
http_mqtt_cfg_page.filename));
|
||||
PT_WAIT_THREAD(&s->generate_pt,
|
||||
enqueue_chunk(s, 0, "method=\"post\" enctype=\""));
|
||||
PT_WAIT_THREAD(&s->generate_pt,
|
||||
|
@ -786,7 +797,8 @@ PT_THREAD(generate_net_uart_config(struct httpd_state *s))
|
|||
|
||||
PT_WAIT_THREAD(&s->generate_pt,
|
||||
enqueue_chunk(s, 0,
|
||||
"<form name=\"input\" action=\"net_uart\" "));
|
||||
"<form name=\"input\" action=\"%s\" ",
|
||||
http_net_cfg_page.filename));
|
||||
PT_WAIT_THREAD(&s->generate_pt,
|
||||
enqueue_chunk(s, 0, "method=\"post\" enctype=\""));
|
||||
PT_WAIT_THREAD(&s->generate_pt,
|
||||
|
@ -974,18 +986,13 @@ parse_post_request_chunk(char *buf, int buf_len, int last_chunk)
|
|||
static httpd_simple_script_t
|
||||
get_script(const char *name)
|
||||
{
|
||||
if(strlen(name) == 10 && strncmp(name, "index.html", 10) == 0) {
|
||||
return generate_index;
|
||||
} else if(strlen(name) == 11 && strncmp(name, "config.html", 11) == 0) {
|
||||
return generate_config;
|
||||
#if CC26XX_WEB_DEMO_MQTT_CLIENT
|
||||
} else if(strlen(name) == 9 && strncmp(name, "mqtt.html", 9) == 0) {
|
||||
return generate_mqtt_config;
|
||||
#endif
|
||||
#if CC26XX_WEB_DEMO_NET_UART
|
||||
} else if(strlen(name) == 8 && strncmp(name, "net.html", 8) == 0) {
|
||||
return generate_net_uart_config;
|
||||
#endif
|
||||
page_t *page;
|
||||
|
||||
for(page = list_head(pages_list); page != NULL;
|
||||
page = list_item_next(page)) {
|
||||
if(strncmp(name, page->filename, strlen(page->filename)) == 0) {
|
||||
return page->script;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -1003,7 +1010,8 @@ PT_THREAD(send_string(struct httpd_state *s, const char *str))
|
|||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr,
|
||||
const char *content_type, const char **additional))
|
||||
const char *content_type, const char *redir,
|
||||
const char **additional))
|
||||
{
|
||||
PT_BEGIN(&s->generate_pt);
|
||||
|
||||
|
@ -1013,6 +1021,11 @@ PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr,
|
|||
PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, *(s->ptr)));
|
||||
}
|
||||
|
||||
if(redir) {
|
||||
PT_WAIT_THREAD(&s->generate_pt,
|
||||
enqueue_chunk(s, 0, "Location: %s\r\n", redir));
|
||||
}
|
||||
|
||||
if(additional) {
|
||||
for(s->ptr = additional; *(s->ptr) != NULL; s->ptr++) {
|
||||
PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, *(s->ptr)));
|
||||
|
@ -1041,25 +1054,30 @@ PT_THREAD(handle_output(struct httpd_state *s))
|
|||
if(s->return_code == RETURN_CODE_OK) {
|
||||
PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_302,
|
||||
http_content_type_plain,
|
||||
http_header_redir_location));
|
||||
s->filename,
|
||||
NULL));
|
||||
} else if(s->return_code == RETURN_CODE_LR) {
|
||||
PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_411,
|
||||
http_content_type_plain,
|
||||
NULL,
|
||||
http_header_con_close));
|
||||
PT_WAIT_THREAD(&s->outputpt, send_string(s, "Content-Length Required\n"));
|
||||
} else if(s->return_code == RETURN_CODE_TL) {
|
||||
PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_413,
|
||||
http_content_type_plain,
|
||||
NULL,
|
||||
http_header_con_close));
|
||||
PT_WAIT_THREAD(&s->outputpt, send_string(s, "Content-Length too Large\n"));
|
||||
} else if(s->return_code == RETURN_CODE_SU) {
|
||||
PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_503,
|
||||
http_content_type_plain,
|
||||
NULL,
|
||||
http_header_con_close));
|
||||
PT_WAIT_THREAD(&s->outputpt, send_string(s, "Service Unavailable\n"));
|
||||
} else {
|
||||
PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_400,
|
||||
http_content_type_plain,
|
||||
NULL,
|
||||
http_header_con_close));
|
||||
PT_WAIT_THREAD(&s->outputpt, send_string(s, "Bad Request\n"));
|
||||
}
|
||||
|
@ -1069,6 +1087,7 @@ PT_THREAD(handle_output(struct httpd_state *s))
|
|||
strncpy(s->filename, "/notfound.html", sizeof(s->filename));
|
||||
PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_404,
|
||||
http_content_type_html,
|
||||
NULL,
|
||||
http_header_con_close));
|
||||
PT_WAIT_THREAD(&s->outputpt,
|
||||
send_string(s, NOT_FOUND));
|
||||
|
@ -1077,6 +1096,7 @@ PT_THREAD(handle_output(struct httpd_state *s))
|
|||
} else {
|
||||
PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_200,
|
||||
http_content_type_html,
|
||||
NULL,
|
||||
http_header_con_close));
|
||||
PT_WAIT_THREAD(&s->outputpt, s->script(s));
|
||||
}
|
||||
|
@ -1109,6 +1129,15 @@ PT_THREAD(handle_input(struct httpd_state *s))
|
|||
}
|
||||
} else if(strncasecmp(s->inputbuf, http_post, 5) == 0) {
|
||||
s->request_type = REQUEST_TYPE_POST;
|
||||
PSOCK_READTO(&s->sin, ISO_space);
|
||||
|
||||
if(s->inputbuf[0] != ISO_slash) {
|
||||
PSOCK_CLOSE_EXIT(&s->sin);
|
||||
}
|
||||
|
||||
s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
|
||||
strncpy(s->filename, s->inputbuf, sizeof(s->filename));
|
||||
|
||||
/* POST: Read out the rest of the line and ignore it */
|
||||
PSOCK_READTO(&s->sin, ISO_nl);
|
||||
|
||||
|
@ -1279,8 +1308,8 @@ PROCESS_THREAD(httpd_simple_process, ev, data)
|
|||
init();
|
||||
|
||||
snprintf(http_mqtt_a, IBM_QUICKSTART_LINK_LEN,
|
||||
"<a href=\"http://quickstart.internetofthings.ibmcloud.com/#/device/"
|
||||
"%02x%02x%02x%02x%02x%02x/sensor/\">[ IBM Quickstart ]</a>",
|
||||
"[ <a href=\"http://quickstart.internetofthings.ibmcloud.com/#/device/"
|
||||
"%02x%02x%02x%02x%02x%02x/sensor/\">IBM Quickstart</a> ]",
|
||||
linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1],
|
||||
linkaddr_node_addr.u8[2], linkaddr_node_addr.u8[5],
|
||||
linkaddr_node_addr.u8[6], linkaddr_node_addr.u8[7]);
|
||||
|
|
|
@ -44,10 +44,14 @@
|
|||
#define CC26XX_WEB_DEMO_CONF_COAP_SERVER 1
|
||||
#define CC26XX_WEB_DEMO_CONF_NET_UART 1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Shrink the size of the uIP buffer, routing table and ND cache */
|
||||
/*
|
||||
* Shrink the size of the uIP buffer, routing table and ND cache.
|
||||
* Set the TCP MSS
|
||||
*/
|
||||
#define UIP_CONF_BUFFER_SIZE 900
|
||||
#define NBR_TABLE_CONF_MAX_NEIGHBORS 8
|
||||
#define UIP_CONF_MAX_ROUTES 8
|
||||
#define UIP_CONF_TCP_MSS 128
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* PROJECT_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -229,28 +229,28 @@ RESOURCE(res_bmp280_press,
|
|||
"title=\"Barometer (Pressure)\";rt=\"hPa (hectopascal / millibar)\"",
|
||||
res_get_handler_bmp_press, NULL, NULL, NULL);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* SHT21 sensor resources and handler: Temperature, Pressure */
|
||||
/* HDC1000 sensor resources and handler: Temperature, Pressure */
|
||||
static void
|
||||
res_get_handler_sht_temp(void *request, void *response, uint8_t *buffer,
|
||||
res_get_handler_hdc_temp(void *request, void *response, uint8_t *buffer,
|
||||
uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
res_get_handler_all(CC26XX_WEB_DEMO_SENSOR_SHT_TEMP, request, response,
|
||||
res_get_handler_all(CC26XX_WEB_DEMO_SENSOR_HDC_TEMP, request, response,
|
||||
buffer, preferred_size, offset);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
res_get_handler_sht_humidity(void *request, void *response, uint8_t *buffer,
|
||||
res_get_handler_hdc_humidity(void *request, void *response, uint8_t *buffer,
|
||||
uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
res_get_handler_all(CC26XX_WEB_DEMO_SENSOR_SHT_HUMIDITY, request, response,
|
||||
res_get_handler_all(CC26XX_WEB_DEMO_SENSOR_HDC_HUMIDITY, request, response,
|
||||
buffer, preferred_size, offset);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
RESOURCE(res_sht21_temp, "title=\"Temperature\";rt=\"C\"",
|
||||
res_get_handler_sht_temp, NULL, NULL, NULL);
|
||||
RESOURCE(res_hdc1000_temp, "title=\"Temperature\";rt=\"C\"",
|
||||
res_get_handler_hdc_temp, NULL, NULL, NULL);
|
||||
|
||||
RESOURCE(res_sht21_hum, "title=\"Humidity\";rt=\"%RH\"",
|
||||
res_get_handler_sht_humidity, NULL, NULL, NULL);
|
||||
RESOURCE(res_hdc1000_hum, "title=\"Humidity\";rt=\"%RH\"",
|
||||
res_get_handler_hdc_humidity, NULL, NULL, NULL);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Illuminance resources and handler */
|
||||
static void
|
||||
|
|
|
@ -66,7 +66,6 @@ PROCESS_THREAD(example_shell_process, ev, data)
|
|||
shell_file_init();
|
||||
shell_httpd_init();
|
||||
shell_irc_init();
|
||||
shell_netfile_init();
|
||||
/*shell_ping_init();*/ /* uIP ping */
|
||||
shell_power_init();
|
||||
/*shell_profile_init();*/
|
||||
|
|
7
examples/http-socket/Makefile
Normal file
7
examples/http-socket/Makefile
Normal file
|
@ -0,0 +1,7 @@
|
|||
all: http-example
|
||||
CONTIKI=../..
|
||||
MODULES += core/net/http-socket
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
||||
|
||||
|
62
examples/http-socket/http-example.c
Normal file
62
examples/http-socket/http-example.c
Normal file
|
@ -0,0 +1,62 @@
|
|||
#include "contiki-net.h"
|
||||
#include "http-socket.h"
|
||||
#include "ip64-addr.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static struct http_socket s;
|
||||
static int bytes_received = 0;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(http_example_process, "HTTP Example");
|
||||
AUTOSTART_PROCESSES(&http_example_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
callback(struct http_socket *s, void *ptr,
|
||||
http_socket_event_t e,
|
||||
const uint8_t *data, uint16_t datalen)
|
||||
{
|
||||
if(e == HTTP_SOCKET_ERR) {
|
||||
printf("HTTP socket error\n");
|
||||
} else if(e == HTTP_SOCKET_TIMEDOUT) {
|
||||
printf("HTTP socket error: timed out\n");
|
||||
} else if(e == HTTP_SOCKET_ABORTED) {
|
||||
printf("HTTP socket error: aborted\n");
|
||||
} else if(e == HTTP_SOCKET_HOSTNAME_NOT_FOUND) {
|
||||
printf("HTTP socket error: hostname not found\n");
|
||||
} else if(e == HTTP_SOCKET_CLOSED) {
|
||||
printf("HTTP socket closed, %d bytes received\n", bytes_received);
|
||||
} else if(e == HTTP_SOCKET_DATA) {
|
||||
bytes_received += datalen;
|
||||
printf("HTTP socket received %d bytes of data\n", datalen);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(http_example_process, ev, data)
|
||||
{
|
||||
static struct etimer et;
|
||||
uip_ip4addr_t ip4addr;
|
||||
uip_ip6addr_t ip6addr;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
uip_ipaddr(&ip4addr, 8,8,8,8);
|
||||
ip64_addr_4to6(&ip4addr, &ip6addr);
|
||||
uip_nameserver_update(&ip6addr, UIP_NAMESERVER_INFINITE_LIFETIME);
|
||||
|
||||
etimer_set(&et, CLOCK_SECOND * 60);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
|
||||
http_socket_init(&s);
|
||||
http_socket_get(&s, "http://www.contiki-os.org/", 0, 0,
|
||||
callback, NULL);
|
||||
|
||||
etimer_set(&et, CLOCK_SECOND);
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
etimer_reset(&et);
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
5
examples/ip64-router/Makefile
Normal file
5
examples/ip64-router/Makefile
Normal file
|
@ -0,0 +1,5 @@
|
|||
all: ip64-router
|
||||
CONTIKI=../..
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
||||
|
27
examples/ip64-router/ip64-router.c
Normal file
27
examples/ip64-router/ip64-router.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "contiki.h"
|
||||
#include "contiki-net.h"
|
||||
#include "ip64.h"
|
||||
#include "net/netstack.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(router_node_process, "Router node");
|
||||
AUTOSTART_PROCESSES(&router_node_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(router_node_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
/* Set us up as a RPL root node. */
|
||||
rpl_dag_root_init_dag();
|
||||
|
||||
/* Initialize the IP64 module so we'll start translating packets */
|
||||
ip64_init();
|
||||
|
||||
/* ... and do nothing more. */
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT();
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
0
examples/ip64-router/project-conf.h
Normal file
0
examples/ip64-router/project-conf.h
Normal file
|
@ -137,7 +137,7 @@ collect_common_send(void)
|
|||
/* Use parts of the IPv6 address as the parent address, in reversed byte order. */
|
||||
parent.u8[LINKADDR_SIZE - 1] = nbr->ipaddr.u8[sizeof(uip_ipaddr_t) - 2];
|
||||
parent.u8[LINKADDR_SIZE - 2] = nbr->ipaddr.u8[sizeof(uip_ipaddr_t) - 1];
|
||||
parent_etx = rpl_get_parent_rank((linkaddr_t *) uip_ds6_nbr_get_ll(nbr)) / 2;
|
||||
parent_etx = rpl_get_parent_rank((uip_lladdr_t *) uip_ds6_nbr_get_ll(nbr)) / 2;
|
||||
}
|
||||
}
|
||||
rtmetric = dag->rank;
|
||||
|
|
|
@ -109,8 +109,7 @@ parse(void)
|
|||
}
|
||||
packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.src_addr);
|
||||
packetbuf_set_attr(PACKETBUF_ATTR_PENDING, frame.fcf.frame_pending);
|
||||
/* packetbuf_set_attr(PACKETBUF_ATTR_RELIABLE, frame.fcf.ack_required);*/
|
||||
packetbuf_set_attr(PACKETBUF_ATTR_PACKET_ID, frame.seq);
|
||||
packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, frame.seq);
|
||||
|
||||
PRINTF("15.4-IN: %2X", frame.fcf.frame_type);
|
||||
PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
all: rest-server-example coap-client-example
|
||||
|
||||
ifndef TARGET
|
||||
TARGET=sky
|
||||
endif
|
||||
|
||||
CONTIKI=../..
|
||||
|
||||
WITH_COAP = 1
|
||||
|
||||
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
|
||||
|
||||
ifeq ($(WITH_COAP), 1)
|
||||
CFLAGS += -DWITH_COAP
|
||||
APPS += rest-coap
|
||||
else
|
||||
CFLAGS += -DWITH_HTTP
|
||||
APPS += rest-http
|
||||
endif
|
||||
|
||||
CONTIKI_WITH_IPV6 = 1
|
||||
include $(CONTIKI)/Makefile.include
|
||||
|
||||
$(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c
|
||||
(cd $(CONTIKI)/tools && $(MAKE) tunslip6)
|
||||
|
||||
connect-router: $(CONTIKI)/tools/tunslip6
|
||||
sudo $(CONTIKI)/tools/tunslip6 aaaa::1/64
|
||||
|
||||
connect-router-cooja: $(CONTIKI)/tools/tunslip6
|
||||
sudo $(CONTIKI)/tools/tunslip6 -a 127.0.0.1 aaaa::1/64
|
|
@ -1,137 +0,0 @@
|
|||
REST example
|
||||
============
|
||||
|
||||
Open a terminal and go to "<CONTIKI_HOME>/examples/rest-example/" directory.
|
||||
|
||||
MAIN EXAMPLE: rest-server-example.c : A RESTful server example showing how to
|
||||
use the REST layer to develop server-side applications (possible to run it over
|
||||
either COAP or HTTP) To use COAP as the underlying application protocol, one
|
||||
should define WITH_COAP = 1 in rest-example/Makefile. Otherwise, HTTP is used.
|
||||
Look at the source code to see which resources are available. (check the
|
||||
RESOURCE macros in the code). Each resource has a handler function which is
|
||||
called by the REST layer to serve the request. (i.e. "helloworld" resource has
|
||||
a handler function named "helloworld_handler" which is called when a web
|
||||
service request is received for "helloworld" resource.)
|
||||
|
||||
|
||||
To run REST examples in COOJA on Linux
|
||||
--------------------------------------------
|
||||
|
||||
Accessing the server from outside:
|
||||
|
||||
1. Start COOJA and load the simulation "rest-server-example.csc" by the following command.
|
||||
|
||||
make TARGET=cooja rest-server-example.csc
|
||||
|
||||
2. After loading the COOJA file, open another another terminal pointing to the
|
||||
same directory and connect to the COOJA simulation using tunslip6:
|
||||
|
||||
make connect-router-cooja
|
||||
|
||||
3. You need to use a COAP or HTTP client to interact with the COOJA nodes
|
||||
running REST code. In this setting, two servers are available: IP addresses
|
||||
are aaaa::0212:7402:0002:0202 and aaaa::0212:7403:0003:0303. COAP uses
|
||||
61616, whereas HTTP uses 8080 port in default configuration. First, ping
|
||||
the COOJA nodes to test the connectivity.
|
||||
|
||||
ping6 aaaa::0212:7402:0002:0202
|
||||
ping6 aaaa::0212:7403:0003:0303
|
||||
|
||||
HTTP Examples
|
||||
-------------
|
||||
|
||||
You can use curl as an http client to interact with the COOJA motes running
|
||||
REST code.
|
||||
|
||||
curl -H "User-Agent: curl" aaaa::0212:7402:0002:0202:8080/helloworld #get helloworld plain text
|
||||
curl -H "User-Agent: curl" aaaa::0212:7402:0002:0202:8080/led?color=green -d mode=off -i #turn off the green led
|
||||
curl -H "User-Agent: curl" aaaa::0212:7402:0002:0202:8080/.well-known/core -i
|
||||
curl -X POST -H "User-Agent: curl" aaaa::0212:7402:0002:0202:8080/helloworld #method not allowed
|
||||
|
||||
COAP Examples
|
||||
-------------
|
||||
|
||||
You should run a COAP client on your computer. You can use the URLs and methods
|
||||
provided above in HTTP examples to test the COAP Server. For example, Matthias
|
||||
Kovatsch has developed a CoAP Firefox plug-in which is accessible via
|
||||
[http://people.inf.ethz.ch/mkovatsc/#pro](http://people.inf.ethz.ch/mkovatsc/#pro)
|
||||
|
||||
Accessing the server inside the sensor network: (Note: Provided only for COAP
|
||||
implementation) Start COOJA and load the simulation
|
||||
"coap-client-server-example.csc" by the following command.
|
||||
|
||||
make TARGET=cooja coap-client-server-example.csc
|
||||
|
||||
coap-client-server-example.csc : Runs rest-server-example.c as the server (over
|
||||
COAP) (IP:aaaa::0212:7401:0001:0101) in one node and coap-client-example.c as
|
||||
the client (IP: aaaa::0212:7402:0002:0202) in another node. Client
|
||||
periodically accesses resources of server and prints the payload.
|
||||
|
||||
Note: If the generated binary is bigger than the MOTE code size, then you will
|
||||
get a "region text is full" error. Right now, REST+HTTP example uses (Contiki
|
||||
& ContikiMAC & uIPv6 & RPL & HTTP Server & REST Layer) which does not fit in
|
||||
Tmote Sky memory. To save same code space and make the example fit, you can
|
||||
define static routes rather than using RPL or use nullrdc rather than
|
||||
ContikiMAC. If border router does not fit, then first try to update the
|
||||
Makefile of border router in <CONTIKI_HOME>/examples/ipv6/rpl-border-router by
|
||||
setting WITH_WEBSERVER=0.
|
||||
|
||||
To run REST server on real nodes (i.e. tmote sky)
|
||||
--------------------------------------------
|
||||
|
||||
1. Program the nodes with the rest-server-example
|
||||
|
||||
make TARGET=sky rest-server-example.upload
|
||||
|
||||
2. Disconnect the nodes and program one node with the RPL border router
|
||||
|
||||
cd ../ipv6/rpl-border-router && make TARGET=sky border-router.upload
|
||||
|
||||
3. Connect to the border router using tunslip6:
|
||||
|
||||
make connect-router
|
||||
|
||||
4. Reconnect the motes, open new terminal for each mote and run the following
|
||||
command to note their IP addresses (after running the command reset the
|
||||
corresponding mote to get IP address printed)
|
||||
|
||||
make login TARGET=sky MOTE=2 #Shows the prints for first mote
|
||||
make login TARGET=sky MOTE=3 #For second mote and so on.
|
||||
|
||||
5. Test the connectivity by pinging them.
|
||||
|
||||
ping6 <IPv6 Address of the MOTE>
|
||||
|
||||
6. Remaining parts are the same with the COOJA example. (i.e. if it is a COAP
|
||||
Server, it's available at <NODE_IP_ADDR>:61616)
|
||||
|
||||
|
||||
To run REST server with minimal-net on Linux
|
||||
--------------------------------------------
|
||||
1. Compile with minimal-net setting.
|
||||
|
||||
make rest-server-example TARGET=minimal-net
|
||||
|
||||
2. Run the generated executable with sudo and note the IP address of the server
|
||||
which will be printed right after.
|
||||
|
||||
sudo ./rest-server-example.minimal-net
|
||||
|
||||
3. How to access and test the server is same with the other settings. (i.e. if
|
||||
it is a COAP Server, it's available at <IP_ADDRESS_FROM_STEP_2>:61616 and if
|
||||
it's a HTTP Server it is available at <IP_ADDRESS_FROM_STEP_2>:8080)
|
||||
|
||||
TODO
|
||||
----
|
||||
|
||||
- Better option handling needed - ex: critical options are not differentiated
|
||||
for now. Need to add support for some such as Tokens. Also, C/E difference
|
||||
should be added.
|
||||
- Reilable message sending is missing. i.e. client example should resend
|
||||
request in case ACK does not arrive. Same for server pushing (in case of
|
||||
subscriptions)
|
||||
- Add Block transfer example
|
||||
- Add Subscription example
|
||||
- Add an Android/Java COAP Client to Contikiprojects to be able to interact
|
||||
with Contiki.
|
||||
- COAP-specific Method Codes
|
|
@ -1,123 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "contiki.h"
|
||||
#include "contiki-net.h"
|
||||
#include "rest.h"
|
||||
#include "buffer.h"
|
||||
|
||||
#define DEBUG 1
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#define PRINT6ADDR(addr) PRINTF("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
|
||||
#define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x ",(lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3],(lladdr)->addr[4], (lladdr)->addr[5])
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#define PRINT6ADDR(addr)
|
||||
#define PRINTLLADDR(addr)
|
||||
#endif
|
||||
|
||||
#define SERVER_NODE(ipaddr) uip_ip6addr(ipaddr, 0xfe80, 0, 0, 0, 0x0212, 0x7401, 0x0001, 0x0101)
|
||||
#define LOCAL_PORT 61617
|
||||
#define REMOTE_PORT 61616
|
||||
|
||||
char temp[100];
|
||||
int xact_id;
|
||||
static uip_ipaddr_t server_ipaddr;
|
||||
static struct uip_udp_conn *client_conn;
|
||||
static struct etimer et;
|
||||
#define MAX_PAYLOAD_LEN 100
|
||||
|
||||
#define NUMBER_OF_URLS 3
|
||||
char* service_urls[NUMBER_OF_URLS] = {"light", ".well-known/core", "helloworld"};
|
||||
|
||||
static void
|
||||
response_handler(coap_packet_t* response)
|
||||
{
|
||||
uint16_t payload_len = 0;
|
||||
uint8_t* payload = NULL;
|
||||
payload_len = coap_get_payload(response, &payload);
|
||||
|
||||
PRINTF("Response transaction id: %u", response->tid);
|
||||
if (payload) {
|
||||
memcpy(temp, payload, payload_len);
|
||||
temp[payload_len] = 0;
|
||||
PRINTF(" payload: %s\n", temp);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
send_data(void)
|
||||
{
|
||||
char buf[MAX_PAYLOAD_LEN];
|
||||
|
||||
if (init_buffer(COAP_DATA_BUFF_SIZE)) {
|
||||
int data_size = 0;
|
||||
int service_id = random_rand() % NUMBER_OF_URLS;
|
||||
coap_packet_t* request = (coap_packet_t*)allocate_buffer(sizeof(coap_packet_t));
|
||||
init_packet(request);
|
||||
|
||||
coap_set_method(request, COAP_GET);
|
||||
request->tid = xact_id++;
|
||||
request->type = MESSAGE_TYPE_CON;
|
||||
coap_set_header_uri(request, service_urls[service_id]);
|
||||
|
||||
data_size = serialize_packet(request, buf);
|
||||
|
||||
PRINTF("Client sending request to:[");
|
||||
PRINT6ADDR(&client_conn->ripaddr);
|
||||
PRINTF("]:%u/%s\n", (uint16_t)REMOTE_PORT, service_urls[service_id]);
|
||||
uip_udp_packet_send(client_conn, buf, data_size);
|
||||
|
||||
delete_buffer();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
handle_incoming_data()
|
||||
{
|
||||
PRINTF("Incoming packet size: %u \n", (uint16_t)uip_datalen());
|
||||
if (init_buffer(COAP_DATA_BUFF_SIZE)) {
|
||||
if (uip_newdata()) {
|
||||
coap_packet_t* response = (coap_packet_t*)allocate_buffer(sizeof(coap_packet_t));
|
||||
if (response) {
|
||||
parse_message(response, uip_appdata, uip_datalen());
|
||||
response_handler(response);
|
||||
}
|
||||
}
|
||||
delete_buffer();
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS(coap_client_example, "COAP Client Example");
|
||||
AUTOSTART_PROCESSES(&coap_client_example);
|
||||
|
||||
PROCESS_THREAD(coap_client_example, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
SERVER_NODE(&server_ipaddr);
|
||||
|
||||
/* new connection with server */
|
||||
client_conn = udp_new(&server_ipaddr, UIP_HTONS(REMOTE_PORT), NULL);
|
||||
udp_bind(client_conn, UIP_HTONS(LOCAL_PORT));
|
||||
|
||||
PRINTF("Created a connection with the server ");
|
||||
PRINT6ADDR(&client_conn->ripaddr);
|
||||
PRINTF(" local/remote port %u/%u\n",
|
||||
UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));
|
||||
|
||||
etimer_set(&et, 5 * CLOCK_SECOND);
|
||||
while(1) {
|
||||
PROCESS_YIELD();
|
||||
if (etimer_expired(&et)) {
|
||||
send_data();
|
||||
etimer_reset(&et);
|
||||
} else if (ev == tcpip_event) {
|
||||
handle_incoming_data();
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
|
@ -1,147 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<simconf>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mrm</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mspsim</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/avrora</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/serial_socket</project>
|
||||
<simulation>
|
||||
<title>coap-client-server-example</title>
|
||||
<delaytime>-2147483648</delaytime>
|
||||
<randomseed>123456</randomseed>
|
||||
<motedelay_us>1000000</motedelay_us>
|
||||
<radiomedium>
|
||||
org.contikios.cooja.radiomediums.UDGM
|
||||
<transmitting_range>50.0</transmitting_range>
|
||||
<interference_range>100.0</interference_range>
|
||||
<success_ratio_tx>1.0</success_ratio_tx>
|
||||
<success_ratio_rx>1.0</success_ratio_rx>
|
||||
</radiomedium>
|
||||
<events>
|
||||
<logoutput>40000</logoutput>
|
||||
</events>
|
||||
<motetype>
|
||||
org.contikios.cooja.mspmote.SkyMoteType
|
||||
<identifier>sky1</identifier>
|
||||
<description>CoapServer</description>
|
||||
<source EXPORT="discard">[CONTIKI_DIR]/examples/rest-example/rest-server-example.c</source>
|
||||
<commands EXPORT="discard">make rest-server-example.sky TARGET=sky</commands>
|
||||
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/rest-example/rest-server-example.sky</firmware>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.RimeAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.MoteAttributes</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspClock</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspMoteID</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyButton</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyFlash</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyCoffeeFilesystem</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.Msp802154Radio</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspSerial</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyLED</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspDebugOutput</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyTemperature</moteinterface>
|
||||
</motetype>
|
||||
<motetype>
|
||||
org.contikios.cooja.mspmote.SkyMoteType
|
||||
<identifier>sky2</identifier>
|
||||
<description>CoapClient</description>
|
||||
<source EXPORT="discard">[CONTIKI_DIR]/examples/rest-example/coap-client-example.c</source>
|
||||
<commands EXPORT="discard">make coap-client-example.sky TARGET=sky</commands>
|
||||
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/rest-example/coap-client-example.sky</firmware>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.RimeAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.MoteAttributes</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspClock</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspMoteID</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyButton</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyFlash</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyCoffeeFilesystem</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.Msp802154Radio</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspSerial</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyLED</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspDebugOutput</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyTemperature</moteinterface>
|
||||
</motetype>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>54.5338749671737</x>
|
||||
<y>36.41934631024719</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>1</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>49.41583327244326</x>
|
||||
<y>52.00647916206431</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>2</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>sky2</motetype_identifier>
|
||||
</mote>
|
||||
</simulation>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.SimControl
|
||||
<width>318</width>
|
||||
<z>2</z>
|
||||
<height>172</height>
|
||||
<location_x>0</location_x>
|
||||
<location_y>0</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.Visualizer
|
||||
<plugin_config>
|
||||
<skin>org.contikios.cooja.plugins.skins.IDVisualizerSkin</skin>
|
||||
<skin>org.contikios.cooja.plugins.skins.AddressVisualizerSkin</skin>
|
||||
<viewport>3.686023978928717 0.0 0.0 3.686023978928717 -20.14794638096936 -127.69712925102564</viewport>
|
||||
</plugin_config>
|
||||
<width>271</width>
|
||||
<z>0</z>
|
||||
<height>211</height>
|
||||
<location_x>666</location_x>
|
||||
<location_y>41</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.LogListener
|
||||
<plugin_config>
|
||||
<filter />
|
||||
</plugin_config>
|
||||
<width>1263</width>
|
||||
<z>1</z>
|
||||
<height>199</height>
|
||||
<location_x>0</location_x>
|
||||
<location_y>339</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.TimeLine
|
||||
<plugin_config>
|
||||
<mote>0</mote>
|
||||
<mote>1</mote>
|
||||
<showRadioRXTX />
|
||||
<showRadioHW />
|
||||
<showLEDs />
|
||||
<split>125</split>
|
||||
<zoomfactor>500.0</zoomfactor>
|
||||
</plugin_config>
|
||||
<width>1263</width>
|
||||
<z>3</z>
|
||||
<height>150</height>
|
||||
<location_x>0</location_x>
|
||||
<location_y>538</location_y>
|
||||
</plugin>
|
||||
</simconf>
|
||||
|
|
@ -1,180 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "contiki.h"
|
||||
#include "contiki-net.h"
|
||||
#include "rest.h"
|
||||
|
||||
#if defined (PLATFORM_HAS_LIGHT)
|
||||
#include "dev/light-sensor.h"
|
||||
#endif
|
||||
#if defined (PLATFORM_HAS_BATT)
|
||||
#include "dev/battery-sensor.h"
|
||||
#endif
|
||||
#if defined (PLATFORM_HAS_SHT11)
|
||||
#include "dev/sht11/sht11-sensor.h"
|
||||
#endif
|
||||
#if defined (PLATFORM_HAS_LEDS)
|
||||
#include "dev/leds.h"
|
||||
#endif
|
||||
|
||||
#define DEBUG 1
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
|
||||
#define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x ",(lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3],(lladdr)->addr[4], (lladdr)->addr[5])
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#define PRINT6ADDR(addr)
|
||||
#define PRINTLLADDR(addr)
|
||||
#endif
|
||||
|
||||
char temp[100];
|
||||
|
||||
/* Resources are defined by RESOURCE macro, signature: resource name, the http methods it handles and its url*/
|
||||
RESOURCE(helloworld, METHOD_GET, "helloworld");
|
||||
|
||||
/* For each resource defined, there corresponds an handler method which should be defined too.
|
||||
* Name of the handler method should be [resource name]_handler
|
||||
* */
|
||||
void
|
||||
helloworld_handler(REQUEST* request, RESPONSE* response)
|
||||
{
|
||||
sprintf(temp,"Hello World!\n");
|
||||
|
||||
rest_set_header_content_type(response, TEXT_PLAIN);
|
||||
rest_set_response_payload(response, (uint8_t*)temp, strlen(temp));
|
||||
}
|
||||
|
||||
RESOURCE(discover, METHOD_GET, ".well-known/core");
|
||||
void
|
||||
discover_handler(REQUEST* request, RESPONSE* response)
|
||||
{
|
||||
char temp[100];
|
||||
int index = 0;
|
||||
index += sprintf(temp + index, "%s,", "</helloworld>;n=\"HelloWorld\"");
|
||||
#if defined (PLATFORM_HAS_LEDS)
|
||||
index += sprintf(temp + index, "%s,", "</led>;n=\"LedControl\"");
|
||||
#endif
|
||||
#if defined (PLATFORM_HAS_LIGHT)
|
||||
index += sprintf(temp + index, "%s", "</light>;n=\"Light\"");
|
||||
#endif
|
||||
|
||||
rest_set_response_payload(response, (uint8_t*)temp, strlen(temp));
|
||||
rest_set_header_content_type(response, APPLICATION_LINK_FORMAT);
|
||||
}
|
||||
|
||||
#if defined (PLATFORM_HAS_LIGHT)
|
||||
uint16_t light_photosynthetic;
|
||||
uint16_t light_solar;
|
||||
|
||||
void
|
||||
read_light_sensor(uint16_t* light_1, uint16_t* light_2)
|
||||
{
|
||||
*light_1 = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC);
|
||||
*light_2 = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);
|
||||
}
|
||||
|
||||
/*A simple getter example. Returns the reading from light sensor with a simple etag*/
|
||||
RESOURCE(light, METHOD_GET, "light");
|
||||
void
|
||||
light_handler(REQUEST* request, RESPONSE* response)
|
||||
{
|
||||
read_light_sensor(&light_photosynthetic, &light_solar);
|
||||
sprintf(temp,"%u;%u", light_photosynthetic, light_solar);
|
||||
|
||||
char etag[4] = "ABCD";
|
||||
rest_set_header_content_type(response, TEXT_PLAIN);
|
||||
rest_set_header_etag(response, etag, sizeof(etag));
|
||||
rest_set_response_payload(response, temp, strlen(temp));
|
||||
}
|
||||
#endif /*PLATFORM_HAS_LIGHT*/
|
||||
|
||||
#if defined (PLATFORM_HAS_LEDS)
|
||||
/*A simple actuator example, depending on the color query parameter and post variable mode, corresponding led is activated or deactivated*/
|
||||
RESOURCE(led, METHOD_POST | METHOD_PUT , "led");
|
||||
|
||||
void
|
||||
led_handler(REQUEST* request, RESPONSE* response)
|
||||
{
|
||||
char color[10];
|
||||
char mode[10];
|
||||
uint8_t led = 0;
|
||||
int success = 1;
|
||||
|
||||
if (rest_get_query_variable(request, "color", color, 10)) {
|
||||
PRINTF("color %s\n", color);
|
||||
|
||||
if (!strcmp(color,"red")) {
|
||||
led = LEDS_RED;
|
||||
} else if(!strcmp(color,"green")) {
|
||||
led = LEDS_GREEN;
|
||||
} else if ( !strcmp(color,"blue") ) {
|
||||
led = LEDS_BLUE;
|
||||
} else {
|
||||
success = 0;
|
||||
}
|
||||
} else {
|
||||
success = 0;
|
||||
}
|
||||
|
||||
if (success && rest_get_post_variable(request, "mode", mode, 10)) {
|
||||
PRINTF("mode %s\n", mode);
|
||||
|
||||
if (!strcmp(mode, "on")) {
|
||||
leds_on(led);
|
||||
} else if (!strcmp(mode, "off")) {
|
||||
leds_off(led);
|
||||
} else {
|
||||
success = 0;
|
||||
}
|
||||
} else {
|
||||
success = 0;
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
rest_set_response_status(response, BAD_REQUEST_400);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*A simple actuator example. Toggles the red led*/
|
||||
RESOURCE(toggle, METHOD_GET | METHOD_PUT | METHOD_POST, "toggle");
|
||||
void
|
||||
toggle_handler(REQUEST* request, RESPONSE* response)
|
||||
{
|
||||
leds_toggle(LEDS_RED);
|
||||
}
|
||||
#endif /*defined (CONTIKI_HAS_LEDS)*/
|
||||
|
||||
|
||||
PROCESS(rest_server_example, "Rest Server Example");
|
||||
AUTOSTART_PROCESSES(&rest_server_example);
|
||||
|
||||
PROCESS_THREAD(rest_server_example, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
#ifdef WITH_COAP
|
||||
PRINTF("COAP Server\n");
|
||||
#else
|
||||
PRINTF("HTTP Server\n");
|
||||
#endif
|
||||
|
||||
rest_init();
|
||||
|
||||
#if defined (PLATFORM_HAS_LIGHT)
|
||||
SENSORS_ACTIVATE(light_sensor);
|
||||
rest_activate_resource(&resource_light);
|
||||
#endif
|
||||
#if defined (PLATFORM_HAS_LEDS)
|
||||
rest_activate_resource(&resource_led);
|
||||
rest_activate_resource(&resource_toggle);
|
||||
#endif /*defined (PLATFORM_HAS_LEDS)*/
|
||||
|
||||
rest_activate_resource(&resource_helloworld);
|
||||
rest_activate_resource(&resource_discover);
|
||||
|
||||
PROCESS_END();
|
||||
}
|
|
@ -1,185 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<simconf>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mrm</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mspsim</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/avrora</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/serial_socket</project>
|
||||
<simulation>
|
||||
<title>REST with RPL router</title>
|
||||
<delaytime>-2147483648</delaytime>
|
||||
<randomseed>123456</randomseed>
|
||||
<motedelay_us>1000000</motedelay_us>
|
||||
<radiomedium>
|
||||
org.contikios.cooja.radiomediums.UDGM
|
||||
<transmitting_range>50.0</transmitting_range>
|
||||
<interference_range>50.0</interference_range>
|
||||
<success_ratio_tx>1.0</success_ratio_tx>
|
||||
<success_ratio_rx>1.0</success_ratio_rx>
|
||||
</radiomedium>
|
||||
<events>
|
||||
<logoutput>40000</logoutput>
|
||||
</events>
|
||||
<motetype>
|
||||
org.contikios.cooja.mspmote.SkyMoteType
|
||||
<identifier>rplroot</identifier>
|
||||
<description>Sky RPL Root</description>
|
||||
<source EXPORT="discard">[CONTIKI_DIR]/examples/ipv6/rpl-border-router/border-router.c</source>
|
||||
<commands EXPORT="discard">make border-router.sky TARGET=sky</commands>
|
||||
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/ipv6/rpl-border-router/border-router.sky</firmware>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.RimeAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.MoteAttributes</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspClock</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspMoteID</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyButton</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyFlash</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyCoffeeFilesystem</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.Msp802154Radio</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspSerial</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyLED</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspDebugOutput</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyTemperature</moteinterface>
|
||||
</motetype>
|
||||
<motetype>
|
||||
org.contikios.cooja.mspmote.SkyMoteType
|
||||
<identifier>skyweb</identifier>
|
||||
<description>Rest</description>
|
||||
<source EXPORT="discard">[CONTIKI_DIR]/examples/rest-example/rest-server-example.c</source>
|
||||
<commands EXPORT="discard">make rest-server-example.sky TARGET=sky</commands>
|
||||
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/rest-example/rest-server-example.sky</firmware>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.RimeAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.MoteAttributes</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspClock</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspMoteID</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyButton</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyFlash</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyCoffeeFilesystem</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.Msp802154Radio</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspSerial</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyLED</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspDebugOutput</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyTemperature</moteinterface>
|
||||
</motetype>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>33.260163187353555</x>
|
||||
<y>30.643217359962595</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>1</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>rplroot</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>62.239287566073514</x>
|
||||
<y>34.43810269527116</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>2</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>skyweb</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>47.68359039801751</x>
|
||||
<y>47.26544238238854</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>3</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>skyweb</motetype_identifier>
|
||||
</mote>
|
||||
</simulation>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.SimControl
|
||||
<width>259</width>
|
||||
<z>1</z>
|
||||
<height>179</height>
|
||||
<location_x>0</location_x>
|
||||
<location_y>0</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.Visualizer
|
||||
<plugin_config>
|
||||
<skin>org.contikios.cooja.plugins.skins.IDVisualizerSkin</skin>
|
||||
<skin>org.contikios.cooja.plugins.skins.UDGMVisualizerSkin</skin>
|
||||
<skin>org.contikios.cooja.plugins.skins.MoteTypeVisualizerSkin</skin>
|
||||
<skin>org.contikios.cooja.plugins.skins.AttributeVisualizerSkin</skin>
|
||||
<viewport>10.505309204322225 0.0 0.0 10.505309204322225 -249.89475921566975 -141.01191150973983</viewport>
|
||||
</plugin_config>
|
||||
<width>819</width>
|
||||
<z>5</z>
|
||||
<height>563</height>
|
||||
<location_x>35</location_x>
|
||||
<location_y>306</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.LogListener
|
||||
<plugin_config>
|
||||
<filter />
|
||||
</plugin_config>
|
||||
<width>762</width>
|
||||
<z>0</z>
|
||||
<height>326</height>
|
||||
<location_x>36</location_x>
|
||||
<location_y>296</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.RadioLogger
|
||||
<plugin_config>
|
||||
<split>150</split>
|
||||
<analyzers name="6lowpan" />
|
||||
</plugin_config>
|
||||
<width>815</width>
|
||||
<z>4</z>
|
||||
<height>385</height>
|
||||
<location_x>255</location_x>
|
||||
<location_y>8</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
SerialSocketServer
|
||||
<mote_arg>0</mote_arg>
|
||||
<width>422</width>
|
||||
<z>3</z>
|
||||
<height>74</height>
|
||||
<location_x>1234</location_x>
|
||||
<location_y>93</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.TimeLine
|
||||
<plugin_config>
|
||||
<mote>0</mote>
|
||||
<mote>1</mote>
|
||||
<showRadioRXTX />
|
||||
<showRadioHW />
|
||||
<showLEDs />
|
||||
<showWatchpoints />
|
||||
<split>125</split>
|
||||
<zoomfactor>25.49079397896416</zoomfactor>
|
||||
</plugin_config>
|
||||
<width>1624</width>
|
||||
<z>2</z>
|
||||
<height>252</height>
|
||||
<location_x>166</location_x>
|
||||
<location_y>699</location_y>
|
||||
</plugin>
|
||||
</simconf>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
CONTIKI = ../..
|
||||
|
||||
all: example-abc example-mesh example-collect example-trickle example-polite \
|
||||
example-rudolph0 example-rudolph1 example-rudolph2 example-rucb \
|
||||
example-rudolph1 example-rudolph2 example-rucb \
|
||||
example-runicast example-unicast example-neighbors
|
||||
|
||||
CONTIKI_WITH_RIME = 1
|
||||
|
|
|
@ -1,150 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Swedish Institute of Computer Science.
|
||||
* 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
|
||||
* Testing the rudolph0 code in Rime
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "cfs/cfs.h"
|
||||
#include "net/rime/rudolph0.h"
|
||||
|
||||
#include "dev/button-sensor.h"
|
||||
|
||||
#include "dev/leds.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define FILESIZE 200
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(example_rudolph0_process, "Rudolph0 example");
|
||||
AUTOSTART_PROCESSES(&example_rudolph0_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
write_chunk(struct rudolph0_conn *c, int offset, int flag,
|
||||
uint8_t *data, int datalen)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if(flag == RUDOLPH0_FLAG_NEWFILE) {
|
||||
/* printf("+++ rudolph0 new file incoming at %lu\n", clock_time());*/
|
||||
leds_on(LEDS_RED);
|
||||
fd = cfs_open("codeprop.out", CFS_WRITE);
|
||||
} else {
|
||||
fd = cfs_open("codeprop.out", CFS_WRITE + CFS_APPEND);
|
||||
}
|
||||
|
||||
if(datalen > 0) {
|
||||
int ret;
|
||||
cfs_seek(fd, offset, CFS_SEEK_SET);
|
||||
ret = cfs_write(fd, data, datalen);
|
||||
/* printf("write_chunk wrote %d bytes at %d, %d\n", ret, offset, (unsigned char)data[0]);*/
|
||||
}
|
||||
|
||||
cfs_close(fd);
|
||||
|
||||
if(flag == RUDOLPH0_FLAG_LASTCHUNK) {
|
||||
int i;
|
||||
/* printf("+++ rudolph0 entire file received at %lu\n", clock_time());*/
|
||||
leds_off(LEDS_RED);
|
||||
leds_on(LEDS_YELLOW);
|
||||
fd = cfs_open("hej", CFS_READ);
|
||||
for(i = 0; i < FILESIZE; ++i) {
|
||||
unsigned char buf;
|
||||
cfs_read(fd, &buf, 1);
|
||||
if(buf != (unsigned char)i) {
|
||||
printf("error: diff at %d, %d != %d\n", i, i, buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
cfs_close(fd);
|
||||
}
|
||||
}
|
||||
static int
|
||||
read_chunk(struct rudolph0_conn *c, int offset, uint8_t *to, int maxsize)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
|
||||
fd = cfs_open("hej", CFS_READ);
|
||||
|
||||
cfs_seek(fd, offset, CFS_SEEK_SET);
|
||||
ret = cfs_read(fd, to, maxsize);
|
||||
/* printf("read_chunk %d bytes at %d, %d\n", ret, offset, (unsigned char)to[0]);*/
|
||||
cfs_close(fd);
|
||||
return ret;
|
||||
}
|
||||
const static struct rudolph0_callbacks rudolph0_call = {write_chunk,
|
||||
read_chunk};
|
||||
static struct rudolph0_conn rudolph0;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(example_rudolph0_process, ev, data)
|
||||
{
|
||||
static int fd;
|
||||
|
||||
PROCESS_EXITHANDLER(rudolph0_close(&rudolph0);)
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
PROCESS_PAUSE();
|
||||
|
||||
|
||||
rudolph0_open(&rudolph0, 138, &rudolph0_call);
|
||||
SENSORS_ACTIVATE(button_sensor);
|
||||
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event &&
|
||||
data == &button_sensor);
|
||||
{
|
||||
int i;
|
||||
|
||||
fd = cfs_open("hej", CFS_WRITE);
|
||||
for(i = 0; i < FILESIZE; i++) {
|
||||
unsigned char buf = i;
|
||||
cfs_write(fd, &buf, 1);
|
||||
}
|
||||
cfs_close(fd);
|
||||
}
|
||||
rudolph0_send(&rudolph0, CLOCK_SECOND / 4);
|
||||
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event &&
|
||||
data == &button_sensor);
|
||||
rudolph0_stop(&rudolph0);
|
||||
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -7,42 +7,8 @@ all: remotepowerswitch
|
|||
CONTIKI=../../../
|
||||
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
|
||||
|
||||
WITH_COAP=13
|
||||
|
||||
# REST framework, requires WITH_COAP
|
||||
ifeq ($(WITH_COAP), 13)
|
||||
${info INFO: compiling with CoAP-13}
|
||||
CFLAGS += -DWITH_COAP=13
|
||||
CFLAGS += -DREST=coap_rest_implementation
|
||||
CFLAGS += -DUIP_CONF_TCP=0
|
||||
APPS += er-coap-13
|
||||
else ifeq ($(WITH_COAP), 12)
|
||||
${info INFO: compiling with CoAP-12}
|
||||
CFLAGS += -DWITH_COAP=12
|
||||
CFLAGS += -DREST=coap_rest_implementation
|
||||
CFLAGS += -DUIP_CONF_TCP=0
|
||||
APPS += er-coap-12
|
||||
else ifeq ($(WITH_COAP), 7)
|
||||
${info INFO: compiling with CoAP-08}
|
||||
CFLAGS += -DWITH_COAP=7
|
||||
CFLAGS += -DREST=coap_rest_implementation
|
||||
CFLAGS += -DUIP_CONF_TCP=0
|
||||
APPS += er-coap-07
|
||||
else ifeq ($(WITH_COAP), 3)
|
||||
${info INFO: compiling with CoAP-03}
|
||||
CFLAGS += -DWITH_COAP=3
|
||||
CFLAGS += -DREST=coap_rest_implementation
|
||||
CFLAGS += -DUIP_CONF_TCP=0
|
||||
APPS += er-coap-03
|
||||
else
|
||||
${info INFO: compiling with HTTP}
|
||||
CFLAGS += -DWITH_HTTP
|
||||
CFLAGS += -DREST=http_rest_implementation
|
||||
CFLAGS += -DUIP_CONF_TCP=1
|
||||
APPS += er-http-engine
|
||||
endif
|
||||
|
||||
APPS += erbium
|
||||
APPS += er-coap
|
||||
APPS += rest-engine
|
||||
|
||||
CONTIKI_WITH_IPV6 = 1
|
||||
include $(CONTIKI)/Makefile.include
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
/*
|
||||
* Remote Power Switch Example for the Seed-Eye Board
|
||||
* Copyright (c) 2013, Giovanni Pellerano
|
||||
*
|
||||
*
|
||||
* Ownership: Scuola Superiore Sant'Anna (http://www.sssup.it) and
|
||||
* Consorzio Nazionale Interuniversitario per le Telecomunicazioni
|
||||
* (http://www.cnit.it).
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
|
@ -33,7 +33,7 @@
|
|||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* \addtogroup Remote Power Switch Example for the Seed-Eye Board
|
||||
*
|
||||
|
@ -55,20 +55,21 @@
|
|||
#include "contiki.h"
|
||||
#include "contiki-net.h"
|
||||
|
||||
#include "erbium.h"
|
||||
#include "rest-engine.h"
|
||||
|
||||
#include "dev/leds.h"
|
||||
|
||||
#include <p32xxxx.h>
|
||||
|
||||
RESOURCE(toggle, METHOD_GET | METHOD_PUT | METHOD_POST, "actuators/powerswitch", "title=\"Red LED\";rt=\"Control\"");
|
||||
void
|
||||
toggle_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
leds_toggle(LEDS_RED);
|
||||
|
||||
|
||||
PORTEbits.RE0 = !PORTEbits.RE0;
|
||||
}
|
||||
RESOURCE(resource_toggle, "title=\"Red LED\";rt=\"Control\"", toggle_handler, toggle_handler, toggle_handler, NULL);
|
||||
|
||||
|
||||
PROCESS(remote_power_switch, "Remote Power Switch");
|
||||
|
||||
|
@ -79,11 +80,11 @@ PROCESS_THREAD(remote_power_switch, ev, data)
|
|||
PROCESS_BEGIN();
|
||||
|
||||
rest_init_engine();
|
||||
|
||||
|
||||
TRISEbits.TRISE0 = 0;
|
||||
PORTEbits.RE0 = 0;
|
||||
|
||||
rest_activate_resource(&resource_toggle);
|
||||
rest_activate_resource(&resource_toggle, "actuators/powerswitch");
|
||||
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT();
|
||||
|
|
|
@ -58,7 +58,6 @@ PROCESS_THREAD(test_shell_process, ev, data)
|
|||
shell_coffee_init();
|
||||
shell_exec_init();
|
||||
shell_file_init();
|
||||
shell_netfile_init();
|
||||
shell_ps_init();
|
||||
shell_rime_init();
|
||||
shell_rime_netcmd_init();
|
||||
|
|
|
@ -1,316 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "contiki.h"
|
||||
#include "sys/etimer.h"
|
||||
#include "loader/elfloader.h"
|
||||
|
||||
#include "net/ip/uip.h"
|
||||
|
||||
#include "dev/leds.h"
|
||||
|
||||
#include "cfs/cfs.h"
|
||||
|
||||
#include "codeprop.h"
|
||||
|
||||
#include "net/rime/rudolph0.h"
|
||||
|
||||
#include <io.h>
|
||||
|
||||
#define DEBUG 0
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
PROCESS(tcp_loader_process, "TCP loader");
|
||||
AUTOSTART_PROCESSES(&tcp_loader_process);
|
||||
|
||||
static
|
||||
struct codeprop_state {
|
||||
uint16_t addr;
|
||||
uint16_t len;
|
||||
struct pt tcpthread_pt;
|
||||
int fd;
|
||||
} s;
|
||||
|
||||
static char msg[30 + 10];
|
||||
|
||||
static struct rudolph0_conn rudolph0;
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
static int
|
||||
start_program(void)
|
||||
{
|
||||
/* Link, load, and start new program. */
|
||||
int ret;
|
||||
s.fd = cfs_open("codeprop.out", CFS_READ);
|
||||
ret = elfloader_load(s.fd);
|
||||
|
||||
/* XXX: Interrupts seems to be turned off a little too long during the
|
||||
ELF loading process, so we need to "manually" trigger a timer
|
||||
interrupt here. */
|
||||
TACCR1 = TAR + 1000;
|
||||
|
||||
if(ret == ELFLOADER_OK) {
|
||||
sprintf(msg, "ok\n");
|
||||
PRINTF("Ok, starting new program.\n");
|
||||
/* Start processes. */
|
||||
autostart_start(elfloader_autostart_processes);
|
||||
} else {
|
||||
sprintf(msg, "err %d %s", ret, elfloader_unknown);
|
||||
PRINTF("Error: '%s'.\n", msg);
|
||||
}
|
||||
cfs_close(s.fd);
|
||||
return ret;
|
||||
}
|
||||
/*---------------------------------------------------------------------*/
|
||||
static
|
||||
PT_THREAD(recv_tcpthread(struct pt *pt))
|
||||
{
|
||||
PT_BEGIN(pt);
|
||||
|
||||
/* Read the header. */
|
||||
PT_WAIT_UNTIL(pt, uip_newdata() && uip_datalen() > 0);
|
||||
|
||||
if(uip_datalen() < sizeof(struct codeprop_tcphdr)) {
|
||||
PRINTF(("codeprop: header not found in first tcp segment\n"));
|
||||
uip_abort();
|
||||
goto thread_done;
|
||||
}
|
||||
|
||||
/* Kill old program. */
|
||||
rudolph0_stop(&rudolph0);
|
||||
/* elfloader_unload();*/
|
||||
|
||||
s.len = uip_htons(((struct codeprop_tcphdr *)uip_appdata)->len);
|
||||
s.addr = 0;
|
||||
uip_appdata += sizeof(struct codeprop_tcphdr);
|
||||
uip_len -= sizeof(struct codeprop_tcphdr);
|
||||
|
||||
s.fd = cfs_open("codeprop.out", CFS_WRITE);
|
||||
cfs_close(s.fd);
|
||||
/* xmem_erase(XMEM_ERASE_UNIT_SIZE, EEPROMFS_ADDR_CODEPROP);*/
|
||||
|
||||
/* Read the rest of the data. */
|
||||
do {
|
||||
leds_toggle(LEDS_RED);
|
||||
if(uip_len > 0) {
|
||||
s.fd = cfs_open("codeprop.out", CFS_WRITE + CFS_APPEND);
|
||||
cfs_seek(s.fd, s.addr, CFS_SEEK_SET);
|
||||
/* xmem_pwrite(uip_appdata, uip_len, EEPROMFS_ADDR_CODEPROP + s.addr);*/
|
||||
cfs_write(s.fd, uip_appdata, uip_len);
|
||||
cfs_close(s.fd);
|
||||
|
||||
PRINTF("Wrote %d bytes to file\n", uip_len);
|
||||
s.addr += uip_len;
|
||||
}
|
||||
if(s.addr < s.len) {
|
||||
PT_YIELD_UNTIL(pt, uip_newdata());
|
||||
}
|
||||
} while(s.addr < s.len);
|
||||
leds_off(LEDS_RED);
|
||||
|
||||
#if DEBUG
|
||||
{
|
||||
int i, fd, j;
|
||||
printf("Contents of file:\n");
|
||||
fd = cfs_open("codeprop.out", CFS_READ);
|
||||
j = 0;
|
||||
printf("\n0x%04x: ", 0);
|
||||
for(i = 0; i < s.len; ++i) {
|
||||
unsigned char byte;
|
||||
cfs_read(fd, &byte, 1);
|
||||
printf("0x%02x, ", byte);
|
||||
++j;
|
||||
if(j == 8) {
|
||||
printf("\n0x%04x: ", i + 1);
|
||||
j = 0;
|
||||
}
|
||||
clock_delay(400);
|
||||
}
|
||||
cfs_close(fd);
|
||||
}
|
||||
#endif
|
||||
|
||||
int ret;
|
||||
|
||||
ret = start_program();
|
||||
|
||||
#if CONTIKI_TARGET_NETSIM
|
||||
rudolph0_send(&rudolph0, CLOCK_SECOND / 4);
|
||||
#else /* CONTIKI_TARGET_NETSIM */
|
||||
if(ret == ELFLOADER_OK) {
|
||||
/* Propagate program. */
|
||||
rudolph0_send(&rudolph0, CLOCK_SECOND / 4);
|
||||
}
|
||||
#endif /* CONTIKI_TARGET_NETSIM */
|
||||
|
||||
/* Return "ok" message. */
|
||||
do {
|
||||
ret = strlen(msg);
|
||||
uip_send(msg, ret);
|
||||
PT_WAIT_UNTIL(pt, uip_acked() || uip_rexmit() || uip_closed());
|
||||
} while(uip_rexmit());
|
||||
|
||||
/* Close the connection. */
|
||||
uip_close();
|
||||
|
||||
|
||||
thread_done:;
|
||||
PT_END(pt);
|
||||
}
|
||||
/*---------------------------------------------------------------------*/
|
||||
static void
|
||||
write_chunk(struct rudolph0_conn *c, int offset, int flag,
|
||||
uint8_t *data, int datalen)
|
||||
{
|
||||
int fd;
|
||||
|
||||
leds_toggle(LEDS_YELLOW);
|
||||
|
||||
if(flag == RUDOLPH0_FLAG_NEWFILE) {
|
||||
printf("+++ rudolph0 new file incoming at %u\n", clock_time());
|
||||
fd = cfs_open("codeprop.out", CFS_WRITE);
|
||||
|
||||
if(elfloader_autostart_processes != NULL) {
|
||||
PRINTF("Stopping old programs.\n");
|
||||
autostart_exit(elfloader_autostart_processes);
|
||||
elfloader_autostart_processes = NULL;
|
||||
}
|
||||
|
||||
} else {
|
||||
fd = cfs_open("codeprop.out", CFS_WRITE + CFS_APPEND);
|
||||
}
|
||||
|
||||
if(datalen > 0) {
|
||||
int ret;
|
||||
cfs_seek(fd, offset, CFS_SEEK_SET);
|
||||
ret = cfs_write(fd, data, datalen);
|
||||
/* printf("write_chunk wrote %d bytes at %d, %d\n", ret, offset, (unsigned char)data[0]);*/
|
||||
}
|
||||
|
||||
cfs_close(fd);
|
||||
|
||||
if(flag == RUDOLPH0_FLAG_LASTCHUNK) {
|
||||
printf("+++ rudolph0 entire file received at %u\n", clock_time());
|
||||
start_program();
|
||||
leds_off(LEDS_YELLOW);
|
||||
}
|
||||
}
|
||||
static int
|
||||
read_chunk(struct rudolph0_conn *c, int offset, uint8_t *to, int maxsize)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
|
||||
leds_toggle(LEDS_GREEN);
|
||||
|
||||
fd = cfs_open("codeprop.out", CFS_READ);
|
||||
|
||||
cfs_seek(fd, offset, CFS_SEEK_SET);
|
||||
ret = cfs_read(fd, to, maxsize);
|
||||
/* printf("read_chunk %d bytes at %d, %d\n", ret, offset, (unsigned char)to[0]);*/
|
||||
if(ret < maxsize) {
|
||||
leds_off(LEDS_GREEN);
|
||||
}
|
||||
cfs_close(fd);
|
||||
return ret;
|
||||
}
|
||||
const static struct rudolph0_callbacks rudolph0_call = {write_chunk,
|
||||
read_chunk};
|
||||
/*---------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(tcp_loader_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
rudolph0_open(&rudolph0, 20, &rudolph0_call);
|
||||
|
||||
tcp_listen(UIP_HTONS(CODEPROP_DATA_PORT));
|
||||
|
||||
while(1) {
|
||||
PROCESS_YIELD();
|
||||
if(ev == tcpip_event && uip_conn->lport == UIP_HTONS(CODEPROP_DATA_PORT)) {
|
||||
if(uip_connected()) { /* Really uip_connecting()!!! */
|
||||
if(data == NULL) {
|
||||
PT_INIT(&s.tcpthread_pt);
|
||||
process_poll(&tcp_loader_process);
|
||||
tcp_markconn(uip_conn, &s);
|
||||
|
||||
if(elfloader_autostart_processes != NULL) {
|
||||
PRINTF("Stopping old programs.\n");
|
||||
autostart_exit(elfloader_autostart_processes);
|
||||
elfloader_autostart_processes = NULL;
|
||||
}
|
||||
} else {
|
||||
PRINTF(("codeprop: uip_connected() and data != NULL\n"));
|
||||
uip_abort();
|
||||
}
|
||||
}
|
||||
recv_tcpthread(&s.tcpthread_pt); /* Run thread */
|
||||
|
||||
if(uip_closed() || uip_aborted() || uip_timedout()) {
|
||||
PRINTF(("codeprop: connection down\n"));
|
||||
tcp_markconn(uip_conn, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------*/
|
||||
#include "net/rime/collect.h"
|
||||
#include "net/rime/mesh.h"
|
||||
#include "net/rime/rudolph0.h"
|
||||
#include "net/rime/rudolph1.h"
|
||||
void
|
||||
dummy(void)
|
||||
{
|
||||
/* Make sure that all Rime modules are present in the core */
|
||||
collect_close(NULL);
|
||||
mesh_close(NULL);
|
||||
ipolite_close(NULL);
|
||||
polite_close(NULL);
|
||||
ruc_close(NULL);
|
||||
sibc_close(NULL);
|
||||
rudolph0_close(NULL);
|
||||
rudolph1_close(NULL);
|
||||
|
||||
/* Make sure psock is included */
|
||||
psock_datalen(NULL);
|
||||
}
|
||||
/*---------------------------------------------------------------------*/
|
|
@ -7,7 +7,7 @@ ZOLERTIA_Z1SP=0
|
|||
|
||||
CONTIKI_PROJECT = test-phidgets blink test-adxl345 test-tmp102 test-light-ziglet
|
||||
CONTIKI_PROJECT += test-battery test-relay-phidget test-tlc59116 test-sht25
|
||||
CONTIKI_SOURCEFILES += sht11.c
|
||||
CONTIKI_SOURCEFILES += sht11.c reed-sensor.c
|
||||
APPS=serial-shell
|
||||
|
||||
ifeq ($(ZOLERTIA_Z1SP),1)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* Copyright (c) 2015, Zolertia <http://www.zolertia.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -26,35 +26,48 @@
|
|||
* 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
|
||||
* A quick program for testing a reed sensor.
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
|
||||
#ifndef PROJECT_RPL_WEB_CONF_H_
|
||||
#define PROJECT_RPL_WEB_CONF_H_
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "reed-sensor.h"
|
||||
#define REED_READ_INTERVAL (CLOCK_SECOND / 4)
|
||||
#define REED_EXAMPLE_EVENT 1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(test_process, "Reed test process");
|
||||
AUTOSTART_PROCESSES(&test_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct etimer et;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(test_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
/* Disabling RDC and CSMA for demo purposes. Core updates often
|
||||
require more memory. */
|
||||
/* For projects, optimize memory and enable RDC and CSMA again. */
|
||||
#undef NETSTACK_CONF_RDC
|
||||
#define NETSTACK_CONF_RDC nullrdc_driver
|
||||
|
||||
#undef NETSTACK_CONF_MAC
|
||||
#define NETSTACK_CONF_MAC nullmac_driver
|
||||
|
||||
#ifndef QUEUEBUF_CONF_NUM
|
||||
#define QUEUEBUF_CONF_NUM 6
|
||||
SENSORS_ACTIVATE(reed_sensor);
|
||||
#if REED_EXAMPLE_EVENT
|
||||
reed_sensor.configure(REED_SENSOR_MODE, REED_SENSOR_EVENT_MODE);
|
||||
#else
|
||||
etimer_set(&et, REED_READ_INTERVAL);
|
||||
#endif
|
||||
|
||||
#ifndef UIP_CONF_BUFFER_SIZE
|
||||
#define UIP_CONF_BUFFER_SIZE 140
|
||||
#endif
|
||||
while(1) {
|
||||
|
||||
#ifndef UIP_CONF_RECEIVE_WINDOW
|
||||
#define UIP_CONF_RECEIVE_WINDOW 60
|
||||
#endif
|
||||
PROCESS_YIELD();
|
||||
|
||||
#ifndef WEBSERVER_CONF_CFS_CONNS
|
||||
#define WEBSERVER_CONF_CFS_CONNS 2
|
||||
#endif
|
||||
|
||||
#endif /* PROJECT_RPL_WEB_CONF_H_ */
|
||||
if(ev == PROCESS_EVENT_TIMER) {
|
||||
printf("Reed poll status [%d]\n", reed_sensor.value(REED_SENSOR_VAL));
|
||||
etimer_restart(&et);
|
||||
} else if(ev == reed_sensor_event_changed) {
|
||||
printf("Reed sensor event --> %d\n", (*((int *)data)));
|
||||
}
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue