diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/start-demo/Makefile b/examples/platform-specific/simplelink/cc13xx-cc26xx/start-demo/Makefile deleted file mode 100644 index bffecb99c..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/start-demo/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -CONTIKI_PROJECT = start-demo - -PLATFORMS_ONLY = simplelink - -all: $(CONTIKI_PROJECT) - -CONTIKI = ../../../../.. -include $(CONTIKI)/Makefile.include diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/start-demo/README.md b/examples/platform-specific/simplelink/cc13xx-cc26xx/start-demo/README.md deleted file mode 100644 index af20f6e3f..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/start-demo/README.md +++ /dev/null @@ -1,14 +0,0 @@ -CC26xx Demo -=========== -This example demonstrates basic functionality for the two supported CC26xx -boards. More specifically, the example demonstrates: - -* How to take sensor readings -* How to use buttons and the reed relay (triggered by holding a magnet near S3 - on the SensorTag). -* How to send out BLE advertisements, if the chip has BLE capability. The - device will periodically send out BLE beacons with the platform name as - payload. Those beacons/BLE ADV packets can be captured with any BLE-capable - device. Two such applications for iOS are the TI Multitool and the TI - Sensortag app. They can be found in the Apple App Store. If you have a - BLE-capable Mac, you can also use LightBlue for OS X. diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/start-demo/project-conf.h b/examples/platform-specific/simplelink/cc13xx-cc26xx/start-demo/project-conf.h deleted file mode 100644 index 17bd2ce29..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/start-demo/project-conf.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2014, 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. - */ -/*---------------------------------------------------------------------------*/ -#ifndef PROJECT_CONF_H_ -#define PROJECT_CONF_H_ -/*---------------------------------------------------------------------------*/ -/* Enable the ROM bootloader */ -#define ROM_BOOTLOADER_ENABLE 1 -/*---------------------------------------------------------------------------*/ -/* Change to match your configuration */ -#define IEEE802154_CONF_PANID 0xABCD -#define IEEE802154_CONF_DEFAULT_CHANNEL 25 -#define RF_BLE_CONF_ENABLED 1 -/*---------------------------------------------------------------------------*/ -#endif /* PROJECT_CONF_H_ */ -/*---------------------------------------------------------------------------*/ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/start-demo/start-demo.c b/examples/platform-specific/simplelink/cc13xx-cc26xx/start-demo/start-demo.c deleted file mode 100644 index 9ed3f32cb..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/start-demo/start-demo.c +++ /dev/null @@ -1,425 +0,0 @@ -/* - * Copyright (c) 2014, 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-platforms - * @{ - * - * \defgroup cc26xx-examples CC26xx Example Projects - * - * Example projects for CC26xx-based platforms. - * @{ - * - * \defgroup cc26xx-demo CC26xx Demo Project - * - * Example project demonstrating the CC13xx/CC26xx platforms - * - * This example will work for the following boards: - * - srf06-cc26xx: SmartRF06EB + CC13xx/CC26xx EM - * - CC2650 and CC1350 SensorTag - * - CC1310, CC1350, CC2650 LaunchPads - * - * This is an IPv6/RPL-enabled example. Thus, if you have a border router in - * your installation (same RDC layer, same PAN ID and RF channel), you should - * be able to ping6 this demo node. - * - * This example also demonstrates CC26xx BLE operation. The process starts - * the BLE beacon daemon (implemented in the RF driver). The daemon will - * send out a BLE beacon periodically. Use any BLE-enabled application (e.g. - * LightBlue on OS X or the TI BLE Multitool smartphone app) and after a few - * seconds the cc26xx device will be discovered. - * - * - etimer/clock : Every CC26XX_DEMO_LOOP_INTERVAL clock ticks the LED defined - * as CC26XX_DEMO_LEDS_PERIODIC will toggle and the device - * will print out readings from some supported sensors - * - sensors : Some sensortag sensors are read asynchronously (see sensor - * documentation). For those, this example will print out - * readings in a staggered fashion at a random interval - * - Buttons : CC26XX_DEMO_TRIGGER_1 button will toggle CC26XX_DEMO_LEDS_BUTTON - * - CC26XX_DEMO_TRIGGER_2 turns on LEDS_REBOOT and causes a - * watchdog reboot - * - The remaining buttons will just print something - * - The example also shows how to retrieve the duration of a - * button press (in ticks). The driver will generate a - * sensors_changed event upon button release - * - Reed Relay : Will toggle the sensortag buzzer on/off - * - * @{ - * - * \file - * Example demonstrating the cc26xx platforms - */ -#include "contiki.h" -#include "sys/etimer.h" -#include "sys/ctimer.h" -#include "dev/leds.h" -#include "dev/watchdog.h" -#include "dev/button-hal.h" -#include "random.h" -#include "button-sensor.h" -#include "batmon-sensor.h" -#include "board-peripherals.h" - -#include "rf/ble-beacond.h" - -#include -#include -/*---------------------------------------------------------------------------*/ -#define CC26XX_DEMO_LOOP_INTERVAL (CLOCK_SECOND * 20) -#define CC26XX_DEMO_LEDS_PERIODIC LEDS_YELLOW -#define CC26XX_DEMO_LEDS_BUTTON LEDS_RED -#define CC26XX_DEMO_LEDS_REBOOT LEDS_ALL -/*---------------------------------------------------------------------------*/ -#define CC26XX_DEMO_TRIGGER_1 BUTTON_HAL_ID_KEY_LEFT -#define CC26XX_DEMO_TRIGGER_2 BUTTON_HAL_ID_KEY_RIGHT - -#if BOARD_SENSORTAG -#define CC26XX_DEMO_TRIGGER_3 BUTTON_HAL_ID_REED_RELAY -#endif -/*---------------------------------------------------------------------------*/ -static struct etimer et; -/*---------------------------------------------------------------------------*/ -PROCESS(cc26xx_demo_process, "cc26xx demo process"); -AUTOSTART_PROCESSES(&cc26xx_demo_process); -/*---------------------------------------------------------------------------*/ -#if BOARD_SENSORTAG -/*---------------------------------------------------------------------------*/ -/* - * Update sensor readings in a staggered fashion every SENSOR_READING_PERIOD - * ticks + a random interval between 0 and SENSOR_READING_RANDOM ticks - */ -#define SENSOR_READING_PERIOD (CLOCK_SECOND * 20) -#define SENSOR_READING_RANDOM (CLOCK_SECOND << 4) - -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_hdc_reading(void *not_used); -static void init_tmp_reading(void *not_used); -static void init_mpu_reading(void *not_used); -/*---------------------------------------------------------------------------*/ -static void -print_mpu_reading(int reading) -{ - if(reading < 0) { - printf("-"); - reading = -reading; - } - - printf("%d.%02d", reading / 100, reading % 100); -} -/*---------------------------------------------------------------------------*/ -static void -get_bmp_reading() -{ - int value; - clock_time_t next = SENSOR_READING_PERIOD + - (random_rand() % SENSOR_READING_RANDOM); - - value = bmp_280_sensor.value(BMP_280_SENSOR_TYPE_PRESS); - if(value != CC26XX_SENSOR_READING_ERROR) { - printf("BAR: Pressure=%d.%02d hPa\n", value / 100, value % 100); - } else { - printf("BAR: Pressure Read Error\n"); - } - - value = bmp_280_sensor.value(BMP_280_SENSOR_TYPE_TEMP); - if(value != CC26XX_SENSOR_READING_ERROR) { - printf("BAR: Temp=%d.%02d C\n", value / 100, value % 100); - } else { - printf("BAR: Temperature Read Error\n"); - } - - SENSORS_DEACTIVATE(bmp_280_sensor); - - ctimer_set(&bmp_timer, next, init_bmp_reading, NULL); -} -/*---------------------------------------------------------------------------*/ -static void -get_tmp_reading() -{ - int value; - clock_time_t next = SENSOR_READING_PERIOD + - (random_rand() % SENSOR_READING_RANDOM); - - value = tmp_007_sensor.value(TMP_007_SENSOR_TYPE_ALL); - - if(value == CC26XX_SENSOR_READING_ERROR) { - printf("TMP: Ambient Read Error\n"); - return; - } - - value = tmp_007_sensor.value(TMP_007_SENSOR_TYPE_AMBIENT); - printf("TMP: Ambient=%d.%03d C\n", value / 1000, value % 1000); - - value = tmp_007_sensor.value(TMP_007_SENSOR_TYPE_OBJECT); - printf("TMP: Object=%d.%03d C\n", value / 1000, value % 1000); - - SENSORS_DEACTIVATE(tmp_007_sensor); - - ctimer_set(&tmp_timer, next, init_tmp_reading, NULL); -} -/*---------------------------------------------------------------------------*/ -static void -get_hdc_reading() -{ - int value; - clock_time_t next = SENSOR_READING_PERIOD + - (random_rand() % SENSOR_READING_RANDOM); - - value = hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_TEMP); - if(value != CC26XX_SENSOR_READING_ERROR) { - printf("HDC: Temp=%d.%02d C\n", value / 100, value % 100); - } else { - printf("HDC: Temp Read Error\n"); - } - - value = hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_HUMIDITY); - if(value != CC26XX_SENSOR_READING_ERROR) { - printf("HDC: Humidity=%d.%02d %%RH\n", value / 100, value % 100); - } else { - printf("HDC: Humidity Read Error\n"); - } - - ctimer_set(&hdc_timer, next, init_hdc_reading, NULL); -} -/*---------------------------------------------------------------------------*/ -static void -get_light_reading() -{ - int value; - clock_time_t next = SENSOR_READING_PERIOD + - (random_rand() % SENSOR_READING_RANDOM); - - value = opt_3001_sensor.value(0); - if(value != CC26XX_SENSOR_READING_ERROR) { - printf("OPT: Light=%d.%02d lux\n", value / 100, value % 100); - } else { - printf("OPT: Light Read Error\n"); - } - - /* The OPT will turn itself off, so we don't need to call its DEACTIVATE */ - ctimer_set(&opt_timer, next, init_opt_reading, NULL); -} -/*---------------------------------------------------------------------------*/ -static void -get_mpu_reading() -{ - int value; - clock_time_t next = SENSOR_READING_PERIOD + - (random_rand() % SENSOR_READING_RANDOM); - - printf("MPU Gyro: X="); - value = mpu_9250_sensor.value(MPU_9250_SENSOR_TYPE_GYRO_X); - print_mpu_reading(value); - printf(" deg/sec\n"); - - printf("MPU Gyro: Y="); - value = mpu_9250_sensor.value(MPU_9250_SENSOR_TYPE_GYRO_Y); - print_mpu_reading(value); - printf(" deg/sec\n"); - - printf("MPU Gyro: Z="); - value = mpu_9250_sensor.value(MPU_9250_SENSOR_TYPE_GYRO_Z); - print_mpu_reading(value); - printf(" deg/sec\n"); - - printf("MPU Acc: X="); - value = mpu_9250_sensor.value(MPU_9250_SENSOR_TYPE_ACC_X); - print_mpu_reading(value); - printf(" G\n"); - - printf("MPU Acc: Y="); - value = mpu_9250_sensor.value(MPU_9250_SENSOR_TYPE_ACC_Y); - print_mpu_reading(value); - printf(" G\n"); - - printf("MPU Acc: Z="); - value = mpu_9250_sensor.value(MPU_9250_SENSOR_TYPE_ACC_Z); - print_mpu_reading(value); - printf(" G\n"); - - SENSORS_DEACTIVATE(mpu_9250_sensor); - - ctimer_set(&mpu_timer, next, init_mpu_reading, NULL); -} -/*---------------------------------------------------------------------------*/ -static void -init_bmp_reading(void *not_used) -{ - SENSORS_ACTIVATE(bmp_280_sensor); -} -/*---------------------------------------------------------------------------*/ -static void -init_opt_reading(void *not_used) -{ - SENSORS_ACTIVATE(opt_3001_sensor); -} -/*---------------------------------------------------------------------------*/ -static void -init_hdc_reading(void *not_used) -{ - SENSORS_ACTIVATE(hdc_1000_sensor); -} -/*---------------------------------------------------------------------------*/ -static void -init_tmp_reading(void *not_used) -{ - SENSORS_ACTIVATE(tmp_007_sensor); -} -/*---------------------------------------------------------------------------*/ -static void -init_mpu_reading(void *not_used) -{ - mpu_9250_sensor.configure(SENSORS_ACTIVE, MPU_9250_SENSOR_TYPE_ALL); -} -#endif -/*---------------------------------------------------------------------------*/ -static void -get_sync_sensor_readings(void) -{ - int value; - - printf("-----------------------------------------\n"); - - value = batmon_sensor.value(BATMON_SENSOR_TYPE_TEMP); - printf("Bat: Temp=%d C\n", value); - - value = batmon_sensor.value(BATMON_SENSOR_TYPE_VOLT); - printf("Bat: Volt=%d mV\n", (value * 125) >> 5); - -#if BOARD_SMARTRF06EB - SENSORS_ACTIVATE(als_sensor); - - value = als_sensor.value(0); - printf("ALS: %d raw\n", value); - - SENSORS_DEACTIVATE(als_sensor); -#endif - - return; -} -/*---------------------------------------------------------------------------*/ -static void -init_sensors(void) -{ - SENSORS_ACTIVATE(batmon_sensor); -} -/*---------------------------------------------------------------------------*/ -static void -init_sensor_readings(void) -{ -#if BOARD_SENSORTAG - SENSORS_ACTIVATE(hdc_1000_sensor); - SENSORS_ACTIVATE(tmp_007_sensor); - SENSORS_ACTIVATE(opt_3001_sensor); - SENSORS_ACTIVATE(bmp_280_sensor); - - init_mpu_reading(NULL); -#endif -} -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(cc26xx_demo_process, ev, data) -{ - - PROCESS_BEGIN(); - - printf("CC26XX demo\n"); - - init_sensors(); - - /* Init the BLE advertisement daemon */ - rf_ble_beacond_start(0, BOARD_STRING); - - etimer_set(&et, CC26XX_DEMO_LOOP_INTERVAL); - get_sync_sensor_readings(); - init_sensor_readings(); - - while(1) { - - PROCESS_YIELD(); - - if(ev == PROCESS_EVENT_TIMER) { - if(data == &et) { - leds_toggle(CC26XX_DEMO_LEDS_PERIODIC); - - get_sync_sensor_readings(); - - etimer_set(&et, CC26XX_DEMO_LOOP_INTERVAL); - } - } else if(ev == button_hal_periodic_event) { - button_hal_button_t *button = data; - - printf("%s periodic event, duration %d seconds\n", - BUTTON_HAL_GET_DESCRIPTION(button), - button->press_duration_seconds); - } else if(ev == button_hal_release_event) { - button_hal_button_t *btn = (button_hal_button_t *)data; - - printf("%s release event\n", BUTTON_HAL_GET_DESCRIPTION(btn)); - - if(btn->unique_id== CC26XX_DEMO_TRIGGER_1) { - leds_toggle(CC26XX_DEMO_LEDS_BUTTON); - } else if(btn->unique_id == CC26XX_DEMO_TRIGGER_2) { - leds_on(CC26XX_DEMO_LEDS_REBOOT); - watchdog_reboot(); -#if BOARD_SENSORTAG - } else if(btn->unique_id == CC26XX_DEMO_TRIGGER_3) { - if(buzzer_state()) { - buzzer_stop(); - } else { - buzzer_start(1000); - } - } - } else if(ev == sensors_event) { - if(data == &bmp_280_sensor) { - get_bmp_reading(); - } else if(data == &opt_3001_sensor) { - get_light_reading(); - } else if(data == &hdc_1000_sensor) { - get_hdc_reading(); - } else if(data == &tmp_007_sensor) { - get_tmp_reading(); - } else if(data == &mpu_9250_sensor) { - get_mpu_reading(); -#endif - } - } - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ -/** - * @} - * @} - * @} - */ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/very-sleepy-demo/Makefile b/examples/platform-specific/simplelink/cc13xx-cc26xx/very-sleepy-demo/Makefile deleted file mode 100644 index 97272c9a7..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/very-sleepy-demo/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -CONTIKI_PROJECT = very-sleepy-demo - -PLATFORMS_ONLY = simplelink - -all: $(CONTIKI_PROJECT) - -MODULES += os/net/app-layer/coap - -CONTIKI = ../../../../.. -include $(CONTIKI)/Makefile.include diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/very-sleepy-demo/README.md b/examples/platform-specific/simplelink/cc13xx-cc26xx/very-sleepy-demo/README.md deleted file mode 100644 index 851150432..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/very-sleepy-demo/README.md +++ /dev/null @@ -1,91 +0,0 @@ -# CC13xx/CC26xx Very Sleepy Demo - -This example demonstrates a way of deploying a very low-consuming, very sleepy -node. The node has two modes of operation: - -* Normal: ContikiMAC duty-cycles the radio as usual. The node is reachable. -* Very Sleepy: Radio cycling mostly off, except when we need to perform network - maintenance tasks. In this mode, the node is unreachable for most of the time. - -The node will operate in RPL leaf mode. This means that it will be reachable -downwards, but it will not advertise the DODAG and it will not participate in -routing. - -After booting, the node will enter "normal" mode. - -The node exposes an OBSERVEable CoAP resource. It will notify subscribers with -a new value for this resource every `interval` seconds. It will then stay in -normal mode for `duration` seconds. During this time window, it will be -reachable over the network in order to e.g. receive a new configuration. -When this time window expires, the node will switch back to very sleepy mode. -This will only happen if very sleepy mode has been enabled by setting `mode=1` -as per the instructions below. - -When the node is duty-cycling the radio, either because it is in normal mode or -because network maintenance is taking place, it will keep its green LED on thus -providing an indication that it is reachable (red LED for the CC1350 tag). - -A normal mode stint can be manually triggered by pressing the left button. - -## Requirements - -To run this example you will need: - -* A border router operating with the same RDC, same channel, same radio mode - (e.g. IEEE or sub-ghz), same PAN ID. Alternatively, you can - use [6lbr](https://github.com/cetic/6lbr) with a suitable slip-radio. -* The [Copper (Cu)](https://addons.mozilla.org/en-US/firefox/addon/copper-270430/) - addon for Firefox - -## Configuration - -To configure the node, send a CoAP POST message to the `very_sleepy_config` -resource. The POST message's payload must specify _at least one_ of: - -* `mode=0|1`: Send `mode=1` to enable very sleepy mode, `mode=0` to disable it. -* `interval=n` where `n` is the number of seconds between two consecutive normal - mode periods. This interval also dictates the OBSERVEr notification period. -* `duration=n` where `n` is the number of seconds that the node will stay in - normal mode before dropping to very sleepy mode. This value is only relevant - if `mode==1`. - -A POST request must contain at least one of the above, but they are otherwise -all optional. So, for example, a POST may simply specify `interval=n`. To send -multiple values, delimit them with `&`. So you can send something like -`mode=1&interval=60&duration=20` - -The current running configuration can be retrieved by sending a GET request to -the same CoAP resource. - -## Running the example - -* Deploy your border router or 6lbr -* Turn on the very sleepy node. -* Fire up the Copper addon -* Select `.well-known/core` and hit `GET` -* Configure very sleepy operation: - * Select the `very_sleepy_config` resource - * In the `Outgoing` pane, type your POST payload as per the instructions - above. For example, you can type: `mode=1&interval=30&duration=10` - * Hit `POST` -* Select the `sen/readings` resource and hit `OBSERVE` - -## Caveats - -If you click on a resource in the Copper resources tree while you are observing -a different resource, the OBSERVEr for the latter will be stopped without -notifying the CoAP server. This will result in the server sending out OBSERVE -notifications that will be responded to with port unreachable ICMPv6 messages. -This will continue for quite a while, until the server detects that the -OBSERVEr has been lost (a test currently performed once every 20 notifications). -In order to prevent this from happening, hit the "Cancel" button for the -OBSERVE before switching views to a different resource. This will unregister -the observer. - -In very sleepy mode, the radio is not truly always off. The contiki core needs -to perform other periodic tasks in order to maintain network connectivity. For -that reason, this example will allow the radio to turn on periodically even -while in very sleepy mode. Thus, you may see that the node becomes briefly -reachable every now and then. However, do not count on those periods of -reachability to perform any tasks, as they will be brief and will be disrupted -without warning. diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/very-sleepy-demo/project-conf.h b/examples/platform-specific/simplelink/cc13xx-cc26xx/very-sleepy-demo/project-conf.h deleted file mode 100644 index 784a0e9ee..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/very-sleepy-demo/project-conf.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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. - */ -/*---------------------------------------------------------------------------*/ -#ifndef PROJECT_CONF_H_ -#define PROJECT_CONF_H_ -/*---------------------------------------------------------------------------*/ -/* Platform configuration */ -#define BOARD_CONF_SENSORS_DISABLE 1 -#define WATCHDOG_CONF_DISABLE 1 -/*---------------------------------------------------------------------------*/ -/* Nestack configuration */ -#define IEEE802154_CONF_PANID 0xABCD -#define IEEE802154_CONF_DEFAULT_CHANNEL 25 -//#define RF_CONF_MODE RF_MODE_SUB_1_GHZ -#define RF_CONF_MODE RF_MODE_2_4_GHZ -#define RF_CONF_BLE_BEACON_ENABLE 0 -/*---------------------------------------------------------------------------*/ -/* TI drivers configuration */ -#define TI_SPI_CONF_ENABLE 0 -#define TI_I2C_CONF_ENABLE 0 -/*---------------------------------------------------------------------------*/ -/* For very sleepy operation */ -#define UIP_DS6_CONF_PERIOD CLOCK_SECOND -#define UIP_CONF_TCP 0 -#define RPL_CONF_LEAF_ONLY 1 - -/* - * We'll fail without RPL probing, so turn it on explicitly even though it's - * on by default - */ -#define RPL_CONF_WITH_PROBING 1 -/*---------------------------------------------------------------------------*/ -#endif /* PROJECT_CONF_H_ */ -/*---------------------------------------------------------------------------*/ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/very-sleepy-demo/very-sleepy-demo.c b/examples/platform-specific/simplelink/cc13xx-cc26xx/very-sleepy-demo/very-sleepy-demo.c deleted file mode 100644 index 711746f7c..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/very-sleepy-demo/very-sleepy-demo.c +++ /dev/null @@ -1,424 +0,0 @@ -/* - * Copyright (c) 2014, 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. - */ -/*---------------------------------------------------------------------------*/ -#include "contiki.h" -#include "sys/etimer.h" -#include "sys/stimer.h" -#include "sys/process.h" -#include "lib/sensors.h" -#include "dev/leds.h" -#include "dev/watchdog.h" -#include "dev/button-hal.h" -#include "net/netstack.h" -#include "net/ipv6/uip-ds6-nbr.h" -#include "net/ipv6/uip-ds6-route.h" -#include "net/routing/routing.h" -#include "net/app-layer/coap/coap.h" -#include "net/app-layer/coap/coap-engine.h" -/*---------------------------------------------------------------------------*/ -#include "board-peripherals.h" -#include "batmon-sensor.h" -/*---------------------------------------------------------------------------*/ -#include -#include -#include -/*---------------------------------------------------------------------------*/ -/* Normal mode duration params in seconds */ -#define NORMAL_OP_DURATION_DEFAULT 10 -#define NORMAL_OP_DURATION_MIN 10 -#define NORMAL_OP_DURATION_MAX 60 -/*---------------------------------------------------------------------------*/ -/* Observer notification period params in seconds */ -#define PERIODIC_INTERVAL_DEFAULT 30 -#define PERIODIC_INTERVAL_MIN 30 -#define PERIODIC_INTERVAL_MAX 86400 /* 1 day */ -/*---------------------------------------------------------------------------*/ -#define VERY_SLEEPY_MODE_OFF 0 -#define VERY_SLEEPY_MODE_ON 1 -/*---------------------------------------------------------------------------*/ -#define BUTTON_TRIGGER BUTTON_HAL_ID_KEY_LEFT -/*---------------------------------------------------------------------------*/ -#define MAC_CAN_BE_TURNED_OFF 0 -#define MAC_MUST_STAY_ON 1 - -#define KEEP_MAC_ON_MIN_PERIOD 10 /* secs */ -/*---------------------------------------------------------------------------*/ -#define PERIODIC_INTERVAL CLOCK_SECOND -/*---------------------------------------------------------------------------*/ -#define POST_STATUS_BAD 0x80 -#define POST_STATUS_HAS_MODE 0x40 -#define POST_STATUS_HAS_DURATION 0x20 -#define POST_STATUS_HAS_INTERVAL 0x10 -#define POST_STATUS_NONE 0x00 -/*---------------------------------------------------------------------------*/ -typedef struct sleepy_config_s { - unsigned long interval; - unsigned long duration; - uint8_t mode; -} sleepy_config_t; - -sleepy_config_t config; -/*---------------------------------------------------------------------------*/ -#define STATE_NORMAL 0 -#define STATE_NOTIFY_OBSERVERS 1 -#define STATE_VERY_SLEEPY 2 -/*---------------------------------------------------------------------------*/ -static struct stimer st_duration; -static struct stimer st_interval; -static struct stimer st_min_mac_on_duration; -static struct etimer et_periodic; -static process_event_t event_new_config; -static uint8_t state; -/*---------------------------------------------------------------------------*/ -const char *not_supported_msg = "Supported:text/plain,application/json"; -/*---------------------------------------------------------------------------*/ -PROCESS(very_sleepy_demo_process, "CC13xx/CC26xx very sleepy process"); -AUTOSTART_PROCESSES(&very_sleepy_demo_process); -/*---------------------------------------------------------------------------*/ -static void -readings_get_handler(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, uint16_t preferred_size, int32_t *offset) -{ - unsigned int accept = -1; - int temp; - int voltage; - - if(request != NULL) { - coap_get_header_accept(request, &accept); - } - - temp = batmon_sensor.value(BATMON_SENSOR_TYPE_TEMP); - - voltage = batmon_sensor.value(BATMON_SENSOR_TYPE_VOLT); - - if(accept == -1 || accept == APPLICATION_JSON) { - coap_set_header_content_format(response, APPLICATION_JSON); - snprintf((char *)buffer, COAP_MAX_CHUNK_SIZE, - "{\"temp\":{\"v\":%d,\"u\":\"C\"}," - "\"voltage\":{\"v\":%d,\"u\":\"mV\"}}", - temp, (voltage * 125) >> 5); - - coap_set_payload(response, buffer, strlen((char *)buffer)); - } else if(accept == TEXT_PLAIN) { - coap_set_header_content_format(response, TEXT_PLAIN); - snprintf((char *)buffer, COAP_MAX_CHUNK_SIZE, "Temp=%dC, Voltage=%dmV", - temp, (voltage * 125) >> 5); - - coap_set_payload(response, buffer, strlen((char *)buffer)); - } else { - coap_set_status_code(response, NOT_ACCEPTABLE_4_06); - coap_set_payload(response, not_supported_msg, - strlen(not_supported_msg)); - } -} -/*---------------------------------------------------------------------------*/ -RESOURCE(readings_resource, "title=\"Sensor Readings\";obs", - readings_get_handler, NULL, NULL, NULL); -/*---------------------------------------------------------------------------*/ -static void -conf_get_handler(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, uint16_t preferred_size, int32_t *offset) -{ - unsigned int accept = -1; - - if(request != NULL) { - coap_get_header_accept(request, &accept); - } - - if(accept == -1 || accept == APPLICATION_JSON) { - coap_set_header_content_format(response, APPLICATION_JSON); - snprintf((char *)buffer, COAP_MAX_CHUNK_SIZE, - "{\"config\":{\"mode\":%u,\"duration\":%lu,\"interval\":%lu}}", - config.mode, config.duration, config.interval); - - coap_set_payload(response, buffer, strlen((char *)buffer)); - } else if(accept == TEXT_PLAIN) { - coap_set_header_content_format(response, TEXT_PLAIN); - snprintf((char *)buffer, COAP_MAX_CHUNK_SIZE, - "Mode=%u, Duration=%lusecs, Interval=%lusecs", - config.mode, config.duration, config.interval); - - coap_set_payload(response, buffer, strlen((char *)buffer)); - } else { - coap_set_status_code(response, NOT_ACCEPTABLE_4_06); - coap_set_payload(response, not_supported_msg, - strlen(not_supported_msg)); - } -} -/*---------------------------------------------------------------------------*/ -static void -conf_post_handler(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, uint16_t preferred_size, int32_t *offset) -{ - const char *ptr = NULL; - char tmp_buf[16]; - unsigned long interval = 0; - unsigned long duration = 0; - uint8_t mode = VERY_SLEEPY_MODE_OFF; - uint8_t post_status = POST_STATUS_NONE; - int rv; - - rv = coap_get_post_variable(request, "mode", &ptr); - if(rv && rv < 16) { - memset(tmp_buf, 0, sizeof(tmp_buf)); - memcpy(tmp_buf, ptr, rv); - rv = atoi(tmp_buf); - - if(rv == 1) { - mode = VERY_SLEEPY_MODE_ON; - post_status |= POST_STATUS_HAS_MODE; - } else if(rv == 0) { - mode = VERY_SLEEPY_MODE_OFF; - post_status |= POST_STATUS_HAS_MODE; - } else { - post_status = POST_STATUS_BAD; - } - } - - rv = coap_get_post_variable(request, "duration", &ptr); - if(rv && rv < 16) { - memset(tmp_buf, 0, sizeof(tmp_buf)); - memcpy(tmp_buf, ptr, rv); - rv = atoi(tmp_buf); - - duration = (unsigned long)rv; - if(duration < NORMAL_OP_DURATION_MIN || duration > NORMAL_OP_DURATION_MAX) { - post_status = POST_STATUS_BAD; - } else { - post_status |= POST_STATUS_HAS_DURATION; - } - } - - rv = coap_get_post_variable(request, "interval", &ptr); - if(rv && rv < 16) { - memset(tmp_buf, 0, sizeof(tmp_buf)); - memcpy(tmp_buf, ptr, rv); - rv = atoi(tmp_buf); - interval = (unsigned long)rv; - if(interval < PERIODIC_INTERVAL_MIN || interval > PERIODIC_INTERVAL_MAX) { - post_status = POST_STATUS_BAD; - } else { - post_status |= POST_STATUS_HAS_INTERVAL; - } - } - - if((post_status & POST_STATUS_BAD) == POST_STATUS_BAD || - post_status == POST_STATUS_NONE) { - coap_set_status_code(response, BAD_REQUEST_4_00); - snprintf((char *)buffer, COAP_MAX_CHUNK_SIZE, - "mode=0|1&duration=[%u,%u]&interval=[%u,%u]", - NORMAL_OP_DURATION_MIN, NORMAL_OP_DURATION_MAX, - PERIODIC_INTERVAL_MIN, PERIODIC_INTERVAL_MAX); - - coap_set_payload(response, buffer, strlen((char *)buffer)); - return; - } - - /* Values are sane. Update the config and notify the process */ - if(post_status & POST_STATUS_HAS_MODE) { - config.mode = mode; - } - - if(post_status & POST_STATUS_HAS_INTERVAL) { - config.interval = interval; - } - - if(post_status & POST_STATUS_HAS_DURATION) { - config.duration = duration; - } - - process_post(&very_sleepy_demo_process, event_new_config, NULL); -} -/*---------------------------------------------------------------------------*/ -RESOURCE(very_sleepy_conf, - "title=\"Very sleepy conf: " - "GET|POST mode=0|1&interval=&duration=\";rt=\"Control\"", - conf_get_handler, conf_post_handler, NULL, NULL); -/*---------------------------------------------------------------------------*/ -/* - * If our preferred parent is not NBR_REACHABLE in the ND cache, NUD will send - * a unicast NS and wait for NA. If NA fails then the neighbour will be removed - * from the ND cache and the default route will be deleted. To prevent this, - * keep the MAC on until the parent becomes NBR_REACHABLE. We also keep the MAC - * on if we are about to do RPL probing. - * - * In all cases, the radio will be locked on for KEEP_MAC_ON_MIN_PERIOD secs - */ -static uint8_t -keep_mac_on(void) -{ - uip_ds6_nbr_t *nbr; - uint8_t rv = MAC_CAN_BE_TURNED_OFF; - - if(!stimer_expired(&st_min_mac_on_duration)) { - return MAC_MUST_STAY_ON; - } - -#if RPL_WITH_PROBING - /* Determine if we are about to send a RPL probe */ - if(CLOCK_LT(etimer_expiration_time( - &rpl_get_default_instance()->dag.probing_timer.etimer), - (clock_time() + PERIODIC_INTERVAL))) { - rv = MAC_MUST_STAY_ON; - } -#endif - - /* It's OK to pass a NULL pointer, the callee checks and returns NULL */ - nbr = uip_ds6_nbr_lookup(uip_ds6_defrt_choose()); - - if(nbr == NULL) { - /* We don't have a default route, or it's not reachable (NUD likely). */ - rv = MAC_MUST_STAY_ON; - } else { - if(nbr->state != NBR_REACHABLE) { - rv = MAC_MUST_STAY_ON; - } - } - - if(rv == MAC_MUST_STAY_ON && stimer_expired(&st_min_mac_on_duration)) { - stimer_set(&st_min_mac_on_duration, KEEP_MAC_ON_MIN_PERIOD); - } - - return rv; -} -/*---------------------------------------------------------------------------*/ -static void -switch_to_normal(void) -{ - state = STATE_NOTIFY_OBSERVERS; - - /* - * Stay in normal mode for 'duration' secs. - * Transition back to normal in 'interval' secs, _including_ 'duration' - */ - stimer_set(&st_duration, config.duration); - stimer_set(&st_interval, config.interval); -} -/*---------------------------------------------------------------------------*/ -static void -switch_to_very_sleepy(void) -{ - state = STATE_VERY_SLEEPY; -} -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(very_sleepy_demo_process, ev, data) -{ - uint8_t mac_keep_on; - - PROCESS_BEGIN(); - - SENSORS_ACTIVATE(batmon_sensor); - - config.mode = VERY_SLEEPY_MODE_OFF; - config.interval = PERIODIC_INTERVAL_DEFAULT; - config.duration = NORMAL_OP_DURATION_DEFAULT; - - state = STATE_NORMAL; - - event_new_config = process_alloc_event(); - - readings_resource.flags += IS_OBSERVABLE; - coap_activate_resource(&readings_resource, "sen/readings"); - coap_activate_resource(&very_sleepy_conf, "very_sleepy_config"); - - printf("Very Sleepy Demo Process\n"); - - switch_to_normal(); - - etimer_set(&et_periodic, PERIODIC_INTERVAL); - - while(1) { - - PROCESS_YIELD(); - - if(ev == button_hal_release_event && - ((button_hal_button_t *)data)->unique_id == BUTTON_TRIGGER) { - switch_to_normal(); - } - - if(ev == event_new_config) { - stimer_set(&st_interval, config.interval); - stimer_set(&st_duration, config.duration); - } - - if((ev == PROCESS_EVENT_TIMER && data == &et_periodic) || - (ev == button_hal_release_event && - ((button_hal_button_t *)data)->unique_id == BUTTON_TRIGGER) || - (ev == event_new_config)) { - - /* - * Determine if the stack is about to do essential network maintenance - * and, if so, keep the MAC layer on - */ - mac_keep_on = keep_mac_on(); - - if(mac_keep_on == MAC_MUST_STAY_ON || state != STATE_VERY_SLEEPY) { - leds_on(LEDS_GREEN); - NETSTACK_MAC.on(); - } - - /* - * Next, switch between normal and very sleepy mode depending on config, - * send notifications to observers as required. - */ - if(state == STATE_NOTIFY_OBSERVERS) { - coap_notify_observers(&readings_resource); - state = STATE_NORMAL; - } - - if(state == STATE_NORMAL) { - if(stimer_expired(&st_duration)) { - stimer_set(&st_duration, config.duration); - if(config.mode == VERY_SLEEPY_MODE_ON) { - switch_to_very_sleepy(); - } - } - } else if(state == STATE_VERY_SLEEPY) { - if(stimer_expired(&st_interval)) { - switch_to_normal(); - } - } - - if(mac_keep_on == MAC_CAN_BE_TURNED_OFF && state == STATE_VERY_SLEEPY) { - leds_off(LEDS_GREEN); - NETSTACK_MAC.off(); - } else { - leds_on(LEDS_GREEN); - NETSTACK_MAC.on(); - } - - /* Schedule next pass */ - etimer_set(&et_periodic, PERIODIC_INTERVAL); - } - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/very-sleepy-demo/very-sleepy-demo.simplelink b/examples/platform-specific/simplelink/cc13xx-cc26xx/very-sleepy-demo/very-sleepy-demo.simplelink deleted file mode 100644 index a405a2444..000000000 Binary files a/examples/platform-specific/simplelink/cc13xx-cc26xx/very-sleepy-demo/very-sleepy-demo.simplelink and /dev/null differ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/Makefile b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/Makefile deleted file mode 100644 index aa310465d..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -CONTIKI_PROJECT = web-demo - -PLATFORMS_ONLY = simplelink - -all: $(CONTIKI_PROJECT) - -MODULES_REL += ./resources - -PROJECT_SOURCEFILES += coap-server.c net-uart.c mqtt-client.c -PROJECT_SOURCEFILES += httpd-simple.c - -ifeq ($(MAKE_ROUTING),MAKE_ROUTING_RPL_CLASSIC) -# 6lbr only supports RPL Classic -PROJECT_SOURCEFILES += cetic-6lbr-client.c -endif - -# REST Engine shall use Erbium CoAP implementation -MODULES += os/net/app-layer/mqtt -MODULES += os/net/app-layer/coap -MODULES += arch/dev/ext-flash - -CONTIKI = ../../../../.. -include $(CONTIKI)/Makefile.include diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/README.md b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/README.md deleted file mode 100644 index 912fcb72a..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/README.md +++ /dev/null @@ -1,185 +0,0 @@ -CC26xx Web Demo Readme -====================== -This demo project combines a number of web-based applications aiming to -demonstrate the CC26xx capability. The applications are: - -* A network-based UART -* A client for [6lbr](http://cetic.github.io/6lbr/) -* A CoAP server -* An MQTT client -* A web server which can be used to display sensor readings but also to - configure MQTT functionality - -The example has been configured to run for all CC26xx-based boards. - -To change between target boards, follow the instructions in the wiki. -Do not forget to `make clean` when switching between the boards. - -Specifically for some older CC2650 SensorTags, you may also need to change -`project-conf.h` such that `SENSORTAG_CC2650_REV_1_2_0` is defined as 1. To -check if your sensortag is one of those older ones, look for "REV: 1.2" -printed on the PCB. There may also be a sticker that reads "HW Rev 1.2.0". An -indication that you may need to do this is if you get a "Could not open flash -to load config" error on device startup. - -You can disable some of those individual components by changing the respective -defines in `project-conf.h`. For instance, to disable the CoAP functionality, -set `#define CC26XX_WEB_DEMO_CONF_COAP_SERVER 0`. The web server cannot be -disabled, all other aforementioned applications can. - -Network UART (net-uart) ------------------------ -This example only makes sense if you are using the Srf or if you have taken -the sensortag out of its case and you have it connected over JTAG to the Srf. - -The net-uart does two things: - -* When you type a string to the UART console, the string will be sent verbatim - to a remote UDP port 7777 listener. This can be for example a netcat listener - on a linux or OS X PC: - `nc -6ulkw 1 7777` -* The net-uart also listens to UDP port 7777 and when it receives a string over - UDP, it will print it verbatim over UART. - -The example will initially send packets to a hard-coded IPv6 address. This can -be changed very easily by entering a different IPv6 address to the console. -Thus, when the serial input string is an IPv6 address, it will not be sent as -any other string would, but instead it will configure the example to send to a -different remote address. This new IPv6 address is not persistent across -device reboots. - -6lbr Client ------------ -This will periodically send a UDP packet to your 6lbr, containing network -information, which will be used by 6lbr to construct a network graph. To see -this in action, fire up a browser and navigate to the 6lbr web page. The -default address is http://[bbbb::100]. Once the page loads, click the 'sensors' -tab, as per the image below. - -![6lbr](img/6lbr-web.png) - -CoAP Server ------------ -For this functionality to work, you will need to install a CoAP client. -You can achieve this by following the guides on how to set up your system -[in the wiki](https://github.com/contiki-ng/contiki-ng/wiki#setting-up-contiki-ng). - -You should start by sending a CoAP GET request for the `.well-known/core` -resource. If you are using libcoap's CoAP client, this can be achieved by: - -``` -coap-client -m get coap://[]/.well-known/core -``` - -Adjust the above command to match the command line arguments of your CoAP -client. - -The Device will respond with a list of all available CoAP resources. This list -will be different between the various CC13x0/CC26x0 boards. - -Send a CoAP GET request for any of those resrouces to retrieve its value. - -Send a CoAP POST to the `lt/g` or `lt/r` to toggle the green/red LED -respectively. - -You can also use CoAP to enable/disable BLE advertisements! This can be done -by sending a PUT or POST request to the `dev/ble_advd` resource. Your request -should contain the desired payload, which can be: - -* `mode=on|off` -* `name=` -* `interval=` - -or a combination of the above delimited with an amp. For example, you can set -as payload `mode=on&name=My CC26xx Device 4&interval=5`. - -Bear in mind that you must set `name` at least once before enabling BLE -advertisements. If you fail to do so, the RF will refuse to enter BLE mode and -the CoAP engine will return 4.03 forbidden. The values of `name` and `interval` -persist across BLE on/off cycles, so you only have to set them once. The values -do _not_ persist through device powercycles. - -HTTPD ------ -Back on the 6lbr page, hit the 'web' link corresponding to your device. This -will take you to a web page served by the CC26xx. The HTTPD serves two pages: - -* index.html: Provides sensor readings and network information -* config.html: Can be used to configure the MQTT client (more below) - -In the navigation bar at the top there is also a third link, which will take -you directly to your device's page on IBM's quickstart service. - -IBM Quickstart / MQTT Client ----------------------------- -The MQTT client can be used to: - -* Publish sensor readings to an MQTT broker. -* Subscribe to a topic and as a result receive commands from an MQTT broker - -The device will try to connect to IBM's quickstart over NAT64, so you will -need a NAT64 gateway in your network to make this work. A guide on how to -setup NAT64 is out of scope here. If this is not an option for you, you can -configure the device to publish to a local MQTT broker over end-to-end IPv6. -See below on how to change the destination broker's address. - -By default the device will publish readings to IBM's quickstart service. The -publish messages include sensor readings but also some other information such -as device uptime in seconds and a message sequence number. Click the "IBM -Quickstart" link in the web page to go directly to your device's page -on Quickstart. After a few seconds, you will see something like this: - -![A SensorTag on IBM Quickstart](img/quickstart-sensortag.png) - -Sensor readings are only published if they have changed since the previous -reading (BatMon is an exception and always gets published). Additionally, you -can turn on/off individual readings from the config.html web page, as per the -figure below. - -![Sensor Readings Configuration](img/sensor-readings-config.png) - -Some of the MQTT client functionality can be configured even further: - -* You can change the broker IP and port. This is useful if you want to use your - own MQTT broker instead of IBM's quickstart. The example has been tested - successfully with [mosquitto](http://mosquitto.org/) -* You can change the publish interval. Recommended values are 10secs or higher. - You will not be allowed to set this to anything less than 5 seconds. -* If you want to use IBM's cloud service with a registered device, change - 'Org ID' and provide an 'Auth Token', which acts as a 'password', but bear in - mind that it gets transported in clear text, both over the web configuration - page as well as inside MQTT messages. -* The remaining configuration options are related to the content of MQTT - messages and in general you won't have to modify them. - -For the SensorTag, changes to the MQTT configuration get saved in external -flash and persist across device restarts. The same does not hold true for -Srf+EM builds. - -You can also subscribe to topics and receive commands, but this will only -work if you use "Org ID" != 'quickstart'. Thus, if you provide a different -Org ID (do not forget the auth token!), the device will subscribe to: - -`iot-2/cmd/+/fmt/json` - -You can then use this to toggle LEDs or to turn the buzzer on and off. -The buzzer is only available on the SensorTag. To do this, you can for example -use mosquitto client to publish to `iot-2/cmd/leds/fmt/json`. So, to turn -the buzzer on, you would do this: - -`mosquitto_pub -h -m "1" -t iot-2/cmd/buzz/fmt/json` - -Where `broker IP` should be replaced with the IP address of your mosquitto -broker (the one where you device has subscribed). Replace `-m "1'` with `-m "0"` -to turn the buzzer back off. Replace `buzz` with `leds` in the topic to change -the state of the LED. - -Bear in mind that, even though the topic suggests that messages are of json -format, they are in fact not. This was done in order to avoid linking a json -parser into the firmware. - -IBM Watson IoT Platform ----------------------------- -To use IBM Watson IoT Platform, you have to go to SECURITY tab of Device page to select "TLS Optional". This step is critical. If you don't do this, you need to use TLS for connection and default cc26xx-web-demo won't work. - -![IBM Watson IoT Platform TLS Optional Configuration](img/ibm-watson-iot-platform-tls-optional.png) diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/cetic-6lbr-client.c b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/cetic-6lbr-client.c deleted file mode 100644 index 7c4cbdfff..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/cetic-6lbr-client.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * 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. - */ -/** - * \addtogroup cc13xx-cc26xx-web-demo - * @{ - * - * \file - * An implementation of a 6LBR UDP client. Is used to populate the 6LBR - * web server's 'sensors' tab - */ -/*---------------------------------------------------------------------------*/ -#include "contiki.h" -#include "contiki-lib.h" -#include "contiki-net.h" -#include "net/ipv6/uip.h" -#include "net/routing/routing.h" -#include "net/routing/rpl-classic/rpl.h" -#include "net/routing/rpl-classic/rpl-private.h" -/*---------------------------------------------------------------------------*/ -#include -#include -/*---------------------------------------------------------------------------*/ -#define DEBUG 0 -#include "net/ipv6/uip-debug.h" -/*---------------------------------------------------------------------------*/ -#if (ROUTING_CONF_RPL_CLASSIC == 0) -#error "The 6LBR client is only meant for RPL Classic. Set MAKE_ROUTING accordingly." -#endif -/*---------------------------------------------------------------------------*/ -#ifndef CETIC_6LBR_NODE_INFO_PORT -#define CETIC_6LBR_NODE_INFO_PORT 3000 -#endif - -#define MAX_PAYLOAD_LEN 40 -#define MSG_INTERVAL (60 * CLOCK_SECOND) -/*---------------------------------------------------------------------------*/ -static struct uip_udp_conn *client_conn = NULL; -static struct etimer et; -static uip_ip6addr_t dest_addr; -/*---------------------------------------------------------------------------*/ -PROCESS(cetic_6lbr_client_process, "6LBR Client Process"); -/*---------------------------------------------------------------------------*/ -static void -tcpip_handler(void) -{ - char *str; - - if(uip_newdata()) { - str = uip_appdata; - str[uip_datalen()] = '\0'; - PRINTF("Response from the server: '%s'\n", str); - } -} -/*---------------------------------------------------------------------------*/ -static char * -add_ipaddr(char *buf, const uip_ipaddr_t *addr) -{ - uint16_t a; - unsigned int i; - int f; - char *p = buf; - - for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) { - a = (addr->u8[i] << 8) + addr->u8[i + 1]; - if(a == 0 && f >= 0) { - if(f++ == 0) { - p += sprintf(p, "::"); - } - } else { - if(f > 0) { - f = -1; - } else if(i > 0) { - p += sprintf(p, ":"); - } - p += sprintf(p, "%04x", a); - } - } - return p; -} -/*---------------------------------------------------------------------------*/ -static void -timeout_handler(void) -{ - static int seq_id; - char buf[MAX_PAYLOAD_LEN]; - int i; - uip_ip6addr_t *globaladdr = NULL; - uint16_t dest_port = CETIC_6LBR_NODE_INFO_PORT; - int has_dest = 0; - rpl_instance_t *instance; - rpl_dag_t *dag; - - uip_ds6_addr_t *addr_desc = uip_ds6_get_global(ADDR_PREFERRED); - if(addr_desc != NULL) { - globaladdr = &addr_desc->ipaddr; - dag = rpl_get_any_dag(); - if(dag) { - uip_ipaddr_copy(&dest_addr, globaladdr); - memcpy(&dest_addr.u8[8], &dag->dag_id.u8[8], sizeof(uip_ipaddr_t) / 2); - has_dest = 1; - } - } - - if(has_dest) { - if(client_conn == NULL) { - PRINTF("UDP-CLIENT: address destination: "); - PRINT6ADDR(&dest_addr); - PRINTF("\n"); - client_conn = udp_new(&dest_addr, UIP_HTONS(dest_port), NULL); - - if(client_conn != NULL) { - 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)); - } else { - PRINTF("Could not open connection\n"); - } - } else { - if(memcmp(&client_conn->ripaddr, &dest_addr, sizeof(uip_ipaddr_t)) != 0) { - PRINTF("UDP-CLIENT: new address destination: "); - PRINT6ADDR(&dest_addr); - PRINTF("\n"); - uip_udp_remove(client_conn); - client_conn = udp_new(&dest_addr, UIP_HTONS(dest_port), NULL); - if(client_conn != NULL) { - 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)); - } else { - PRINTF("Could not open connection\n"); - } - } - } - if(client_conn != NULL) { - PRINTF("Client sending to: "); - PRINT6ADDR(&client_conn->ripaddr); - i = sprintf(buf, "%d | ", ++seq_id); - instance = rpl_get_default_instance(); - if(instance && instance->current_dag->preferred_parent) { - add_ipaddr(buf + i, rpl_parent_get_ipaddr(instance->current_dag->preferred_parent)); - } else { - sprintf(buf + i, "(null)"); - } - PRINTF(" (msg: %s)\n", buf); - uip_udp_packet_send(client_conn, buf, strlen(buf)); - } else { - PRINTF("No connection created\n"); - } - } else { - PRINTF("No address configured\n"); - } -} -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(cetic_6lbr_client_process, ev, data) -{ - - PROCESS_BEGIN(); - - printf("6LBR Client Process\n"); - - memset(&dest_addr, 0, sizeof(uip_ipaddr_t)); - - etimer_set(&et, MSG_INTERVAL); - while(1) { - PROCESS_YIELD(); - if(etimer_expired(&et)) { - timeout_handler(); - etimer_set(&et, MSG_INTERVAL); - } else if(ev == tcpip_event) { - tcpip_handler(); - } - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ -/** - * @} - */ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/coap-server.c b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/coap-server.c deleted file mode 100644 index 5a53fb1ae..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/coap-server.c +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2014, 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 cc13xx-cc26xx-web-demo - * @{ - * - * \file - * A CC13xx/CC26xx-specific CoAP server - */ -/*---------------------------------------------------------------------------*/ -#include "contiki.h" -#include "contiki-net.h" -#include "net/app-layer/coap/coap-engine.h" -/*---------------------------------------------------------------------------*/ -#include "board-peripherals.h" -#include "rf/ble-beacond.h" -/*---------------------------------------------------------------------------*/ -#include "web-demo.h" -/*---------------------------------------------------------------------------*/ -#include -#include -#include -/*---------------------------------------------------------------------------*/ -/* Common resources */ -extern coap_resource_t res_leds; - -extern coap_resource_t res_batmon_temp; -extern coap_resource_t res_batmon_volt; - -extern coap_resource_t res_device_sw; -extern coap_resource_t res_device_hw; -extern coap_resource_t res_device_uptime; -extern coap_resource_t res_device_cfg_reset; - -extern coap_resource_t res_parent_rssi; -extern coap_resource_t res_parent_ip; - -#if RF_CONF_BLE_BEACON_ENABLE -extern coap_resource_t res_ble_advd; -#endif - -extern coap_resource_t res_toggle_red; -extern coap_resource_t res_toggle_green; - -/* Board-specific resources */ -#if BOARD_SENSORTAG -extern coap_resource_t res_bmp280_temp; -extern coap_resource_t res_bmp280_press; -extern coap_resource_t res_tmp007_amb; -extern coap_resource_t res_tmp007_obj; -extern coap_resource_t res_hdc1000_temp; -extern coap_resource_t res_hdc1000_hum; -extern coap_resource_t res_opt3001_light; -extern coap_resource_t res_mpu_acc_x; -extern coap_resource_t res_mpu_acc_y; -extern coap_resource_t res_mpu_acc_z; -extern coap_resource_t res_mpu_gyro_x; -extern coap_resource_t res_mpu_gyro_y; -extern coap_resource_t res_mpu_gyro_z; -#else -extern coap_resource_t res_toggle_orange; -extern coap_resource_t res_toggle_yellow; -#endif - -#if WEB_DEMO_ADC_DEMO -extern coap_resource_t res_adc_dio23; -#endif -/*---------------------------------------------------------------------------*/ -const char *coap_server_not_found_msg = "Resource not found"; -const char *coap_server_supported_msg = "Supported:" - "text/plain," - "application/json," - "application/xml"; -/*---------------------------------------------------------------------------*/ -static void -start_board_resources(void) -{ - - coap_activate_resource(&res_toggle_green, "lt/g"); - coap_activate_resource(&res_toggle_red, "lt/r"); - coap_activate_resource(&res_leds, "lt"); - -#if BOARD_SENSORTAG - coap_activate_resource(&res_bmp280_temp, "sen/bar/temp"); - coap_activate_resource(&res_bmp280_press, "sen/bar/pres"); - coap_activate_resource(&res_tmp007_amb, "sen/tmp/amb"); - coap_activate_resource(&res_tmp007_obj, "sen/tmp/obj"); - coap_activate_resource(&res_hdc1000_temp, "sen/hdc/t"); - coap_activate_resource(&res_hdc1000_hum, "sen/hdc/h"); - coap_activate_resource(&res_opt3001_light, "sen/opt/light"); - coap_activate_resource(&res_mpu_acc_x, "sen/mpu/acc/x"); - coap_activate_resource(&res_mpu_acc_y, "sen/mpu/acc/y"); - coap_activate_resource(&res_mpu_acc_z, "sen/mpu/acc/z"); - coap_activate_resource(&res_mpu_gyro_x, "sen/mpu/gyro/x"); - coap_activate_resource(&res_mpu_gyro_y, "sen/mpu/gyro/y"); - coap_activate_resource(&res_mpu_gyro_z, "sen/mpu/gyro/z"); -#elif BOARD_SMARTRF06EB - coap_activate_resource(&res_toggle_yellow, "lt/y"); - coap_activate_resource(&res_toggle_orange, "lt/o"); -#endif -} -/*---------------------------------------------------------------------------*/ -PROCESS(coap_server_process, "CC13xx/CC26xx CoAP Server"); -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(coap_server_process, ev, data) -{ - PROCESS_BEGIN(); - - printf("CC13xx/CC26xx CoAP Server\n"); - - coap_activate_resource(&res_batmon_temp, "sen/batmon/temp"); - coap_activate_resource(&res_batmon_volt, "sen/batmon/voltage"); - -#if WEB_DEMO_ADC_DEMO - coap_activate_resource(&res_adc_dio23, "sen/adc/dio23"); -#endif - - coap_activate_resource(&res_device_hw, "dev/mdl/hw"); - coap_activate_resource(&res_device_sw, "dev/mdl/sw"); - coap_activate_resource(&res_device_uptime, "dev/uptime"); - coap_activate_resource(&res_device_cfg_reset, "dev/cfg_reset"); - - coap_activate_resource(&res_parent_rssi, "net/parent/RSSI"); - coap_activate_resource(&res_parent_ip, "net/parent/IPv6"); - -#if RF_CONF_BLE_BEACON_ENABLE - coap_activate_resource(&res_ble_advd, "dev/ble_advd"); -#endif - - start_board_resources(); - - /* Define application-specific events here. */ - while(1) { - PROCESS_WAIT_EVENT(); - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ -/** - * @} - */ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/coap-server.h b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/coap-server.h deleted file mode 100644 index 839928871..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/coap-server.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2014, 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 cc13xx-cc26xx-web-demo - * @{ - * - * \file - * Header file for the CC13xx/CC26xx web demo CoAP functionality - */ -/*---------------------------------------------------------------------------*/ -#include "sys/process.h" -/*---------------------------------------------------------------------------*/ -#ifndef COAP_SERVER_H_ -#define COAP_SERVER_H_ -/*---------------------------------------------------------------------------*/ -extern const char *coap_server_not_found_msg; -extern const char *coap_server_supported_msg; -/*---------------------------------------------------------------------------*/ -PROCESS_NAME(coap_server_process); -/*---------------------------------------------------------------------------*/ -#endif /* COAP_SERVER_H_ */ -/*---------------------------------------------------------------------------*/ -/** - * @} - */ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/httpd-simple.c b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/httpd-simple.c deleted file mode 100644 index 46f247ac8..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/httpd-simple.c +++ /dev/null @@ -1,1351 +0,0 @@ -/* - * Copyright (c) 2010, Swedish Institute of Computer Science. - * Copyright (c) 2014, 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 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. - * - */ -/** - * \addtogroup cc13xx-cc26xx-web-demo - * @{ - * - * \file - * A simple web server which displays network and sensor information - */ -/*---------------------------------------------------------------------------*/ -#include "contiki.h" -#include "net/ipv6/uip-ds6-route.h" -#include "lib/sensors.h" -#include "lib/list.h" -/*---------------------------------------------------------------------------*/ -#include "batmon-sensor.h" -/*---------------------------------------------------------------------------*/ -#include "web-demo.h" -#include "mqtt-client.h" -#include "httpd-simple.h" -#include "net-uart.h" -/*---------------------------------------------------------------------------*/ -#include -#include -#include -#include -#include -#include -#include -#include -/*---------------------------------------------------------------------------*/ -#define SEND_STRING(s, str) PSOCK_SEND(s, (uint8_t *)str, strlen(str)) -/*---------------------------------------------------------------------------*/ -#define CONNS 2 -#define CONTENT_LENGTH_MAX 256 -#define STATE_WAITING 0 -#define STATE_OUTPUT 1 -#define IPADDR_BUF_LEN 64 -/*---------------------------------------------------------------------------*/ -#define RETURN_CODE_OK 0 -#define RETURN_CODE_NF 1 /* Not Found */ -#define RETURN_CODE_SU 2 /* Service Unavailable */ -#define RETURN_CODE_BR 3 /* Bad Request */ -#define RETURN_CODE_LR 4 /* Length Required */ -#define RETURN_CODE_TL 5 /* Content Length too Large */ -/*---------------------------------------------------------------------------*/ -/* POST request machine states */ -#define PARSE_POST_STATE_INIT 0 -#define PARSE_POST_STATE_MORE 1 -#define PARSE_POST_STATE_READING_KEY 2 -#define PARSE_POST_STATE_READING_VAL 3 -#define PARSE_POST_STATE_ERROR 0xFFFFFFFF -/*---------------------------------------------------------------------------*/ -#define PARSE_POST_BUF_SIZES 64 - -/* Last byte always used to null terminate */ -#define PARSE_POST_MAX_POS (PARSE_POST_BUF_SIZES - 2) - -static char key[PARSE_POST_BUF_SIZES]; -static char val_escaped[PARSE_POST_BUF_SIZES]; -static char val[PARSE_POST_BUF_SIZES]; -static int key_len; -static int val_len; -static int state; -/*---------------------------------------------------------------------------*/ -/* Stringified min/max intervals */ -#define STRINGIFY(x) XSTR(x) -#define XSTR(x) #x - -#define RSSI_INT_MAX STRINGIFY(WEB_DEMO_RSSI_MEASURE_INTERVAL_MAX) -#define RSSI_INT_MIN STRINGIFY(WEB_DEMO_RSSI_MEASURE_INTERVAL_MIN) -#define PUB_INT_MAX STRINGIFY(MQTT_CLIENT_PUBLISH_INTERVAL_MAX) -#define PUB_INT_MIN STRINGIFY(MQTT_CLIENT_PUBLISH_INTERVAL_MIN) -/*---------------------------------------------------------------------------*/ -/* - * We can only handle a single POST request at a time. Since a second POST - * request cannot interrupt us while obtaining a lock, we don't really need - * this lock to be atomic. - * - * An HTTP connection will first request a lock before it starts processing - * a POST request. We maintain a global lock which is either NULL or points - * to the http conn which currently has the lock - */ -static struct httpd_state *lock; -/*---------------------------------------------------------------------------*/ -PROCESS(httpd_simple_process, "CC13xx/CC26xx Web Server"); -/*---------------------------------------------------------------------------*/ -#define ISO_nl 0x0A -#define ISO_space 0x20 -#define ISO_slash 0x2F -#define ISO_amp 0x26 -#define ISO_column 0x3A -#define ISO_equal 0x3D -/*---------------------------------------------------------------------------*/ -#define HTTP_200_OK "HTTP/1.0 200 OK\r\n" -#define HTTP_302_FO "HTTP/1.0 302 Found\r\n" -#define HTTP_400_BR "HTTP/1.0 400 Bad Request\r\n" -#define HTTP_404_NF "HTTP/1.0 404 Not Found\r\n" -#define HTTP_411_LR "HTTP/1.0 411 Length Required\r\n" -#define HTTP_413_TL "HTTP/1.0 413 Request Entity Too Large\r\n" -#define HTTP_503_SU "HTTP/1.0 503 Service Unavailable\r\n" -#define CONN_CLOSE "Connection: close\r\n" -/*---------------------------------------------------------------------------*/ -#define SECTION_TAG "div" -#define SECTION_OPEN "<" SECTION_TAG ">" -#define SECTION_CLOSE "" - -#define CONTENT_OPEN "
"
-#define CONTENT_CLOSE "
" -/*---------------------------------------------------------------------------*/ -#define REQUEST_TYPE_GET 1 -#define REQUEST_TYPE_POST 2 -/*---------------------------------------------------------------------------*/ -static const char *NOT_FOUND = "" - "
" - "

404 - file not found

" - "
" - "" - ""; -/*---------------------------------------------------------------------------*/ -/* Page template */ -static const char http_doctype[] = ""; -static const char http_header_200[] = HTTP_200_OK; -static const char http_header_302[] = HTTP_302_FO; -static const char http_header_400[] = HTTP_400_BR; -static const char http_header_404[] = HTTP_404_NF; -static const char http_header_411[] = HTTP_411_LR; -static const char http_header_413[] = HTTP_413_TL; -static const char http_header_503[] = HTTP_503_SU; -static const char http_get[] = "GET "; -static const char http_post[] = "POST "; -static const char http_index_html[] = "/index.html"; -static const char http_html_start[] = ""; -static const char *http_header_srv_str[] = { - "Server: Contiki, ", - BOARD_STRING "\r\n", - NULL -}; - -static const char *http_header_con_close[] = { - CONN_CLOSE, - NULL -}; - -static const char *http_config_css[] = { - "", - NULL -}; -static const char http_head_charset[] = ""; -static const char http_title_start[] = ""; -static const char http_title_end[] = ""; -static const char http_head_end[] = ""; -static const char http_body_start[] = ""; -static const char http_bottom[] = ""; -/*---------------------------------------------------------------------------*/ -static const char http_content_type_html[] = "text/html"; -static const char http_content_type_plain[] = "text/plain"; -/*---------------------------------------------------------------------------*/ -/* For the config page */ -static const char config_div_left[] = "
"; -static const char config_div_right[] = "
"; -static const char config_div_close[] = "
"; -/*---------------------------------------------------------------------------*/ -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 WEB_DEMO_NET_UART -static char generate_net_uart_config(struct httpd_state *s); - -static page_t http_net_cfg_page = { - NULL, - "netu.html", - "Net-UART Config", - generate_net_uart_config, -}; -#endif - -#if 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 -/*---------------------------------------------------------------------------*/ -#define IBM_QUICKSTART_LINK_LEN 128 -static char http_mqtt_a[IBM_QUICKSTART_LINK_LEN]; -/*---------------------------------------------------------------------------*/ -static uint16_t numtimes; -static const httpd_simple_post_handler_t *handler; -/*---------------------------------------------------------------------------*/ -static uint8_t config_ok; -process_event_t httpd_simple_event_new_config; -/*---------------------------------------------------------------------------*/ -struct httpd_state; -typedef char (*httpd_simple_script_t)(struct httpd_state *s); - -struct httpd_state { - char buf[HTTPD_SIMPLE_MAIN_BUF_SIZE]; - char tmp_buf[TMP_BUF_SIZE]; - struct timer timer; - struct psock sin, sout; - int blen; - const char **ptr; - const web_demo_sensor_reading_t *reading; - const page_t *page; - uip_ds6_route_t *r; - uip_ds6_nbr_t *nbr; - httpd_simple_script_t script; - int content_length; - int tmp_buf_len; - int tmp_buf_copied; - char filename[HTTPD_PATHLEN]; - char inputbuf[HTTPD_INBUF_LEN]; - struct pt outputpt; - struct pt generate_pt; - struct pt top_matter_pt; - char state; - char request_type; - char return_code; -}; -/*---------------------------------------------------------------------------*/ -LIST(post_handlers); -LIST(pages_list); -MEMB(conns, struct httpd_state, CONNS); -/*---------------------------------------------------------------------------*/ -#define HEX_TO_INT(x) (isdigit(x) ? x - '0' : x - 'W') -static size_t -url_unescape(const char *src, size_t srclen, char *dst, size_t dstlen) -{ - size_t i, j; - int a, b; - - for(i = j = 0; i < srclen && j < dstlen - 1; i++, j++) { - if(src[i] == '%' && isxdigit(*(unsigned char *)(src + i + 1)) - && isxdigit(*(unsigned char *)(src + i + 2))) { - a = tolower(*(unsigned char *)(src + i + 1)); - b = tolower(*(unsigned char *)(src + i + 2)); - dst[j] = ((HEX_TO_INT(a) << 4) | HEX_TO_INT(b)) & 0xff; - i += 2; - } else if(src[i] == '+') { - dst[j] = ' '; - } else { - dst[j] = src[i]; - } - } - - dst[j] = '\0'; - - return i == srclen; -} -/*---------------------------------------------------------------------------*/ -void -httpd_simple_register_post_handler(httpd_simple_post_handler_t *h) -{ - list_add(post_handlers, h); -} -/*---------------------------------------------------------------------------*/ -static void -get_neighbour_state_text(char *buf, uint8_t state) -{ - switch(state) { - case NBR_INCOMPLETE: - memcpy(buf, "INCOMPLETE", strlen("INCOMPLETE")); - break; - case NBR_REACHABLE: - memcpy(buf, "REACHABLE", strlen("REACHABLE")); - break; - case NBR_STALE: - memcpy(buf, "STALE", strlen("STALE")); - break; - case NBR_DELAY: - memcpy(buf, "DELAY", strlen("DELAY")); - break; - case NBR_PROBE: - memcpy(buf, "NBR_PROBE", strlen("NBR_PROBE")); - break; - } -} -/*---------------------------------------------------------------------------*/ -static -PT_THREAD(enqueue_chunk(struct httpd_state *s, uint8_t immediate, - const char *format, ...)) -{ - va_list ap; - - PSOCK_BEGIN(&s->sout); - - va_start(ap, format); - - s->tmp_buf_len = vsnprintf(s->tmp_buf, TMP_BUF_SIZE, format, ap); - - va_end(ap); - - if(s->blen + s->tmp_buf_len < HTTPD_SIMPLE_MAIN_BUF_SIZE) { - /* Enough space for the entire chunk. Copy over */ - memcpy(&s->buf[s->blen], s->tmp_buf, s->tmp_buf_len); - s->blen += s->tmp_buf_len; - } else { - memcpy(&s->buf[s->blen], s->tmp_buf, HTTPD_SIMPLE_MAIN_BUF_SIZE - s->blen); - s->tmp_buf_copied = HTTPD_SIMPLE_MAIN_BUF_SIZE - s->blen; - s->blen = HTTPD_SIMPLE_MAIN_BUF_SIZE; - PSOCK_SEND(&s->sout, (uint8_t *)s->buf, s->blen); - s->blen = 0; - if(s->tmp_buf_copied < s->tmp_buf_len) { - memcpy(s->buf, &s->tmp_buf[s->tmp_buf_copied], - s->tmp_buf_len - s->tmp_buf_copied); - s->blen += s->tmp_buf_len - s->tmp_buf_copied; - } - } - - if(immediate != 0 && s->blen > 0) { - PSOCK_SEND(&s->sout, (uint8_t *)s->buf, s->blen); - s->blen = 0; - } - - PSOCK_END(&s->sout); -} -/*---------------------------------------------------------------------------*/ -static -PT_THREAD(generate_top_matter(struct httpd_state *s, const char *title, - const char **css)) -{ - - PT_BEGIN(&s->top_matter_pt); - - PT_WAIT_THREAD(&s->top_matter_pt, enqueue_chunk(s, 0, http_doctype)); - PT_WAIT_THREAD(&s->top_matter_pt, enqueue_chunk(s, 0, http_html_start)); - PT_WAIT_THREAD(&s->top_matter_pt, enqueue_chunk(s, 0, http_title_start)); - - PT_WAIT_THREAD(&s->top_matter_pt, enqueue_chunk(s, 0, title)); - PT_WAIT_THREAD(&s->top_matter_pt, enqueue_chunk(s, 0, http_title_end)); - - if(css != NULL) { - for(s->ptr = css; *(s->ptr) != NULL; s->ptr++) { - PT_WAIT_THREAD(&s->top_matter_pt, enqueue_chunk(s, 0, *(s->ptr))); - } - } - - PT_WAIT_THREAD(&s->top_matter_pt, enqueue_chunk(s, 0, http_head_charset)); - PT_WAIT_THREAD(&s->top_matter_pt, enqueue_chunk(s, 0, http_head_end)); - PT_WAIT_THREAD(&s->top_matter_pt, enqueue_chunk(s, 0, http_body_start)); - - /* Links */ - PT_WAIT_THREAD(&s->top_matter_pt, - enqueue_chunk(s, 0, SECTION_OPEN "

")); - - s->page = list_head(pages_list); - PT_WAIT_THREAD(&s->top_matter_pt, - enqueue_chunk(s, 0, "[ %s ]", - 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, " | [ %s ]", - s->page->filename, s->page->title)); - } - -#if WEB_DEMO_MQTT_CLIENT - PT_WAIT_THREAD(&s->top_matter_pt, - enqueue_chunk(s, 0, " | %s", http_mqtt_a)); -#endif - PT_WAIT_THREAD(&s->top_matter_pt, - enqueue_chunk(s, 0, "

" SECTION_CLOSE)); - - PT_END(&s->top_matter_pt); -} -/*---------------------------------------------------------------------------*/ -static -PT_THREAD(generate_index(struct httpd_state *s)) -{ - char ipaddr_buf[IPADDR_BUF_LEN]; /* Intentionally on stack */ - - PT_BEGIN(&s->generate_pt); - - /* Generate top matter (doctype, title, nav links etc) */ - PT_WAIT_THREAD(&s->generate_pt, - generate_top_matter(s, http_index_page.title, NULL)); - - /* ND Cache */ - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, SECTION_OPEN "Neighbors" CONTENT_OPEN)); - - for(s->nbr = nbr_table_head(ds6_neighbors); s->nbr != NULL; - s->nbr = nbr_table_next(ds6_neighbors, s->nbr)) { - - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, "\n")); - - memset(ipaddr_buf, 0, IPADDR_BUF_LEN); - web_demo_ipaddr_sprintf(ipaddr_buf, IPADDR_BUF_LEN, &s->nbr->ipaddr); - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, "%s", ipaddr_buf)); - - memset(ipaddr_buf, 0, IPADDR_BUF_LEN); - get_neighbour_state_text(ipaddr_buf, s->nbr->state); - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, " %s", ipaddr_buf)); - } - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, CONTENT_CLOSE SECTION_CLOSE)); - - /* Default Route */ - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, - SECTION_OPEN "Default Route" CONTENT_OPEN)); - - memset(ipaddr_buf, 0, IPADDR_BUF_LEN); - web_demo_ipaddr_sprintf(ipaddr_buf, IPADDR_BUF_LEN, - uip_ds6_defrt_choose()); - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, "%s", ipaddr_buf)); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, CONTENT_CLOSE SECTION_CLOSE)); - - /* Routes */ - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, SECTION_OPEN "Routes" CONTENT_OPEN)); - - for(s->r = uip_ds6_route_head(); s->r != NULL; - s->r = uip_ds6_route_next(s->r)) { - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, "\n")); - - memset(ipaddr_buf, 0, IPADDR_BUF_LEN); - web_demo_ipaddr_sprintf(ipaddr_buf, IPADDR_BUF_LEN, &s->r->ipaddr); - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, "%s", ipaddr_buf)); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, " / %u via ", s->r->length)); - - memset(ipaddr_buf, 0, IPADDR_BUF_LEN); - web_demo_ipaddr_sprintf(ipaddr_buf, IPADDR_BUF_LEN, - uip_ds6_route_nexthop(s->r)); - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, "%s", ipaddr_buf)); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, - ", lifetime=%lus", s->r->state.lifetime)); - } - - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, - CONTENT_CLOSE SECTION_CLOSE)); - - /* Sensors */ - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, SECTION_OPEN "Sensors" CONTENT_OPEN)); - - for(s->reading = web_demo_sensor_first(); - s->reading != NULL; s->reading = s->reading->next) { - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "\n%s = %s %s", s->reading->descr, - s->reading->publish ? s->reading->converted : "N/A", - s->reading->units)); - } - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, CONTENT_CLOSE SECTION_CLOSE)); - - /* Footer */ - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, SECTION_OPEN)); - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, "Page hits: %u
", - ++numtimes)); - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, "Uptime: %lu secs
", - clock_seconds())); - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, SECTION_CLOSE)); - - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 1, http_bottom)); - - PT_END(&s->generate_pt); -} -/*---------------------------------------------------------------------------*/ -static -PT_THREAD(generate_config(struct httpd_state *s)) -{ - PT_BEGIN(&s->generate_pt); - - /* Generate top matter (doctype, title, nav links etc) */ - PT_WAIT_THREAD(&s->generate_pt, - generate_top_matter(s, http_dev_cfg_page.title, - http_config_css)); - - /* Sensor Settings */ - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "

Sensors

")); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, - "
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\">")); - - for(s->reading = web_demo_sensor_first(); - s->reading != NULL; s->reading = s->reading->next) { - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%s%s:%s%s", config_div_left, - s->reading->descr, config_div_close, - config_div_right)); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "generate_pt, - enqueue_chunk(s, 0, "title=\"On\" name=\"%s\"%s>", - s->reading->form_field, - s->reading->publish ? " Checked" : "")); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "generate_pt, - enqueue_chunk(s, 0, "title=\"Off\" name=\"%s\"%s>%s", - s->reading->form_field, - s->reading->publish ? "" : " Checked", - config_div_close)); - } - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, - "")); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "
")); - - /* RSSI measurements */ -#if WEB_DEMO_READ_PARENT_RSSI - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "

RSSI Probing

")); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, - "
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, "%sgenerate_pt, - enqueue_chunk(s, 0, "value=\"%lu\" ", - (clock_time_t) - (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, - "")); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "
")); -#endif - - /* Actions */ - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, "

Actions

")); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, - "
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, "")); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "")); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "
")); - - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 1, http_bottom)); - - PT_END(&s->generate_pt); -} -/*---------------------------------------------------------------------------*/ -#if WEB_DEMO_MQTT_CLIENT -static -PT_THREAD(generate_mqtt_config(struct httpd_state *s)) -{ - PT_BEGIN(&s->generate_pt); - - /* Generate top matter (doctype, title, nav links etc) */ - PT_WAIT_THREAD(&s->generate_pt, - generate_top_matter(s, http_mqtt_cfg_page.title, - http_config_css)); - - /* MQTT client settings */ - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "

%s

", http_mqtt_cfg_page.title)); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, - "
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, "%sType ID:%s", config_div_left, - config_div_close)); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%sgenerate_pt, - enqueue_chunk(s, 0, "value=\"%s\" ", - web_demo_config.mqtt_config.type_id)); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "name=\"type_id\">%s", config_div_close)); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%sOrg ID:%s", config_div_left, - config_div_close)); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%sgenerate_pt, - enqueue_chunk(s, 0, "value=\"%s\" ", - web_demo_config.mqtt_config.org_id)); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "name=\"org_id\">%s", config_div_close)); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%sAuth Token:%s", config_div_left, - config_div_close)); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%sgenerate_pt, - enqueue_chunk(s, 0, "value=\"\" ")); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "name=\"auth_token\">%s", - config_div_close)); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%sCommand Type:%s", config_div_left, - config_div_close)); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%sgenerate_pt, - enqueue_chunk(s, 0, "value=\"%s\" ", - web_demo_config.mqtt_config.cmd_type)); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "name=\"cmd_type\">%s", - config_div_close)); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%sEvent Type ID:%s", config_div_left, - config_div_close)); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%sgenerate_pt, - enqueue_chunk(s, 0, "value=\"%s\" ", - web_demo_config.mqtt_config.event_type_id)); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "name=\"event_type_id\">%s", - config_div_close)); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%sInterval (secs):%s", - config_div_left, config_div_close)); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%sgenerate_pt, - enqueue_chunk(s, 0, "value=\"%lu\" ", - (clock_time_t) - (web_demo_config.mqtt_config.pub_interval - / CLOCK_SECOND))); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, - "min=\"" PUB_INT_MIN "\" " - "max=\"" PUB_INT_MAX "\" " - "name=\"interval\">%s", - config_div_close)); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%sBroker IP:%s", config_div_left, - config_div_close)); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%sgenerate_pt, - enqueue_chunk(s, 0, "value=\"%s\" ", - web_demo_config.mqtt_config.broker_ip)); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "name=\"broker_ip\">%s", - config_div_close)); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%sBroker Port:%s", config_div_left, - config_div_close)); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%sgenerate_pt, - enqueue_chunk(s, 0, "value=\"%d\" ", - web_demo_config.mqtt_config.broker_port)); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "min=\"1\" max=\"65535\" " - "name=\"broker_port\">%s", - config_div_close)); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, - "")); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "
")); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, - "
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, "")); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "")); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "
")); - - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 1, http_bottom)); - - PT_END(&s->generate_pt); -} -#endif -/*---------------------------------------------------------------------------*/ -#if WEB_DEMO_NET_UART -static -PT_THREAD(generate_net_uart_config(struct httpd_state *s)) -{ - - PT_BEGIN(&s->generate_pt); - - /* Generate top matter (doctype, title, nav links etc) */ - PT_WAIT_THREAD(&s->generate_pt, - generate_top_matter(s, http_net_cfg_page.title, - http_config_css)); - - /* Net-UART settings */ - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "

%s

", http_net_cfg_page.title)); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, - "
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, "%sRemote IPv6:%s", config_div_left, - config_div_close)); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%sgenerate_pt, - enqueue_chunk(s, 0, "value=\"%s\" ", - web_demo_config.net_uart.remote_address)); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "name=\"net_uart_ip\">%s", - config_div_close)); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%sRemote Port:%s", config_div_left, - config_div_close)); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%sgenerate_pt, - enqueue_chunk(s, 0, "value=\"%u\" ", - web_demo_config.net_uart.remote_port)); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "min=\"1\" max=\"65535\" " - "name=\"net_uart_port\">%s", - config_div_close)); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "%s%s:%s%s", config_div_left, - "Enable", config_div_close, - config_div_right)); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "generate_pt, - enqueue_chunk(s, 0, "title=\"On\" name=\"net_uart_on\"%s>", - web_demo_config.net_uart.enable ? - " Checked" : "")); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "generate_pt, - enqueue_chunk(s, 0, "title=\"Off\" name=\"net_uart_on\"" - "%s>%s", - web_demo_config.net_uart.enable ? - "" : " Checked", config_div_close)); - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, - "")); - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "
")); - - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 1, http_bottom)); - - PT_END(&s->generate_pt); -} -#endif -/*---------------------------------------------------------------------------*/ -static void -lock_obtain(struct httpd_state *s) -{ - if(lock == NULL) { - lock = s; - } -} -/*---------------------------------------------------------------------------*/ -static void -lock_release(struct httpd_state *s) -{ - if(lock == s) { - lock = NULL; - } -} -/*---------------------------------------------------------------------------*/ -static void -parse_post_request_chunk(char *buf, int buf_len, int last_chunk) -{ - int i; - int finish; - - for(i = 0; i < buf_len; i++) { - switch(state) { - case PARSE_POST_STATE_INIT: - state = PARSE_POST_STATE_MORE; - /* continue */ - case PARSE_POST_STATE_MORE: - memset(key, 0, PARSE_POST_BUF_SIZES); - memset(val, 0, PARSE_POST_BUF_SIZES); - memset(val_escaped, 0, PARSE_POST_BUF_SIZES); - key_len = 0; - val_len = 0; - state = PARSE_POST_STATE_READING_KEY; - /* continue */ - case PARSE_POST_STATE_READING_KEY: - if(buf[i] == ISO_equal) { - state = PARSE_POST_STATE_READING_VAL; - } else if(buf[i] == ISO_amp) { - /* Don't accept an amp while reading a key */ - state = PARSE_POST_STATE_ERROR; - } else { - /* Make sure we don't overshoot key's boundary */ - if(key_len <= PARSE_POST_MAX_POS) { - key[key_len] = buf[i]; - key_len++; - } else { - /* Not enough space for the key. Abort */ - state = PARSE_POST_STATE_ERROR; - } - } - break; - case PARSE_POST_STATE_READING_VAL: - finish = 0; - if(buf[i] == ISO_amp) { - finish = 1; - } else if(buf[i] == ISO_equal) { - /* Don't accept an '=' while reading a val */ - state = PARSE_POST_STATE_ERROR; - } else { - /* Make sure we don't overshoot key's boundary */ - if(val_len <= PARSE_POST_MAX_POS) { - val[val_len] = buf[i]; - val_len++; - /* Last character of the last chunk */ - if((i == buf_len - 1) && (last_chunk == 1)) { - finish = 1; - } - } else { - /* Not enough space for the value. Abort */ - state = PARSE_POST_STATE_ERROR; - } - } - - if(finish == 1) { - /* - * Done reading a key=value pair, either because we encountered an amp - * or because we reached the end of the message body. - * - * First, unescape the value. - * - * Then invoke handlers. We will bail out with PARSE_POST_STATE_ERROR, - * unless the key-val gets correctly processed - */ - url_unescape(val, val_len, val_escaped, PARSE_POST_BUF_SIZES); - val_len = strlen(val_escaped); - - for(handler = list_head(post_handlers); handler != NULL; - handler = list_item_next((void *)handler)) { - if(handler->handler != NULL) { - finish = handler->handler(key, key_len, val_escaped, val_len); - } - if(finish == HTTPD_SIMPLE_POST_HANDLER_ERROR) { - state = PARSE_POST_STATE_ERROR; - break; - } else if(finish == HTTPD_SIMPLE_POST_HANDLER_OK) { - /* Restart the state machine to expect the next pair */ - state = PARSE_POST_STATE_MORE; - - /* - * At least one handler returned OK, therefore we must generate a - * new config event when we're done. - */ - config_ok = 1; - break; - } - /* Else, continue */ - } - } - break; - case PARSE_POST_STATE_ERROR: - /* If we entered the error state earlier, do nothing */ - return; - default: - break; - } - } -} -/*---------------------------------------------------------------------------*/ -static httpd_simple_script_t -get_script(const char *name) -{ - 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; -} -/*---------------------------------------------------------------------------*/ -static -PT_THREAD(send_string(struct httpd_state *s, const char *str)) -{ - PSOCK_BEGIN(&s->sout); - - SEND_STRING(&s->sout, str); - - PSOCK_END(&s->sout); -} -/*---------------------------------------------------------------------------*/ -static -PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr, - const char *content_type, const char *redir, - const char **additional)) -{ - PT_BEGIN(&s->generate_pt); - - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, statushdr)); - - for(s->ptr = http_header_srv_str; *(s->ptr) != NULL; s->ptr++) { - 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))); - } - } - - PT_WAIT_THREAD(&s->generate_pt, - enqueue_chunk(s, 0, "Content-type: %s; ", content_type)); - - PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 1, "charset=UTF-8\r\n\r\n")); - - PT_END(&s->generate_pt); -} -/*---------------------------------------------------------------------------*/ -static -PT_THREAD(handle_output(struct httpd_state *s)) -{ - PT_BEGIN(&s->outputpt); - - s->script = NULL; - - PT_INIT(&s->generate_pt); - PT_INIT(&s->top_matter_pt); - - if(s->request_type == REQUEST_TYPE_POST) { - if(s->return_code == RETURN_CODE_OK) { - PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_302, - http_content_type_plain, - 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")); - } - } else if(s->request_type == REQUEST_TYPE_GET) { - s->script = get_script(&s->filename[1]); - if(s->script == NULL) { - 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)); - uip_close(); - PT_EXIT(&s->outputpt); - } 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)); - } - } - s->script = NULL; - PSOCK_CLOSE(&s->sout); - PT_END(&s->outputpt); -} -/*---------------------------------------------------------------------------*/ -static -PT_THREAD(handle_input(struct httpd_state *s)) -{ - PSOCK_BEGIN(&s->sin); - - PSOCK_READTO(&s->sin, ISO_space); - - if(strncasecmp(s->inputbuf, http_get, 4) == 0) { - s->request_type = REQUEST_TYPE_GET; - PSOCK_READTO(&s->sin, ISO_space); - - if(s->inputbuf[0] != ISO_slash) { - PSOCK_CLOSE_EXIT(&s->sin); - } - - if(s->inputbuf[1] == ISO_space) { - strncpy(s->filename, http_index_html, sizeof(s->filename)); - } else { - s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0; - strncpy(s->filename, s->inputbuf, sizeof(s->filename)); - } - } 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); - - /* - * Start parsing headers. We look for Content-Length and ignore everything - * else until we hit the start of the message body. - * - * We will return 411 if the client doesn't send Content-Length and 413 - * if Content-Length is too high - */ - s->content_length = 0; - s->return_code = RETURN_CODE_LR; - do { - s->inputbuf[PSOCK_DATALEN(&s->sin)] = 0; - /* We anticipate a content length */ - if((PSOCK_DATALEN(&s->sin) > 14) && - strncasecmp(s->inputbuf, "Content-Length:", 15) == 0) { - char *val_start = &s->inputbuf[15]; - s->content_length = atoi(val_start); - - /* So far so good */ - s->return_code = RETURN_CODE_OK; - } - PSOCK_READTO(&s->sin, ISO_nl); - } while(PSOCK_DATALEN(&s->sin) != 2); - - /* - * Done reading headers. - * Reject content length greater than CONTENT_LENGTH_MAX bytes - */ - if(s->content_length > CONTENT_LENGTH_MAX) { - s->content_length = 0; - s->return_code = RETURN_CODE_TL; - } - - if(s->return_code == RETURN_CODE_OK) { - /* Acceptable Content Length. Try to obtain a lock */ - lock_obtain(s); - - if(lock == s) { - state = PARSE_POST_STATE_INIT; - } else { - s->return_code = RETURN_CODE_SU; - } - } - - /* Parse the message body, unless we have detected an error. */ - while(s->content_length > 0 && lock == s && - s->return_code == RETURN_CODE_OK) { - PSOCK_READBUF_LEN(&s->sin, s->content_length); - s->content_length -= PSOCK_DATALEN(&s->sin); - - /* Parse the message body */ - parse_post_request_chunk(s->inputbuf, PSOCK_DATALEN(&s->sin), - (s->content_length == 0)); - if(state == PARSE_POST_STATE_ERROR) { - /* Could not parse: Bad Request and stop parsing */ - s->return_code = RETURN_CODE_BR; - } - } - - /* - * Done. If our return code is OK but the state machine is not in - * STATE_MORE, it means that the message body ended half-way reading a key - * or value. Set 'Bad Request' - */ - if(s->return_code == RETURN_CODE_OK && state != PARSE_POST_STATE_MORE) { - s->return_code = RETURN_CODE_BR; - } - - /* If the flag is set, we had at least 1 configuration value accepted */ - if(config_ok) { - process_post(PROCESS_BROADCAST, httpd_simple_event_new_config, NULL); - } - config_ok = 0; - - lock_release(s); - } else { - PSOCK_CLOSE_EXIT(&s->sin); - } - - s->state = STATE_OUTPUT; - - while(1) { - PSOCK_READTO(&s->sin, ISO_nl); - } - - PSOCK_END(&s->sin); -} -/*---------------------------------------------------------------------------*/ -static void -handle_connection(struct httpd_state *s) -{ - handle_input(s); - if(s->state == STATE_OUTPUT) { - handle_output(s); - } -} -/*---------------------------------------------------------------------------*/ -static void -appcall(void *state) -{ - struct httpd_state *s = (struct httpd_state *)state; - - if(uip_closed() || uip_aborted() || uip_timedout()) { - if(s != NULL) { - memset(s, 0, sizeof(struct httpd_state)); - memb_free(&conns, s); - } - } else if(uip_connected()) { - s = (struct httpd_state *)memb_alloc(&conns); - if(s == NULL) { - uip_abort(); - return; - } - tcp_markconn(uip_conn, s); - PSOCK_INIT(&s->sin, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1); - PSOCK_INIT(&s->sout, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1); - PT_INIT(&s->outputpt); - s->script = NULL; - s->state = STATE_WAITING; - timer_set(&s->timer, CLOCK_SECOND * 10); - handle_connection(s); - } else if(s != NULL) { - if(uip_poll()) { - if(timer_expired(&s->timer)) { - uip_abort(); - memset(s, 0, sizeof(struct httpd_state)); - memb_free(&conns, s); - } - } else { - timer_restart(&s->timer); - } - handle_connection(s); - } else { - uip_abort(); - } -} -/*---------------------------------------------------------------------------*/ -static void -init(void) -{ - tcp_listen(UIP_HTONS(80)); - memb_init(&conns); - - list_add(pages_list, &http_index_page); - list_add(pages_list, &http_dev_cfg_page); - -#if WEB_DEMO_NET_UART - list_add(pages_list, &http_net_cfg_page); -#endif - -#if WEB_DEMO_MQTT_CLIENT - list_add(pages_list, &http_mqtt_cfg_page); -#endif -} -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(httpd_simple_process, ev, data) -{ - PROCESS_BEGIN(); - - printf("CC26XX Web Server\n"); - - httpd_simple_event_new_config = process_alloc_event(); - - init(); - - snprintf(http_mqtt_a, IBM_QUICKSTART_LINK_LEN, - "[ IBM Quickstart ]", - 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]); - - while(1) { - PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); - appcall(data); - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ -/** - * @} - */ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/httpd-simple.h b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/httpd-simple.h deleted file mode 100644 index 810fd4782..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/httpd-simple.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2010, Swedish Institute of Computer Science. - * Copyright (c) 2014, 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 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. - * - */ -/*---------------------------------------------------------------------------*/ -/** - * \file - * Header file for the HTTPD of the CC13xx/CC26xx web demo example. - * \author - * Adam Dunkels - * Niclas Finne - * Joakim Eriksson - * Texas Instruments Incorporated - http://www.ti.com/ - */ -/*---------------------------------------------------------------------------*/ -#ifndef HTTPD_SIMPLE_H_ -#define HTTPD_SIMPLE_H_ -/*---------------------------------------------------------------------------*/ -#include "contiki-net.h" -#include "sys/process.h" -/*---------------------------------------------------------------------------*/ -#include "web-demo.h" -/*---------------------------------------------------------------------------*/ -/* Ideally a multiple of TCP_MSS */ -#ifdef HTTPD_SIMPLE_CONF_MAIN_BUF_SIZE -#define HTTPD_SIMPLE_MAIN_BUF_SIZE HTTPD_SIMPLE_CONF_MAIN_BUF_SIZE -#else -#define HTTPD_SIMPLE_MAIN_BUF_SIZE UIP_TCP_MSS -#endif -/*---------------------------------------------------------------------------*/ -#define HTTPD_PATHLEN 16 -#define HTTPD_INBUF_LEN (HTTPD_PATHLEN + 10) - -#define TMP_BUF_SIZE (UIP_TCP_MSS + 1) -/*---------------------------------------------------------------------------*/ -/* POST request handlers */ -#define HTTPD_SIMPLE_POST_HANDLER_OK 1 -#define HTTPD_SIMPLE_POST_HANDLER_UNKNOWN 0 -#define HTTPD_SIMPLE_POST_HANDLER_ERROR 0xFFFFFFFF - -/** - * \brief Datatype for a handler which can process incoming POST requests - * \param key The configuration key to be updated - * \param key_len The length of the key argument - * \param val The new configuration value for key - * \param val_len The length of the value argument - * - * \return 1: HTTPD_SIMPLE_POST_HANDLER_OK if the function can handle the - * request, HTTPD_SIMPLE_POST_HANDLER_UNKNOWN if it does not know how to handle - * it. HTTPD_SIMPLE_POST_HANDLER_ERROR if it does know how to handle it but - * the request was malformed. - */ -typedef struct httpd_simple_post_handler { - struct httpd_simple_post_handler *next; - int (*handler)(char *key, int key_len, char *val, int val_len); -} httpd_simple_post_handler_t; - -/* Declare a handler */ -#define HTTPD_SIMPLE_POST_HANDLER(name, fp) \ - httpd_simple_post_handler_t name##_handler = { NULL, fp } - -/** - * \brief Register a handler for POST requests - * \param h A pointer to the handler structure - */ -void httpd_simple_register_post_handler(httpd_simple_post_handler_t *h); -/*---------------------------------------------------------------------------*/ -/* - * An event generated by the HTTPD when a new configuration request has been - * received - */ -extern process_event_t httpd_simple_event_new_config; -/*---------------------------------------------------------------------------*/ -PROCESS_NAME(httpd_simple_process); -/*---------------------------------------------------------------------------*/ -#endif /* HTTPD_SIMPLE_H_ */ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/img/6lbr-web.png b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/img/6lbr-web.png deleted file mode 100644 index 5308c412b..000000000 Binary files a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/img/6lbr-web.png and /dev/null differ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/img/ibm-watson-iot-platform-tls-optional.png b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/img/ibm-watson-iot-platform-tls-optional.png deleted file mode 100644 index 93c98624f..000000000 Binary files a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/img/ibm-watson-iot-platform-tls-optional.png and /dev/null differ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/img/quickstart-sensortag.png b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/img/quickstart-sensortag.png deleted file mode 100644 index a7ce7dabe..000000000 Binary files a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/img/quickstart-sensortag.png and /dev/null differ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/img/sensor-readings-config.png b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/img/sensor-readings-config.png deleted file mode 100644 index 79c8e61e3..000000000 Binary files a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/img/sensor-readings-config.png and /dev/null differ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/img/well-known-core.png b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/img/well-known-core.png deleted file mode 100644 index 93552e502..000000000 Binary files a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/img/well-known-core.png and /dev/null differ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/mqtt-client.c b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/mqtt-client.c deleted file mode 100644 index 3be86ffd8..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/mqtt-client.c +++ /dev/null @@ -1,927 +0,0 @@ -/* - * Copyright (c) 2014, 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 cc13xx-cc26xx-web-demo - * @{ - * - * \file - * MQTT/IBM cloud service client for the CC13xx/CC26xx web demo. - */ -/*---------------------------------------------------------------------------*/ -#include "contiki.h" -#include "dev/button-hal.h" -#include "dev/leds.h" -#include "sys/etimer.h" -#include "sys/ctimer.h" -#include "net/routing/routing.h" -#include "net/ipv6/uip.h" -#include "net/ipv6/uip-icmp6.h" -#include "net/app-layer/mqtt/mqtt.h" -#include "lib/sensors.h" -/*---------------------------------------------------------------------------*/ -#include "board-peripherals.h" -/*---------------------------------------------------------------------------*/ -#include "web-demo.h" -#include "httpd-simple.h" -#include "mqtt-client.h" -/*---------------------------------------------------------------------------*/ -#include -#include -/*---------------------------------------------------------------------------*/ -/* - * IBM server: messaging.quickstart.internetofthings.ibmcloud.com - * (184.172.124.189) mapped in an NAT64 (prefix 64:ff9b::/96) IPv6 address - * Note: If not able to connect; lookup the IP address again as it may change. - * - * If the node has a broker IP setting saved on flash, this value here will - * get ignored - */ -static const char *broker_ip = "0064:ff9b:0000:0000:0000:0000:b8ac:7cbd"; -/*---------------------------------------------------------------------------*/ -/* - * A timeout used when waiting for something to happen (e.g. to connect or to - * disconnect) - */ -#define STATE_MACHINE_PERIODIC (CLOCK_SECOND >> 1) -/*---------------------------------------------------------------------------*/ -/* Provide visible feedback via LEDS during various states */ -/* When connecting to broker */ -#define CONNECTING_LED_DURATION (CLOCK_SECOND >> 3) - -/* Each time we try to publish */ -#define PUBLISH_LED_ON_DURATION (CLOCK_SECOND) -/*---------------------------------------------------------------------------*/ -/* Connections and reconnections */ -#define RETRY_FOREVER 0xFF -#define RECONNECT_INTERVAL (CLOCK_SECOND * 2) - -/* - * 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 - */ -#define RECONNECT_ATTEMPTS 5 -#define CONNECTION_STABLE_TIME (CLOCK_SECOND * 5) -#define NEW_CONFIG_WAIT_INTERVAL (CLOCK_SECOND * 20) -static struct timer connection_life; -static uint8_t connect_attempt; -/*---------------------------------------------------------------------------*/ -/* Various states */ -static uint8_t state; -#define MQTT_CLIENT_STATE_INIT 0 -#define MQTT_CLIENT_STATE_REGISTERED 1 -#define MQTT_CLIENT_STATE_CONNECTING 2 -#define MQTT_CLIENT_STATE_CONNECTED 3 -#define MQTT_CLIENT_STATE_PUBLISHING 4 -#define MQTT_CLIENT_STATE_DISCONNECTED 5 -#define MQTT_CLIENT_STATE_NEWCONFIG 6 -#define MQTT_CLIENT_STATE_CONFIG_ERROR 0xFE -#define MQTT_CLIENT_STATE_ERROR 0xFF -/*---------------------------------------------------------------------------*/ -/* Maximum TCP segment size for outgoing segments of our socket */ -#define MQTT_CLIENT_MAX_SEGMENT_SIZE 32 -/*---------------------------------------------------------------------------*/ -/* - * Buffers for Client ID and Topic. - * Make sure they are large enough to hold the entire respective string - * - * d:quickstart:status:EUI64 is 32 bytes long - * iot-2/evt/status/fmt/json is 25 bytes - * We also need space for the null termination - */ -#define BUFFER_SIZE 64 -static char client_id[BUFFER_SIZE]; -static char pub_topic[BUFFER_SIZE]; -static char sub_topic[BUFFER_SIZE]; -/*---------------------------------------------------------------------------*/ -/* - * The main MQTT buffers. - * We will need to increase if we start publishing more data. - */ -#define APP_BUFFER_SIZE 512 -static struct mqtt_connection conn; -static char app_buffer[APP_BUFFER_SIZE]; -/*---------------------------------------------------------------------------*/ -#define QUICKSTART "quickstart" -/*---------------------------------------------------------------------------*/ -static struct mqtt_message *msg_ptr = 0; -static struct etimer publish_periodic_timer; -static struct ctimer ct; -static char *buf_ptr; -static uint16_t seq_nr_value = 0; -/*---------------------------------------------------------------------------*/ -static uip_ip6addr_t def_route; -/*---------------------------------------------------------------------------*/ -/* Parent RSSI functionality */ -extern int def_rt_rssi; -/*---------------------------------------------------------------------------*/ -const static web_demo_sensor_reading_t *reading; -/*---------------------------------------------------------------------------*/ -mqtt_client_config_t *conf; -/*---------------------------------------------------------------------------*/ -PROCESS(mqtt_client_process, "CC13xx/CC26xx MQTT Client"); -/*---------------------------------------------------------------------------*/ -static void -publish_led_off(void *d) -{ - leds_off(WEB_DEMO_STATUS_LED); -} -/*---------------------------------------------------------------------------*/ -static void -new_net_config(void) -{ - /* - * We got a new configuration over the net. - * - * Disconnect from the current broker and stop the periodic timer. - * - * When the source of the new configuration is done, we will get notified - * via an event. - */ - if(state == MQTT_CLIENT_STATE_NEWCONFIG) { - return; - } - - state = MQTT_CLIENT_STATE_NEWCONFIG; - - etimer_stop(&publish_periodic_timer); - mqtt_disconnect(&conn); -} -/*---------------------------------------------------------------------------*/ -static int -org_id_post_handler(char *key, int key_len, char *val, int val_len) -{ - int rv = HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - if(key_len != strlen("org_id") || - strncasecmp(key, "org_id", strlen("org_id")) != 0) { - /* Not ours */ - return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - } - - if(val_len > MQTT_CLIENT_CONFIG_ORG_ID_LEN) { - /* Ours but bad value */ - rv = HTTPD_SIMPLE_POST_HANDLER_ERROR; - } else { - memset(conf->org_id, 0, MQTT_CLIENT_CONFIG_ORG_ID_LEN); - memcpy(conf->org_id, val, val_len); - - rv = HTTPD_SIMPLE_POST_HANDLER_OK; - } - - new_net_config(); - - return rv; -} -/*---------------------------------------------------------------------------*/ -static int -type_id_post_handler(char *key, int key_len, char *val, int val_len) -{ - int rv = HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - if(key_len != strlen("type_id") || - strncasecmp(key, "type_id", strlen("type_id")) != 0) { - /* Not ours */ - return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - } - - if(val_len > MQTT_CLIENT_CONFIG_TYPE_ID_LEN) { - /* Ours but bad value */ - rv = HTTPD_SIMPLE_POST_HANDLER_ERROR; - } else { - memset(conf->type_id, 0, MQTT_CLIENT_CONFIG_TYPE_ID_LEN); - memcpy(conf->type_id, val, val_len); - - rv = HTTPD_SIMPLE_POST_HANDLER_OK; - } - - new_net_config(); - - return rv; -} -/*---------------------------------------------------------------------------*/ -static int -event_type_id_post_handler(char *key, int key_len, char *val, int val_len) -{ - int rv = HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - if(key_len != strlen("event_type_id") || - strncasecmp(key, "event_type_id", strlen("event_type_id")) != 0) { - /* Not ours */ - return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - } - - if(val_len > MQTT_CLIENT_CONFIG_EVENT_TYPE_ID_LEN) { - /* Ours but bad value */ - rv = HTTPD_SIMPLE_POST_HANDLER_ERROR; - } else { - memset(conf->event_type_id, 0, MQTT_CLIENT_CONFIG_EVENT_TYPE_ID_LEN); - memcpy(conf->event_type_id, val, val_len); - - rv = HTTPD_SIMPLE_POST_HANDLER_OK; - } - - new_net_config(); - - return rv; -} -/*---------------------------------------------------------------------------*/ -static int -cmd_type_post_handler(char *key, int key_len, char *val, int val_len) -{ - int rv = HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - if(key_len != strlen("cmd_type") || - strncasecmp(key, "cmd_type", strlen("cmd_type")) != 0) { - /* Not ours */ - return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - } - - if(val_len > MQTT_CLIENT_CONFIG_CMD_TYPE_LEN) { - /* Ours but bad value */ - rv = HTTPD_SIMPLE_POST_HANDLER_ERROR; - } else { - memset(conf->cmd_type, 0, MQTT_CLIENT_CONFIG_CMD_TYPE_LEN); - memcpy(conf->cmd_type, val, val_len); - - rv = HTTPD_SIMPLE_POST_HANDLER_OK; - } - - new_net_config(); - - return rv; -} -/*---------------------------------------------------------------------------*/ -static int -auth_token_post_handler(char *key, int key_len, char *val, int val_len) -{ - int rv = HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - if(key_len != strlen("auth_token") || - strncasecmp(key, "auth_token", strlen("auth_token")) != 0) { - /* Not ours */ - return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - } - - if(val_len > MQTT_CLIENT_CONFIG_AUTH_TOKEN_LEN) { - /* Ours but bad value */ - rv = HTTPD_SIMPLE_POST_HANDLER_ERROR; - } else { - memset(conf->auth_token, 0, MQTT_CLIENT_CONFIG_AUTH_TOKEN_LEN); - memcpy(conf->auth_token, val, val_len); - - rv = HTTPD_SIMPLE_POST_HANDLER_OK; - } - - new_net_config(); - - return rv; -} -/*---------------------------------------------------------------------------*/ -static int -interval_post_handler(char *key, int key_len, char *val, int val_len) -{ - int rv = 0; - - if(key_len != strlen("interval") || - strncasecmp(key, "interval", strlen("interval")) != 0) { - /* Not ours */ - return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - } - - rv = atoi(val); - - if(rv < MQTT_CLIENT_PUBLISH_INTERVAL_MIN || - rv > MQTT_CLIENT_PUBLISH_INTERVAL_MAX) { - return HTTPD_SIMPLE_POST_HANDLER_ERROR; - } - - conf->pub_interval = rv * CLOCK_SECOND; - - return HTTPD_SIMPLE_POST_HANDLER_OK; -} -/*---------------------------------------------------------------------------*/ -static int -port_post_handler(char *key, int key_len, char *val, int val_len) -{ - int rv = 0; - - if(key_len != strlen("broker_port") || - strncasecmp(key, "broker_port", strlen("broker_port")) != 0) { - /* Not ours */ - return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - } - - rv = atoi(val); - - if(rv <= 65535 && rv > 0) { - conf->broker_port = rv; - } else { - return HTTPD_SIMPLE_POST_HANDLER_ERROR; - } - - new_net_config(); - - return HTTPD_SIMPLE_POST_HANDLER_OK; -} -/*---------------------------------------------------------------------------*/ -static int -ip_addr_post_handler(char *key, int key_len, char *val, int val_len) -{ - int rv = HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - - if(key_len != strlen("broker_ip") || - strncasecmp(key, "broker_ip", strlen("broker_ip")) != 0) { - /* Not ours */ - return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - } - - if(val_len > MQTT_CLIENT_CONFIG_IP_ADDR_STR_LEN) { - /* Ours but bad value */ - rv = HTTPD_SIMPLE_POST_HANDLER_ERROR; - } else { - memset(conf->broker_ip, 0, MQTT_CLIENT_CONFIG_IP_ADDR_STR_LEN); - memcpy(conf->broker_ip, val, val_len); - - rv = HTTPD_SIMPLE_POST_HANDLER_OK; - } - - new_net_config(); - - return rv; -} -/*---------------------------------------------------------------------------*/ -static int -reconnect_post_handler(char *key, int key_len, char *val, int val_len) -{ - if(key_len != strlen("reconnect") || - strncasecmp(key, "reconnect", strlen("reconnect")) != 0) { - /* Not ours */ - return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - } - - new_net_config(); - - return HTTPD_SIMPLE_POST_HANDLER_OK; -} -/*---------------------------------------------------------------------------*/ -HTTPD_SIMPLE_POST_HANDLER(org_id, org_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(cmd_type, cmd_type_post_handler); -HTTPD_SIMPLE_POST_HANDLER(auth_token, auth_token_post_handler); -HTTPD_SIMPLE_POST_HANDLER(ip_addr, ip_addr_post_handler); -HTTPD_SIMPLE_POST_HANDLER(port, port_post_handler); -HTTPD_SIMPLE_POST_HANDLER(interval, interval_post_handler); -HTTPD_SIMPLE_POST_HANDLER(reconnect, reconnect_post_handler); -/*---------------------------------------------------------------------------*/ -static void -pub_handler(const char *topic, uint16_t topic_len, const uint8_t *chunk, - uint16_t chunk_len) -{ - DBG("Pub Handler: topic='%s' (len=%u), chunk_len=%u\n", topic, topic_len, - chunk_len); - - /* If we don't like the length, ignore */ - if(topic_len != 23 || chunk_len != 1) { - printf("Incorrect topic or chunk len. Ignored\n"); - return; - } - - /* If the format != json, ignore */ - if(strncmp(&topic[topic_len - 4], "json", 4) != 0) { - printf("Incorrect format\n"); - } - - if(strncmp(&topic[10], "leds", 4) == 0) { - if(chunk[0] == '1') { - leds_on(LEDS_RED); - } else if(chunk[0] == '0') { - leds_off(LEDS_RED); - } - return; - } - -#if BOARD_SENSORTAG - if(strncmp(&topic[10], "buzz", 4) == 0) { - if(chunk[0] == '1') { - buzzer_start(1000); - } else if(chunk[0] == '0') { - buzzer_stop(); - } - return; - } -#endif -} -/*---------------------------------------------------------------------------*/ -static void -mqtt_event(struct mqtt_connection *m, mqtt_event_t event, void *data) -{ - switch(event) { - case MQTT_EVENT_CONNECTED: { - DBG("APP - Application has a MQTT connection\n"); - timer_set(&connection_life, CONNECTION_STABLE_TIME); - state = MQTT_CLIENT_STATE_CONNECTED; - break; - } - case MQTT_EVENT_DISCONNECTED: { - DBG("APP - MQTT Disconnect. Reason %u\n", *((mqtt_event_t *)data)); - - /* Do nothing if the disconnect was the result of an incoming config */ - if(state != MQTT_CLIENT_STATE_NEWCONFIG) { - state = MQTT_CLIENT_STATE_DISCONNECTED; - process_poll(&mqtt_client_process); - } - break; - } - case MQTT_EVENT_PUBLISH: { - msg_ptr = data; - - /* Implement first_flag in publish message? */ - if(msg_ptr->first_chunk) { - msg_ptr->first_chunk = 0; - DBG("APP - Application received a publish on topic '%s'. Payload " - "size is %i bytes. Content:\n\n", - msg_ptr->topic, msg_ptr->payload_length); - } - - pub_handler(msg_ptr->topic, strlen(msg_ptr->topic), msg_ptr->payload_chunk, - msg_ptr->payload_length); - break; - } - case MQTT_EVENT_SUBACK: { - DBG("APP - Application is subscribed to topic successfully\n"); - break; - } - case MQTT_EVENT_UNSUBACK: { - DBG("APP - Application is unsubscribed to topic successfully\n"); - break; - } - case MQTT_EVENT_PUBACK: { - DBG("APP - Publishing complete.\n"); - break; - } - default: - DBG("APP - Application got a unhandled MQTT event: %i\n", event); - break; - } -} -/*---------------------------------------------------------------------------*/ -static int -construct_pub_topic(void) -{ - int len = snprintf(pub_topic, BUFFER_SIZE, "iot-2/evt/%s/fmt/json", - conf->event_type_id); - - /* len < 0: Error. Len >= BUFFER_SIZE: Buffer too small */ - if(len < 0 || len >= BUFFER_SIZE) { - printf("Pub Topic: %d, Buffer %d\n", len, BUFFER_SIZE); - return 0; - } - - return 1; -} -/*---------------------------------------------------------------------------*/ -static int -construct_sub_topic(void) -{ - int len = snprintf(sub_topic, BUFFER_SIZE, "iot-2/cmd/%s/fmt/json", - conf->cmd_type); - - /* len < 0: Error. Len >= BUFFER_SIZE: Buffer too small */ - if(len < 0 || len >= BUFFER_SIZE) { - printf("Sub Topic: %d, Buffer %d\n", len, BUFFER_SIZE); - return 0; - } - - return 1; -} -/*---------------------------------------------------------------------------*/ -static int -construct_client_id(void) -{ - int len = snprintf(client_id, BUFFER_SIZE, "d:%s:%s:%02x%02x%02x%02x%02x%02x", - conf->org_id, conf->type_id, - 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]); - - /* len < 0: Error. Len >= BUFFER_SIZE: Buffer too small */ - if(len < 0 || len >= BUFFER_SIZE) { - printf("Client ID: %d, Buffer %d\n", len, BUFFER_SIZE); - return 0; - } - - return 1; -} -/*---------------------------------------------------------------------------*/ -static void -update_config(void) -{ - if(construct_client_id() == 0) { - /* Fatal error. Client ID larger than the buffer */ - state = MQTT_CLIENT_STATE_CONFIG_ERROR; - return; - } - - if(construct_sub_topic() == 0) { - /* Fatal error. Topic larger than the buffer */ - state = MQTT_CLIENT_STATE_CONFIG_ERROR; - return; - } - - if(construct_pub_topic() == 0) { - /* Fatal error. Topic larger than the buffer */ - state = MQTT_CLIENT_STATE_CONFIG_ERROR; - return; - } - - /* Reset the counter */ - seq_nr_value = 0; - - state = MQTT_CLIENT_STATE_INIT; - - /* - * Schedule next timer event ASAP - * - * If we entered an error state then we won't do anything when it fires. - * - * Since the error at this stage is a config error, we will only exit this - * error state if we get a new config. - */ - etimer_set(&publish_periodic_timer, 0); - - return; -} -/*---------------------------------------------------------------------------*/ -static int -init_config() -{ - /* Populate configuration with default values */ - memset(conf, 0, sizeof(mqtt_client_config_t)); - - memcpy(conf->org_id, WEB_DEMO_DEFAULT_ORG_ID, 11); - memcpy(conf->type_id, WEB_DEMO_DEFAULT_TYPE_ID, 7); - memcpy(conf->event_type_id, WEB_DEMO_DEFAULT_EVENT_TYPE_ID, 7); - memcpy(conf->broker_ip, broker_ip, strlen(broker_ip)); - memcpy(conf->cmd_type, WEB_DEMO_DEFAULT_SUBSCRIBE_CMD_TYPE, 1); - - conf->broker_port = WEB_DEMO_DEFAULT_BROKER_PORT; - conf->pub_interval = WEB_DEMO_DEFAULT_PUBLISH_INTERVAL; - - return 1; -} -/*---------------------------------------------------------------------------*/ -static void -register_http_post_handlers(void) -{ - httpd_simple_register_post_handler(&org_id_handler); - httpd_simple_register_post_handler(&type_id_handler); - httpd_simple_register_post_handler(&event_type_id_handler); - httpd_simple_register_post_handler(&cmd_type_handler); - httpd_simple_register_post_handler(&auth_token_handler); - httpd_simple_register_post_handler(&interval_handler); - httpd_simple_register_post_handler(&port_handler); - httpd_simple_register_post_handler(&ip_addr_handler); - httpd_simple_register_post_handler(&reconnect_handler); -} -/*---------------------------------------------------------------------------*/ -static void -subscribe(void) -{ - /* Publish MQTT topic in IBM quickstart format */ - mqtt_status_t status; - - status = mqtt_subscribe(&conn, NULL, sub_topic, MQTT_QOS_LEVEL_0); - - DBG("APP - Subscribing!\n"); - if(status == MQTT_STATUS_OUT_QUEUE_FULL) { - DBG("APP - Tried to subscribe but command queue was full!\n"); - } -} -/*---------------------------------------------------------------------------*/ -static void -publish(void) -{ - /* Publish MQTT topic in IBM quickstart format */ - int len; - int remaining = APP_BUFFER_SIZE; - char def_rt_str[64]; - - seq_nr_value++; - - buf_ptr = app_buffer; - - len = snprintf(buf_ptr, remaining, - "{" - "\"d\":{" - "\"myName\":\"%s\"," - "\"Seq #\":%d," - "\"Uptime (sec)\":%lu", - BOARD_STRING, seq_nr_value, clock_seconds()); - - if(len < 0 || len >= remaining) { - printf("Buffer too short. Have %d, need %d + \\0\n", remaining, len); - return; - } - - remaining -= len; - buf_ptr += len; - - /* Put our Default route's string representation in a buffer */ - memset(def_rt_str, 0, sizeof(def_rt_str)); - web_demo_ipaddr_sprintf(def_rt_str, sizeof(def_rt_str), - uip_ds6_defrt_choose()); - - len = snprintf(buf_ptr, remaining, ",\"Def Route\":\"%s\",\"RSSI (dBm)\":%d", - def_rt_str, def_rt_rssi); - - if(len < 0 || len >= remaining) { - printf("Buffer too short. Have %d, need %d + \\0\n", remaining, len); - return; - } - remaining -= len; - buf_ptr += len; - - memcpy(&def_route, uip_ds6_defrt_choose(), sizeof(uip_ip6addr_t)); - - for(reading = web_demo_sensor_first(); - reading != NULL; reading = reading->next) { - if(reading->publish && reading->raw != -1) { - len = snprintf(buf_ptr, remaining, - ",\"%s (%s)\":%s", reading->descr, reading->units, - reading->converted); - - if(len < 0 || len >= remaining) { - printf("Buffer too short. Have %d, need %d + \\0\n", remaining, len); - return; - } - remaining -= len; - buf_ptr += len; - } - } - - len = snprintf(buf_ptr, remaining, "}}"); - - if(len < 0 || len >= remaining) { - printf("Buffer too short. Have %d, need %d + \\0\n", remaining, len); - return; - } - - mqtt_publish(&conn, NULL, pub_topic, (uint8_t *)app_buffer, - strlen(app_buffer), MQTT_QOS_LEVEL_0, MQTT_RETAIN_OFF); - - DBG("APP - Publish!\n"); -} -/*---------------------------------------------------------------------------*/ -static void -connect_to_broker(void) -{ - /* Connect to MQTT server */ - mqtt_status_t conn_attempt_result = mqtt_connect(&conn, conf->broker_ip, - conf->broker_port, - conf->pub_interval * 3); - - if(conn_attempt_result == MQTT_STATUS_OK) { - state = MQTT_CLIENT_STATE_CONNECTING; - } else { - state = MQTT_CLIENT_STATE_CONFIG_ERROR; - } -} -/*---------------------------------------------------------------------------*/ -static void -state_machine(void) -{ - switch(state) { - case MQTT_CLIENT_STATE_INIT: - /* If we have just been configured register MQTT connection */ - mqtt_register(&conn, &mqtt_client_process, client_id, mqtt_event, - MQTT_CLIENT_MAX_SEGMENT_SIZE); - - /* - * If we are not using the quickstart service (thus we are an IBM - * registered device), we need to provide user name and password - */ - if(strncasecmp(conf->org_id, QUICKSTART, strlen(conf->org_id)) != 0) { - if(strlen(conf->auth_token) == 0) { - printf("User name set, but empty auth token\n"); - state = MQTT_CLIENT_STATE_ERROR; - break; - } else { - mqtt_set_username_password(&conn, "use-token-auth", - conf->auth_token); - } - } - - /* _register() will set auto_reconnect. We don't want that. */ - conn.auto_reconnect = 0; - connect_attempt = 1; - - /* - * Wipe out the default route so we'll republish it every time we switch to - * a new broker - */ - memset(&def_route, 0, sizeof(def_route)); - - state = MQTT_CLIENT_STATE_REGISTERED; - DBG("Init\n"); - /* Continue */ - case MQTT_CLIENT_STATE_REGISTERED: - if(uip_ds6_get_global(ADDR_PREFERRED) != NULL) { - /* Registered and with a public IP. Connect */ - DBG("Registered. Connect attempt %u\n", connect_attempt); - connect_to_broker(); - } - etimer_set(&publish_periodic_timer, WEB_DEMO_NET_CONNECT_PERIODIC); - return; - break; - case MQTT_CLIENT_STATE_CONNECTING: - leds_on(WEB_DEMO_STATUS_LED); - ctimer_set(&ct, CONNECTING_LED_DURATION, publish_led_off, NULL); - /* Not connected yet. Wait */ - DBG("Connecting (%u)\n", connect_attempt); - break; - case MQTT_CLIENT_STATE_CONNECTED: - /* Don't subscribe unless we are a registered device */ - if(strncasecmp(conf->org_id, QUICKSTART, strlen(conf->org_id)) == 0) { - DBG("Using 'quickstart': Skipping subscribe\n"); - state = MQTT_CLIENT_STATE_PUBLISHING; - } - /* Continue */ - case MQTT_CLIENT_STATE_PUBLISHING: - /* If the timer expired, the connection is stable. */ - if(timer_expired(&connection_life)) { - /* - * Intentionally using 0 here instead of 1: We want RECONNECT_ATTEMPTS - * attempts if we disconnect after a successful connect - */ - connect_attempt = 0; - } - - if(mqtt_ready(&conn) && conn.out_buffer_sent) { - /* Connected. Publish */ - if(state == MQTT_CLIENT_STATE_CONNECTED) { - subscribe(); - state = MQTT_CLIENT_STATE_PUBLISHING; - } else { - leds_on(WEB_DEMO_STATUS_LED); - ctimer_set(&ct, PUBLISH_LED_ON_DURATION, publish_led_off, NULL); - publish(); - } - etimer_set(&publish_periodic_timer, conf->pub_interval); - - DBG("Publishing\n"); - /* Return here so we don't end up rescheduling the timer */ - return; - } else { - /* - * Our publish timer fired, but some MQTT packet is already in flight - * (either not sent at all, or sent but not fully ACKd). - * - * This can mean that we have lost connectivity to our broker or that - * simply there is some network delay. In both cases, we refuse to - * trigger a new message and we wait for TCP to either ACK the entire - * packet after retries, or to timeout and notify us. - */ - DBG("Publishing... (MQTT state=%d, q=%u)\n", conn.state, - conn.out_queue_full); - } - break; - case MQTT_CLIENT_STATE_DISCONNECTED: - DBG("Disconnected\n"); - if(connect_attempt < RECONNECT_ATTEMPTS || - RECONNECT_ATTEMPTS == RETRY_FOREVER) { - /* Disconnect and backoff */ - clock_time_t interval; - mqtt_disconnect(&conn); - connect_attempt++; - - interval = connect_attempt < 3 ? RECONNECT_INTERVAL << connect_attempt : - RECONNECT_INTERVAL << 3; - - DBG("Disconnected. Attempt %u in %lu ticks\n", connect_attempt, interval); - - etimer_set(&publish_periodic_timer, interval); - - state = MQTT_CLIENT_STATE_REGISTERED; - return; - } else { - /* Max reconnect attempts reached. Enter error state */ - state = MQTT_CLIENT_STATE_ERROR; - DBG("Aborting connection after %u attempts\n", connect_attempt - 1); - } - break; - case MQTT_CLIENT_STATE_NEWCONFIG: - /* Only update config after we have disconnected or in the case of an error */ - if(conn.state == MQTT_CONN_STATE_NOT_CONNECTED || conn.state == MQTT_CONN_STATE_ERROR) { - update_config(); - DBG("New config\n"); - - /* update_config() scheduled next pass. Return */ - return; - } - break; - case MQTT_CLIENT_STATE_CONFIG_ERROR: - /* Idle away. The only way out is a new config */ - printf("Bad configuration.\n"); - return; - case MQTT_CLIENT_STATE_ERROR: - default: - leds_on(WEB_DEMO_STATUS_LED); - /* - * 'default' should never happen. - * - * If we enter here it's because of some error. Stop timers. The only thing - * that can bring us out is a new config event - */ - printf("Default case: State=0x%02x\n", state); - return; - } - - /* If we didn't return so far, reschedule ourselves */ - etimer_set(&publish_periodic_timer, STATE_MACHINE_PERIODIC); -} -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(mqtt_client_process, ev, data) -{ - - PROCESS_BEGIN(); - - printf("CC13xx/CC26xx MQTT Client Process\n"); - - conf = &web_demo_config.mqtt_config; - if(init_config() != 1) { - PROCESS_EXIT(); - } - - register_http_post_handlers(); - - update_config(); - - /* Main loop */ - while(1) { - - PROCESS_YIELD(); - - if(ev == button_hal_release_event) { - button_hal_button_t *btn = (button_hal_button_t *)data; - - if(btn->unique_id == WEB_DEMO_MQTT_PUBLISH_TRIGGER) { - if(state == MQTT_CLIENT_STATE_ERROR) { - connect_attempt = 1; - state = MQTT_CLIENT_STATE_REGISTERED; - } - } - } - - if(ev == httpd_simple_event_new_config) { - /* - * Schedule next pass in a while. When HTTPD sends us this event, it is - * also in the process of sending the config page. Wait a little before - * reconnecting, so as to not cause congestion. - */ - etimer_set(&publish_periodic_timer, NEW_CONFIG_WAIT_INTERVAL); - } - - if((ev == PROCESS_EVENT_TIMER && data == &publish_periodic_timer) || - ev == PROCESS_EVENT_POLL || - ev == web_demo_publish_event || - (ev == button_hal_release_event && - ((button_hal_button_t *)data)->unique_id == - WEB_DEMO_MQTT_PUBLISH_TRIGGER)) { - state_machine(); - } - - if(ev == web_demo_load_config_defaults) { - init_config(); - etimer_set(&publish_periodic_timer, NEW_CONFIG_WAIT_INTERVAL); - } - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ -/** - * @} - */ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/mqtt-client.h b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/mqtt-client.h deleted file mode 100644 index d37c31fbc..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/mqtt-client.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2014, 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 cc13xx-cc26xx-web-demo - * @{ - * - * \file - * Header file for the CC13xx/CC26xx web demo MQTT client functionality - */ -/*---------------------------------------------------------------------------*/ -#ifndef MQTT_CLIENT_H_ -#define MQTT_CLIENT_H_ -/*---------------------------------------------------------------------------*/ -#define MQTT_CLIENT_CONFIG_ORG_ID_LEN 32 -#define MQTT_CLIENT_CONFIG_TYPE_ID_LEN 32 -#define MQTT_CLIENT_CONFIG_AUTH_TOKEN_LEN 32 -#define MQTT_CLIENT_CONFIG_EVENT_TYPE_ID_LEN 32 -#define MQTT_CLIENT_CONFIG_CMD_TYPE_LEN 8 -#define MQTT_CLIENT_CONFIG_IP_ADDR_STR_LEN 64 -/*---------------------------------------------------------------------------*/ -#define MQTT_CLIENT_PUBLISH_INTERVAL_MAX 86400 /* secs: 1 day */ -#define MQTT_CLIENT_PUBLISH_INTERVAL_MIN 5 /* secs */ -/*---------------------------------------------------------------------------*/ -PROCESS_NAME(mqtt_client_process); -/*---------------------------------------------------------------------------*/ -/** - * \brief Data structure declaration for the MQTT client configuration - */ -typedef struct mqtt_client_config { - char org_id[MQTT_CLIENT_CONFIG_ORG_ID_LEN]; - char type_id[MQTT_CLIENT_CONFIG_TYPE_ID_LEN]; - char auth_token[MQTT_CLIENT_CONFIG_AUTH_TOKEN_LEN]; - char event_type_id[MQTT_CLIENT_CONFIG_EVENT_TYPE_ID_LEN]; - char broker_ip[MQTT_CLIENT_CONFIG_IP_ADDR_STR_LEN]; - char cmd_type[MQTT_CLIENT_CONFIG_CMD_TYPE_LEN]; - clock_time_t pub_interval; - uint16_t broker_port; -} mqtt_client_config_t; -/*---------------------------------------------------------------------------*/ -#endif /* MQTT_CLIENT_H_ */ -/*---------------------------------------------------------------------------*/ -/** - * @} - */ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/net-uart.c b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/net-uart.c deleted file mode 100644 index 564abe27d..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/net-uart.c +++ /dev/null @@ -1,321 +0,0 @@ -/* - * Copyright (c) 2014, 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 cc13xx-cc26xx-web-demo - * @{ - * - * \file - * A process which receives data over UART and transmits them over UDP - * to a pre-defined IPv6 address and port. It also listens on the same UDP - * port for messages, which it prints out over UART. - * - * For this example to work, you will have to modify the destination IPv6 - * address by adjusting the set_dest_addr() macro below. - * - * To listen on your linux or OS X box: - * nc -6ulkw 1 REMOTE_PORT - * - * (REMOTE_PORT should be the actual value of the define below, e.g. 7777) - * - * Once netcat is up and listening, type something to the CC13xx/CC26xx's terminal - * Bear in mind that the datagram will only be sent after a 0x0a (LF) char - * has been received. Therefore, if you are on Win, do NOT use PuTTY for - * this purpose, since it does not send 0x0a as part of the line end. On - * Win XP use hyperterm. On Win 7 use some other software (e.g. Tera Term, - * which can be configured to send CRLF on enter keystrokes). - * - * To send data in the other direction from your linux or OS X box: - * - * nc -6u \ REMOTE_PORT - */ -/*---------------------------------------------------------------------------*/ -#include "contiki.h" -#include "sys/cc.h" -#include "sys/process.h" -#include "dev/serial-line.h" -#include "net/ipv6/uip.h" -#include "net/ipv6/uip-udp-packet.h" -#include "net/ipv6/uiplib.h" -/*---------------------------------------------------------------------------*/ -#include "uart0-arch.h" -/*---------------------------------------------------------------------------*/ -#include "net-uart.h" -#include "httpd-simple.h" -/*---------------------------------------------------------------------------*/ -#include -#include -#include -#include -#include -/*---------------------------------------------------------------------------*/ -#define DEBUG DEBUG_NONE -#include "net/ipv6/uip-debug.h" -/*---------------------------------------------------------------------------*/ -#define REMOTE_PORT 7777 -#define MAX_MSG_SIZE 100 - -#define set_dest_addr() uip_ip6addr(&remote_addr, \ - 0xBBBB, 0x0000, 0x0000, 0x0000, \ - 0x3E07, 0x54FF, 0xFE74, 0x4885); -/*---------------------------------------------------------------------------*/ -#define ADDRESS_CONVERSION_OK 1 -#define ADDRESS_CONVERSION_ERROR 0 -/*---------------------------------------------------------------------------*/ -static struct uip_udp_conn *udp_conn = NULL; - -static uint8_t buffer[MAX_MSG_SIZE]; -static uint8_t msg_len; -static uip_ip6addr_t remote_addr; -/*---------------------------------------------------------------------------*/ -#define IPV6_ADDR_STR_LEN 64 -/*---------------------------------------------------------------------------*/ -PROCESS(net_uart_process, "Net UART Process"); -/*---------------------------------------------------------------------------*/ -/* - * \brief Attempts to convert a string representation of an IPv6 address to a - * numeric one. - * \param buf The buffer with the string to be converted. - * \return ADDRESS_CONVERSION_OK or ADDRESS_CONVERSION_ERROR - * - * ToDo: Add support for NAT64 conversion in case the incoming address is a v4 - * This is now supported in the current master, so when we pull it in this will - * be very straightforward. - */ -static int -set_new_ip_address(char *buf) -{ - /* - * uiplib_ip6addrconv will immediately start writing into the supplied buffer - * even if it subsequently fails. Thus, pass an intermediate buffer - */ - uip_ip6addr_t tmp_addr; - - int rv = uiplib_ip6addrconv(buf, &tmp_addr); - - if(rv == ADDRESS_CONVERSION_OK) { - /* Conversion OK, copy to our main buffer */ - memcpy(&remote_addr, &tmp_addr, sizeof(remote_addr)); - - PRINTF("Updated remote address "); - PRINT6ADDR(&remote_addr); - PRINTF("\n"); - } - - return rv; -} -/*---------------------------------------------------------------------------*/ -static void -net_input(void) -{ - if(uip_newdata()) { - memset(buffer, 0, MAX_MSG_SIZE); - msg_len = MIN(uip_datalen(), MAX_MSG_SIZE - 1); - - /* Copy data */ - memcpy(buffer, uip_appdata, msg_len); - printf("%s", (char *)buffer); - } - - return; -} -/*---------------------------------------------------------------------------*/ -static void -release_uart(void) -{ - uart0_set_callback(NULL); -} -/*---------------------------------------------------------------------------*/ -static void -keep_uart_on(void) -{ - uart0_set_callback(serial_line_input_byte); -} -/*---------------------------------------------------------------------------*/ -static int -remote_port_post_handler(char *key, int key_len, char *val, int val_len) -{ - int rv; - - if(key_len != strlen("net_uart_port") || - strncasecmp(key, "net_uart_port", strlen("net_uart_port")) != 0) { - /* Not ours */ - return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - } - - rv = atoi(val); - - if(rv <= 65535 && rv > 0) { - web_demo_config.net_uart.remote_port = (uint16_t)rv; - } else { - return HTTPD_SIMPLE_POST_HANDLER_ERROR; - } - - return HTTPD_SIMPLE_POST_HANDLER_OK; -} -/*---------------------------------------------------------------------------*/ -static int -remote_ipv6_post_handler(char *key, int key_len, char *val, int val_len) -{ - int rv = HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - - if(key_len != strlen("net_uart_ip") || - strncasecmp(key, "net_uart_ip", strlen("net_uart_ip")) != 0) { - /* Not ours */ - return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - } - - if(val_len > IPV6_ADDR_STR_LEN) { - /* Ours but bad value */ - rv = HTTPD_SIMPLE_POST_HANDLER_ERROR; - } else { - if(set_new_ip_address(val)) { - memset(web_demo_config.net_uart.remote_address, 0, - NET_UART_IP_ADDR_STRLEN); - memcpy(web_demo_config.net_uart.remote_address, val, val_len); - rv = HTTPD_SIMPLE_POST_HANDLER_OK; - } - } - - return rv; -} -/*---------------------------------------------------------------------------*/ -static int -on_off_post_handler(char *key, int key_len, char *val, int val_len) -{ - int rv; - - if(key_len != strlen("net_uart_on") || - strncasecmp(key, "net_uart_on", strlen("net_uart_on")) != 0) { - /* Not ours */ - return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - } - - rv = atoi(val); - - /* Be pedantic: only accept 0 and 1, not just any non-zero value */ - if(rv == 0) { - web_demo_config.net_uart.enable = 0; - release_uart(); - } else if(rv == 1) { - web_demo_config.net_uart.enable = 1; - keep_uart_on(); - } else { - return HTTPD_SIMPLE_POST_HANDLER_ERROR; - } - - return HTTPD_SIMPLE_POST_HANDLER_OK; -} -/*---------------------------------------------------------------------------*/ -HTTPD_SIMPLE_POST_HANDLER(remote_port, remote_port_post_handler); -HTTPD_SIMPLE_POST_HANDLER(remote_ipv6, remote_ipv6_post_handler); -HTTPD_SIMPLE_POST_HANDLER(on_off, on_off_post_handler); -/*---------------------------------------------------------------------------*/ -static void -set_config_defaults(void) -{ - /* Set a hard-coded destination address to start with */ - set_dest_addr(); - - /* Set config defaults */ - web_demo_ipaddr_sprintf(web_demo_config.net_uart.remote_address, - NET_UART_IP_ADDR_STRLEN, &remote_addr); - web_demo_config.net_uart.remote_port = REMOTE_PORT; - web_demo_config.net_uart.enable = 1; -} -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(net_uart_process, ev, data) -{ - PROCESS_BEGIN(); - - printf("CC13xx/CC26xx Net UART Process\n"); - - set_config_defaults(); - - udp_conn = udp_new(NULL, UIP_HTONS(0), NULL); - udp_bind(udp_conn, UIP_HTONS(REMOTE_PORT)); - - if(udp_conn == NULL) { - printf("No UDP connection available, exiting the process!\n"); - PROCESS_EXIT(); - } - - httpd_simple_register_post_handler(&remote_port_handler); - httpd_simple_register_post_handler(&remote_ipv6_handler); - httpd_simple_register_post_handler(&on_off_handler); - - while(1) { - - PROCESS_YIELD(); - - if(ev == serial_line_event_message) { - /* - * If the message contains a new IP address, save it and go back to - * waiting. - */ - if(set_new_ip_address((char *)data) == ADDRESS_CONVERSION_ERROR) { - /* Not an IP address in the message. Send to current destination */ - memset(buffer, 0, MAX_MSG_SIZE); - - /* We need to add a line feed, thus never fill the entire buffer */ - msg_len = MIN(strlen(data), MAX_MSG_SIZE - 1); - memcpy(buffer, data, msg_len); - - /* Add a line feed */ - buffer[msg_len] = 0x0A; - msg_len++; - - uip_udp_packet_sendto( - udp_conn, buffer, msg_len, &remote_addr, - UIP_HTONS(web_demo_config.net_uart.remote_port)); - } - } else if(ev == tcpip_event) { - net_input(); - } else if(ev == web_demo_config_loaded_event) { - /* - * New config. Check if it's possible to update the remote address. - * The port will have been updated already - */ - set_new_ip_address(web_demo_config.net_uart.remote_address); - - if(web_demo_config.net_uart.enable == 1) { - keep_uart_on(); - } - } else if(ev == web_demo_load_config_defaults) { - set_config_defaults(); - } - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ -/** - * @} - * @} - */ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/net-uart.h b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/net-uart.h deleted file mode 100644 index 362bc79ff..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/net-uart.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2014, 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. - */ -#ifndef NET_UART_H_ -#define NET_UART_H_ -/*---------------------------------------------------------------------------*/ -#include "net/ipv6/uip.h" -/*---------------------------------------------------------------------------*/ -#include -/*---------------------------------------------------------------------------*/ -#define NET_UART_IP_ADDR_STRLEN 64 -/*---------------------------------------------------------------------------*/ -PROCESS_NAME(net_uart_process); -/*---------------------------------------------------------------------------*/ -typedef struct net_uart_config_s { - char remote_address[NET_UART_IP_ADDR_STRLEN]; - uint16_t remote_port; - uint8_t enable; -} net_uart_config_t; -/*---------------------------------------------------------------------------*/ -#endif /* NET_UART_H_ */ -/*---------------------------------------------------------------------------*/ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/project-conf.h b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/project-conf.h deleted file mode 100644 index 06cd4ed09..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/project-conf.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2014, 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. - */ -/*---------------------------------------------------------------------------*/ -#ifndef PROJECT_CONF_H_ -#define PROJECT_CONF_H_ -/*---------------------------------------------------------------------------*/ -/* Platform configuration */ -#define BOARD_CONF_SENSORS_DISABLE 1 -#define WATCHDOG_CONF_DISABLE 1 -/*---------------------------------------------------------------------------*/ -/* Change to match your configuration */ -#define IEEE802154_CONF_PANID 0xABCD -#define IEEE802154_CONF_DEFAULT_CHANNEL 25 -#define RF_CONF_MODE RF_MODE_2_4_GHZ -#define RF_CONF_BLE_BEACON_ENABLE 1 -/*---------------------------------------------------------------------------*/ -/* TI drivers configuration */ -#define TI_SPI_CONF_ENABLE 1 -#define TI_I2C_CONF_ENABLE 0 -/*---------------------------------------------------------------------------*/ - -/* Enable TCP */ -#define UIP_CONF_TCP 1 - -/* Enable/Disable Components of this Demo */ -#define WEB_DEMO_CONF_MQTT_CLIENT 1 -#define WEB_DEMO_CONF_6LBR_CLIENT ROUTING_CONF_RPL_CLASSIC -#define WEB_DEMO_CONF_COAP_SERVER 1 -#define WEB_DEMO_CONF_NET_UART 1 - -/* - * ADC sensor functionality. To test this, an external voltage source should be - * connected to DIO23 - * Enable/Disable DIO23 ADC reading by setting WEB_DEMO_CONF_ADC_DEMO - */ -#define WEB_DEMO_CONF_ADC_DEMO 0 -/*---------------------------------------------------------------------------*/ -/* - * Change to 1 if you are using an older CC2650 Sensortag (look for Rev: 1.2 - * printed on the PCB, or for a sticker reading "HW Rev 1.2.0"). - * - * This may be the case if you are getting this error: - * "Could not open flash to load config" - * when your sensortag is starting up. - */ -#define SENSORTAG_CC2650_REV_1_2_0 0 -/*---------------------------------------------------------------------------*/ -/* Enable the ROM bootloader */ -#define ROM_BOOTLOADER_ENABLE 1 -/*---------------------------------------------------------------------------*/ -/* - * Shrink the size of the uIP buffer, routing table and ND cache. - * Set the TCP MSS - */ -#define UIP_CONF_BUFFER_SIZE 500 -#define NETSTACK_MAX_ROUTE_ENTRIES 5 -#define NBR_TABLE_CONF_MAX_NEIGHBORS 5 -#define UIP_CONF_TCP_MSS 128 -/*---------------------------------------------------------------------------*/ -#endif /* PROJECT_CONF_H_ */ -/*---------------------------------------------------------------------------*/ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/resources/res-ble-advd.c b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/resources/res-ble-advd.c deleted file mode 100644 index 8c79067d3..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/resources/res-ble-advd.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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 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. - */ -/*---------------------------------------------------------------------------*/ -/** - * \addtogroup cc13xx-cc26xx-web-demo - * @{ - * - * \file - * CoAP resource to start/stop/configure BLE advertisements - */ -/*---------------------------------------------------------------------------*/ -#include "contiki.h" -#include "net/app-layer/coap/coap.h" -#include "net/app-layer/coap/coap-engine.h" -/*---------------------------------------------------------------------------*/ -#include "rf/ble-beacond.h" -/*---------------------------------------------------------------------------*/ -#include -#include -/*---------------------------------------------------------------------------*/ -#define BLE_NAME_BUF_LEN 32 -/*---------------------------------------------------------------------------*/ -const char *forbidden_payload = "Name to advertise unspecified.\n" - "Use name= in the request"; -/*---------------------------------------------------------------------------*/ -static void -res_ble_post_put_handler(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - size_t len = 0; - const char *text = NULL; - char name[BLE_NAME_BUF_LEN]; - int success = 0; - int rv; - - memset(name, 0, BLE_NAME_BUF_LEN); - - len = coap_get_post_variable(request, "name", &text); - - if(len > 0 && len < BLE_NAME_BUF_LEN) { - memcpy(name, text, len); - rf_ble_beacond_config(0, name); - success = 1; - } - - len = coap_get_post_variable(request, "interval", &text); - - rv = atoi(text); - - if(rv > 0) { - rf_ble_beacond_config((clock_time_t)(rv * CLOCK_SECOND), NULL); - success = 1; - } - - len = coap_get_post_variable(request, "mode", &text); - - if(len) { - if(strncmp(text, "on", len) == 0) { - if(rf_ble_beacond_start()) { - success = 1; - } else { - coap_set_status_code(response, FORBIDDEN_4_03); - coap_set_payload(response, forbidden_payload, - strlen(forbidden_payload)); - return; - } - } else if(strncmp(text, "off", len) == 0) { - rf_ble_beacond_stop(); - success = 1; - } else { - success = 0; - } - } - - if(!success) { - coap_set_status_code(response, BAD_REQUEST_4_00); - } -} -/*---------------------------------------------------------------------------*/ -RESOURCE(res_ble_advd, - "title=\"BLE advd config: POST/PUT name=&mode=on|off" - "&interval=\";rt=\"Control\"", - NULL, - res_ble_post_put_handler, - res_ble_post_put_handler, - NULL); -/*---------------------------------------------------------------------------*/ -/** @} */ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/resources/res-device.c b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/resources/res-device.c deleted file mode 100644 index a0485867b..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/resources/res-device.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (c) 2014, 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 cc13xx-cc26xx-web-demo - * @{ - * - * \file - * CoAP resource handler for CC13xx/CC26xx software and hardware version - */ -/*---------------------------------------------------------------------------*/ -#include "contiki.h" -#include "sys/clock.h" -#include "net/app-layer/coap/coap.h" -#include "net/app-layer/coap/coap-engine.h" -/*---------------------------------------------------------------------------*/ -#include -#include DeviceFamily_constructPath(driverlib/chipinfo.h) -/*---------------------------------------------------------------------------*/ -#include "web-demo.h" -#include "coap-server.h" -/*---------------------------------------------------------------------------*/ -#include -#include -/*---------------------------------------------------------------------------*/ -static const char * -detect_chip(void) -{ - switch(ChipInfo_GetChipType()) { - case CHIP_TYPE_CC1310: return "CC1310"; - case CHIP_TYPE_CC1350: return "CC1350"; - case CHIP_TYPE_CC2620: return "CC2620"; - case CHIP_TYPE_CC2630: return "CC2630"; - case CHIP_TYPE_CC2640: return "CC2640"; - case CHIP_TYPE_CC2650: return "CC2650"; - case CHIP_TYPE_CC2642: return "CC2642"; - case CHIP_TYPE_CC2652: return "CC2652"; - case CHIP_TYPE_CC1312: return "CC1312"; - case CHIP_TYPE_CC1352: return "CC1352"; - case CHIP_TYPE_CC1352P: return "CC1352P"; - default: return "Unknown"; - } -} -/*---------------------------------------------------------------------------*/ -static void -res_get_handler_hw(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - unsigned int accept = -1; - const char *chip = detect_chip(); - - coap_get_header_accept(request, &accept); - - if(accept == -1 || accept == TEXT_PLAIN) { - coap_set_header_content_format(response, TEXT_PLAIN); - snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%s on %s", BOARD_STRING, - chip); - - coap_set_payload(response, (uint8_t *)buffer, strlen((char *)buffer)); - } else if(accept == APPLICATION_JSON) { - coap_set_header_content_format(response, APPLICATION_JSON); - snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{\"HW Ver\":\"%s on %s\"}", - BOARD_STRING, chip); - - coap_set_payload(response, buffer, strlen((char *)buffer)); - } else if(accept == APPLICATION_XML) { - coap_set_header_content_format(response, APPLICATION_XML); - snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, - "", BOARD_STRING, - chip); - - coap_set_payload(response, buffer, strlen((char *)buffer)); - } else { - coap_set_status_code(response, NOT_ACCEPTABLE_4_06); - coap_set_payload(response, coap_server_supported_msg, - strlen(coap_server_supported_msg)); - } -} -/*---------------------------------------------------------------------------*/ -static void -res_get_handler_sw(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - unsigned int accept = -1; - - coap_get_header_accept(request, &accept); - - if(accept == -1 || accept == TEXT_PLAIN) { - coap_set_header_content_format(response, TEXT_PLAIN); - snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%s", CONTIKI_VERSION_STRING); - - coap_set_payload(response, (uint8_t *)buffer, strlen((char *)buffer)); - } else if(accept == APPLICATION_JSON) { - coap_set_header_content_format(response, APPLICATION_JSON); - snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{\"SW Ver\":\"%s\"}", - CONTIKI_VERSION_STRING); - - coap_set_payload(response, buffer, strlen((char *)buffer)); - } else if(accept == APPLICATION_XML) { - coap_set_header_content_format(response, APPLICATION_XML); - snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, - "", CONTIKI_VERSION_STRING); - - coap_set_payload(response, buffer, strlen((char *)buffer)); - } else { - coap_set_status_code(response, NOT_ACCEPTABLE_4_06); - coap_set_payload(response, coap_server_supported_msg, - strlen(coap_server_supported_msg)); - } -} -/*---------------------------------------------------------------------------*/ -static void -res_get_handler_uptime(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - unsigned int accept = -1; - - coap_get_header_accept(request, &accept); - - if(accept == -1 || accept == TEXT_PLAIN) { - coap_set_header_content_format(response, TEXT_PLAIN); - snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%lu", clock_seconds()); - - coap_set_payload(response, (uint8_t *)buffer, strlen((char *)buffer)); - } else if(accept == APPLICATION_JSON) { - coap_set_header_content_format(response, APPLICATION_JSON); - snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{\"uptime\":%lu}", - clock_seconds()); - - coap_set_payload(response, buffer, strlen((char *)buffer)); - } else if(accept == APPLICATION_XML) { - coap_set_header_content_format(response, APPLICATION_XML); - snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, - "", clock_seconds()); - - coap_set_payload(response, buffer, strlen((char *)buffer)); - } else { - coap_set_status_code(response, NOT_ACCEPTABLE_4_06); - coap_set_payload(response, coap_server_supported_msg, - strlen(coap_server_supported_msg)); - } -} -/*---------------------------------------------------------------------------*/ -static void -res_post_handler_cfg_reset(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - web_demo_restore_defaults(); -} -/*---------------------------------------------------------------------------*/ -RESOURCE(res_device_sw, - "title=\"Software version\";rt=\"text\"", - res_get_handler_sw, - NULL, - NULL, - NULL); -/*---------------------------------------------------------------------------*/ -RESOURCE(res_device_uptime, - "title=\"Uptime\";rt=\"seconds\"", - res_get_handler_uptime, - NULL, - NULL, - NULL); -/*---------------------------------------------------------------------------*/ -RESOURCE(res_device_hw, - "title=\"Hardware version\";rt=\"text\"", - res_get_handler_hw, - NULL, - NULL, - NULL); -/*---------------------------------------------------------------------------*/ -RESOURCE(res_device_cfg_reset, - "title=\"Reset Device Config: POST\";rt=\"Control\"", - NULL, res_post_handler_cfg_reset, NULL, NULL); -/*---------------------------------------------------------------------------*/ -/** @} */ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/resources/res-leds.c b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/resources/res-leds.c deleted file mode 100644 index 5e4da11da..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/resources/res-leds.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich - * Copyright (c) 2014, 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 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. - */ -/*---------------------------------------------------------------------------*/ -/** - * \addtogroup cc13xx-cc26xx-web-demo - * @{ - * - * \file - * CoAP resource handler for the CC13xx/CC26xx LEDs. Slightly modified copy of - * the one found in Contiki's original CoAP example. - * \author - * Matthias Kovatsch (original) - */ -/*---------------------------------------------------------------------------*/ -#include "contiki.h" -#include "dev/leds.h" -#include "net/app-layer/coap/coap-engine.h" -/*---------------------------------------------------------------------------*/ -#include -/*---------------------------------------------------------------------------*/ -static void -res_post_put_handler(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - size_t len = 0; - const char *color = NULL; - const char *mode = NULL; - uint8_t led = 0; - int success = 1; - - if((len = coap_get_query_variable(request, "color", &color))) { - if(strncmp(color, "r", len) == 0) { - led = LEDS_RED; - } else if(strncmp(color, "g", len) == 0) { - led = LEDS_GREEN; -#if BOARD_SMARTRF06EB - } else if(strncmp(color, "y", len) == 0) { - led = LEDS_YELLOW; - } else if(strncmp(color, "o", len) == 0) { - led = LEDS_ORANGE; -#endif - } else { - success = 0; - } - } else { - success = 0; - } - - if(success && (len = coap_get_post_variable(request, "mode", &mode))) { - if(strncmp(mode, "on", len) == 0) { - leds_on(led); - } else if(strncmp(mode, "off", len) == 0) { - leds_off(led); - } else { - success = 0; - } - } else { - success = 0; - } - - if(!success) { - coap_set_status_code(response, BAD_REQUEST_4_00); - } -} -/*---------------------------------------------------------------------------*/ -/* - * A simple actuator example, depending on the color query parameter and post - * variable mode, corresponding led is activated or deactivated - */ -#if BOARD_SENSORTAG || BOARD_LAUNCHPAD -#define RESOURCE_PARAMS "r|g" -#elif BOARD_SMARTRF06EB -#define RESOURCE_PARAMS "r|g|y|o" -#endif - -RESOURCE(res_leds, - "title=\"LEDs: ?color=" RESOURCE_PARAMS ", POST/PUT mode=on|off\";rt=\"Control\"", - NULL, - res_post_put_handler, - res_post_put_handler, - NULL); -/*---------------------------------------------------------------------------*/ -/** @} */ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/resources/res-net.c b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/resources/res-net.c deleted file mode 100644 index b1f6b8725..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/resources/res-net.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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 cc13xx-cc26xx-web-demo - * @{ - * - * \file - * CoAP resource handler for network-related resources - */ -/*---------------------------------------------------------------------------*/ -#include "contiki.h" -#include "net/ipv6/uip-ds6.h" -#include "net/app-layer/coap/coap.h" -#include "net/app-layer/coap/coap-engine.h" -/*---------------------------------------------------------------------------*/ -#include "coap-server.h" -#include "web-demo.h" -/*---------------------------------------------------------------------------*/ -#include -#include -/*---------------------------------------------------------------------------*/ -extern int def_rt_rssi; -/*---------------------------------------------------------------------------*/ -static void -res_get_handler_parent_rssi(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - unsigned int accept = -1; - - coap_get_header_accept(request, &accept); - - if(accept == -1 || accept == TEXT_PLAIN) { - coap_set_header_content_format(response, TEXT_PLAIN); - snprintf((char *)buffer, COAP_MAX_CHUNK_SIZE, "%d", def_rt_rssi); - - coap_set_payload(response, (uint8_t *)buffer, strlen((char *)buffer)); - } else if(accept == APPLICATION_JSON) { - coap_set_header_content_format(response, APPLICATION_JSON); - snprintf((char *)buffer, COAP_MAX_CHUNK_SIZE, "{\"Parent RSSI\":\"%d\"}", - def_rt_rssi); - - coap_set_payload(response, buffer, strlen((char *)buffer)); - } else if(accept == APPLICATION_XML) { - coap_set_header_content_format(response, APPLICATION_XML); - snprintf((char *)buffer, COAP_MAX_CHUNK_SIZE, - "", def_rt_rssi); - - coap_set_payload(response, buffer, strlen((char *)buffer)); - } else { - coap_set_status_code(response, NOT_ACCEPTABLE_4_06); - coap_set_payload(response, coap_server_supported_msg, - strlen(coap_server_supported_msg)); - } -} -/*---------------------------------------------------------------------------*/ -static void -res_get_handler_pref_parent(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - unsigned int accept = -1; - char def_rt_str[64]; - - coap_get_header_accept(request, &accept); - - memset(def_rt_str, 0, sizeof(def_rt_str)); - web_demo_ipaddr_sprintf(def_rt_str, sizeof(def_rt_str), - uip_ds6_defrt_choose()); - - if(accept == -1 || accept == TEXT_PLAIN) { - coap_set_header_content_format(response, TEXT_PLAIN); - snprintf((char *)buffer, COAP_MAX_CHUNK_SIZE, "%s", def_rt_str); - - coap_set_payload(response, (uint8_t *)buffer, strlen((char *)buffer)); - } else if(accept == APPLICATION_JSON) { - coap_set_header_content_format(response, APPLICATION_JSON); - snprintf((char *)buffer, COAP_MAX_CHUNK_SIZE, "{\"Parent\":\"%s\"}", - def_rt_str); - - coap_set_payload(response, buffer, strlen((char *)buffer)); - } else if(accept == APPLICATION_XML) { - coap_set_header_content_format(response, APPLICATION_XML); - snprintf((char *)buffer, COAP_MAX_CHUNK_SIZE, - "", def_rt_str); - - coap_set_payload(response, buffer, strlen((char *)buffer)); - } else { - coap_set_status_code(response, NOT_ACCEPTABLE_4_06); - coap_set_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); -/*---------------------------------------------------------------------------*/ -/** @} */ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/resources/res-sensors.c b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/resources/res-sensors.c deleted file mode 100644 index 27f93f8f2..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/resources/res-sensors.c +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Copyright (c) 2014, 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 cc13xx-cc26xx-web-demo - * @{ - * - * \file - * CoAP resource handler for the Sensortag sensors - */ -/*---------------------------------------------------------------------------*/ -#include "contiki.h" -#include "net/app-layer/coap/coap.h" -#include "net/app-layer/coap/coap-engine.h" -/*---------------------------------------------------------------------------*/ -#include "web-demo.h" -#include "coap-server.h" -/*---------------------------------------------------------------------------*/ -#include -#include -#include -/*---------------------------------------------------------------------------*/ -/* - * Generic resource handler for any sensor in this example. Ultimately gets - * called by all handlers and populates the CoAP response - */ -static void -res_get_handler_all(int sens_type, coap_message_t *request, - coap_message_t *response, - uint8_t *buffer, uint16_t preferred_size, int32_t *offset) -{ - unsigned int accept = -1; - const web_demo_sensor_reading_t *reading; - - reading = web_demo_sensor_lookup(sens_type); - - if(reading == NULL) { - coap_set_status_code(response, NOT_FOUND_4_04); - coap_set_payload(response, coap_server_not_found_msg, - strlen(coap_server_not_found_msg)); - return; - } - - coap_get_header_accept(request, &accept); - - if(accept == -1 || accept == TEXT_PLAIN) { - coap_set_header_content_format(response, TEXT_PLAIN); - snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%s", reading->converted); - - coap_set_payload(response, (uint8_t *)buffer, - strlen((char *)buffer)); - } else if(accept == APPLICATION_JSON) { - coap_set_header_content_format(response, APPLICATION_JSON); - snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{\"%s\":%s}", - reading->descr, reading->converted); - - coap_set_payload(response, buffer, strlen((char *)buffer)); - } else if(accept == APPLICATION_XML) { - coap_set_header_content_format(response, APPLICATION_XML); - snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, - "<%s val=\"%s\" unit=\"%s\"/>", reading->xml_element, - reading->converted, reading->units); - - coap_set_payload(response, buffer, strlen((char *)buffer)); - } else { - coap_set_status_code(response, NOT_ACCEPTABLE_4_06); - coap_set_payload(response, coap_server_supported_msg, - strlen(coap_server_supported_msg)); - } -} -/*---------------------------------------------------------------------------*/ -/* BatMon resources and handler: Temperature, Voltage */ -static void -res_get_handler_batmon_temp(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - res_get_handler_all(WEB_DEMO_SENSOR_BATMON_TEMP, request, response, - buffer, preferred_size, offset); -} -/*---------------------------------------------------------------------------*/ -static void -res_get_handler_batmon_volt(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - res_get_handler_all(WEB_DEMO_SENSOR_BATMON_VOLT, request, response, - buffer, preferred_size, offset); -} -/*---------------------------------------------------------------------------*/ -RESOURCE(res_batmon_temp, "title=\"Battery Temp\";rt=\"C\"", - res_get_handler_batmon_temp, NULL, NULL, NULL); -/*---------------------------------------------------------------------------*/ -RESOURCE(res_batmon_volt, "title=\"Battery Voltage\";rt=\"mV\"", - res_get_handler_batmon_volt, NULL, NULL, NULL); -/*---------------------------------------------------------------------------*/ -#if WEB_DEMO_ADC_DEMO -/*---------------------------------------------------------------------------*/ -static void -res_get_handler_adc_dio23(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - res_get_handler_all(WEB_DEMO_SENSOR_ADC_DIO23, request, response, - buffer, preferred_size, offset); -} -/*---------------------------------------------------------------------------*/ -RESOURCE(res_adc_dio23, "title=\"ADC DIO23\";rt=\"mV\"", - res_get_handler_adc_dio23, NULL, NULL, NULL); -/*---------------------------------------------------------------------------*/ -#endif -/*---------------------------------------------------------------------------*/ -#if BOARD_SENSORTAG -/*---------------------------------------------------------------------------*/ -/* MPU resources and handler: Accelerometer and Gyro */ -static void -res_get_handler_mpu_acc_x(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - res_get_handler_all(WEB_DEMO_SENSOR_MPU_ACC_X, request, response, - buffer, preferred_size, offset); -} -/*---------------------------------------------------------------------------*/ -static void -res_get_handler_mpu_acc_y(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - res_get_handler_all(WEB_DEMO_SENSOR_MPU_ACC_Y, request, response, - buffer, preferred_size, offset); -} -/*---------------------------------------------------------------------------*/ -static void -res_get_handler_mpu_acc_z(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - res_get_handler_all(WEB_DEMO_SENSOR_MPU_ACC_Z, request, response, - buffer, preferred_size, offset); -} -/*---------------------------------------------------------------------------*/ -static void -res_get_handler_mpu_gyro_x(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - res_get_handler_all(WEB_DEMO_SENSOR_MPU_GYRO_X, request, response, - buffer, preferred_size, offset); -} -/*---------------------------------------------------------------------------*/ -static void -res_get_handler_mpu_gyro_y(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - res_get_handler_all(WEB_DEMO_SENSOR_MPU_GYRO_Y, request, response, - buffer, preferred_size, offset); -} -/*---------------------------------------------------------------------------*/ -static void -res_get_handler_mpu_gyro_z(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - res_get_handler_all(WEB_DEMO_SENSOR_MPU_GYRO_Z, request, response, - buffer, preferred_size, offset); -} -/*---------------------------------------------------------------------------*/ -RESOURCE(res_mpu_acc_x, "title=\"Acc X\";rt=\"G\"", res_get_handler_mpu_acc_x, - NULL, NULL, NULL); -RESOURCE(res_mpu_acc_y, "title=\"Acc Y\";rt=\"G\"", res_get_handler_mpu_acc_y, - NULL, NULL, NULL); -RESOURCE(res_mpu_acc_z, "title=\"Acc Z\";rt=\"G\"", res_get_handler_mpu_acc_z, - NULL, NULL, NULL); - -RESOURCE(res_mpu_gyro_x, "title=\"Gyro X\";rt=\"deg/sec\"", - res_get_handler_mpu_gyro_x, NULL, NULL, NULL); -RESOURCE(res_mpu_gyro_y, "title=\"Gyro Y\";rt=\"deg/sec\"", - res_get_handler_mpu_gyro_y, NULL, NULL, NULL); -RESOURCE(res_mpu_gyro_z, "title=\"Gyro Z\";rt=\"deg/sec\"", - res_get_handler_mpu_gyro_z, NULL, NULL, NULL); -/*---------------------------------------------------------------------------*/ -/* TMP sensor resources and handlers: Object, Ambient */ -static void -res_get_handler_obj_temp(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - res_get_handler_all(WEB_DEMO_SENSOR_TMP_OBJECT, request, response, - buffer, preferred_size, offset); -} -/*---------------------------------------------------------------------------*/ -static void -res_get_handler_amb_temp(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - res_get_handler_all(WEB_DEMO_SENSOR_TMP_AMBIENT, request, response, - buffer, preferred_size, offset); -} -/*---------------------------------------------------------------------------*/ -RESOURCE(res_tmp007_obj, "title=\"Temperature (Object)\";rt=\"C\"", - res_get_handler_obj_temp, NULL, NULL, NULL); - -RESOURCE(res_tmp007_amb, "title=\"Temperature (Ambient)\";rt=\"C\"", - res_get_handler_amb_temp, NULL, NULL, NULL); -/*---------------------------------------------------------------------------*/ -/* BMP sensor resources: Temperature, Pressure */ -static void -res_get_handler_bmp_temp(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - res_get_handler_all(WEB_DEMO_SENSOR_BMP_TEMP, request, response, - buffer, preferred_size, offset); -} -/*---------------------------------------------------------------------------*/ -static void -res_get_handler_bmp_press(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - res_get_handler_all(WEB_DEMO_SENSOR_BMP_PRES, request, response, - buffer, preferred_size, offset); -} -/*---------------------------------------------------------------------------*/ -RESOURCE(res_bmp280_temp, "title=\"Barometer (Temperature)\";rt=\"C\"", - res_get_handler_bmp_temp, NULL, NULL, NULL); - -RESOURCE(res_bmp280_press, - "title=\"Barometer (Pressure)\";rt=\"hPa (hectopascal / millibar)\"", - res_get_handler_bmp_press, NULL, NULL, NULL); -/*---------------------------------------------------------------------------*/ -/* HDC1000 sensor resources and handler: Temperature, Pressure */ -static void -res_get_handler_hdc_temp(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - res_get_handler_all(WEB_DEMO_SENSOR_HDC_TEMP, request, response, - buffer, preferred_size, offset); -} -/*---------------------------------------------------------------------------*/ -static void -res_get_handler_hdc_humidity(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - res_get_handler_all(WEB_DEMO_SENSOR_HDC_HUMIDITY, request, response, - buffer, preferred_size, offset); -} -/*---------------------------------------------------------------------------*/ -RESOURCE(res_hdc1000_temp, "title=\"Temperature\";rt=\"C\"", - res_get_handler_hdc_temp, 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 -res_get_handler_opt(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - res_get_handler_all(WEB_DEMO_SENSOR_OPT_LIGHT, request, response, - buffer, preferred_size, offset); -} -/*---------------------------------------------------------------------------*/ -RESOURCE(res_opt3001_light, "title=\"Illuminance\";rt=\"Lux\"", - res_get_handler_opt, NULL, NULL, NULL); -/*---------------------------------------------------------------------------*/ -#endif /* BOARD_SENSORTAG */ -/*---------------------------------------------------------------------------*/ -/** @} */ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/resources/res-toggle-leds.c b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/resources/res-toggle-leds.c deleted file mode 100644 index 0ba4c2881..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/resources/res-toggle-leds.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich - * Copyright (c) 2014, 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 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. - */ -/*---------------------------------------------------------------------------*/ -/** - * \addtogroup cc13xx-cc26xx-web-demo - * @{ - * - * \file - * CoAP resource to toggle LEDs. Slightly modified copy of the one found - * in Contiki's original CoAP example. - * \author - * Matthias Kovatsch (original) - */ -/*---------------------------------------------------------------------------*/ -#include "contiki.h" -#include "dev/leds.h" -#include "net/app-layer/coap/coap-engine.h" -/*---------------------------------------------------------------------------*/ -#include -/*---------------------------------------------------------------------------*/ -static void -res_post_handler_red(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - leds_toggle(LEDS_RED); -} -/*---------------------------------------------------------------------------*/ -static void -res_post_handler_green(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - leds_toggle(LEDS_GREEN); -} -/*---------------------------------------------------------------------------*/ -/* Toggles the red led */ -RESOURCE(res_toggle_red, - "title=\"Red LED\";rt=\"Control\"", - NULL, - res_post_handler_red, - NULL, - NULL); - -/* Toggles the green led */ -RESOURCE(res_toggle_green, - "title=\"Green LED\";rt=\"Control\"", - NULL, - res_post_handler_green, - NULL, - NULL); -/*---------------------------------------------------------------------------*/ -/* An additional 2 LEDs on the Srf */ -#if BOARD_SMARTRF06EB -/*---------------------------------------------------------------------------*/ -static void -res_post_handler_yellow(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - leds_toggle(LEDS_YELLOW); -} -/*---------------------------------------------------------------------------*/ -static void -res_post_handler_orange(coap_message_t *request, coap_message_t *response, - uint8_t *buffer, - uint16_t preferred_size, int32_t *offset) -{ - leds_toggle(LEDS_ORANGE); -} -/*---------------------------------------------------------------------------*/ -/* Toggles the yellow led */ -RESOURCE(res_toggle_yellow, - "title=\"Yellow LED\";rt=\"Control\"", - NULL, - res_post_handler_yellow, - NULL, - NULL); - -/* Toggles the orange led */ -RESOURCE(res_toggle_orange, - "title=\"Orange LED\";rt=\"Control\"", - NULL, - res_post_handler_orange, - NULL, - NULL); -#endif -/*---------------------------------------------------------------------------*/ -/** @} */ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/web-demo.c b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/web-demo.c deleted file mode 100644 index 8e729576d..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/web-demo.c +++ /dev/null @@ -1,1054 +0,0 @@ -/* - * Copyright (c) 2014, 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 cc13xx-cc26xx-web-demo - * @{ - * - * \file - * Main module for the CC13xx/CC26xx web demo. Activates on-device resources, - * takes sensor readings periodically and caches them for all other modules - * to use. - */ -/*---------------------------------------------------------------------------*/ -#include "contiki.h" -#include "contiki-net.h" -#include "dev/button-hal.h" -#include "dev/ext-flash/ext-flash.h" -#include "sys/process.h" -#include "net/ipv6/sicslowpan.h" -#include "net/app-layer/coap/coap-engine.h" -#include "lib/sensors.h" -#include "lib/list.h" -/*---------------------------------------------------------------------------*/ -#include -#include -/*---------------------------------------------------------------------------*/ -#include "board-peripherals.h" -#include "batmon-sensor.h" -/*---------------------------------------------------------------------------*/ -#include "web-demo.h" -#include "httpd-simple.h" -#include "mqtt-client.h" -#include "coap-server.h" -/*---------------------------------------------------------------------------*/ -#include -#include -#include -#include -/*---------------------------------------------------------------------------*/ -PROCESS_NAME(cetic_6lbr_client_process); -PROCESS(web_demo_process, "CC13xx/CC26xx Web Demo"); -/*---------------------------------------------------------------------------*/ -/* - * Update sensor readings in a staggered fashion every SENSOR_READING_PERIOD - * ticks + a random interval between 0 and SENSOR_READING_RANDOM ticks - */ -#define SENSOR_READING_PERIOD (CLOCK_SECOND * 20) -#define SENSOR_READING_RANDOM (CLOCK_SECOND << 4) - -struct ctimer batmon_timer; - -#if BOARD_SENSORTAG -struct ctimer bmp_timer, hdc_timer, tmp_timer, opt_timer, mpu_timer; -#endif -/*---------------------------------------------------------------------------*/ -/* Provide visible feedback via LEDS while searching for a network */ -#define NO_NET_LED_DURATION (WEB_DEMO_NET_CONNECT_PERIODIC >> 1) - -static struct etimer et; -static struct ctimer ct; -/*---------------------------------------------------------------------------*/ -/* Parent RSSI functionality */ -#if 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 -/*---------------------------------------------------------------------------*/ -#if WEB_DEMO_ADC_DEMO -PROCESS(adc_process, "ADC process"); - -static uint_fast16_t single_adc_sample; -static struct etimer et_adc; -#endif -/*---------------------------------------------------------------------------*/ -process_event_t web_demo_publish_event; -process_event_t web_demo_config_loaded_event; -process_event_t web_demo_load_config_defaults; -/*---------------------------------------------------------------------------*/ -/* Saved settings on flash: store, offset, magic */ -#define CONFIG_FLASH_OFFSET 0 -#define CONFIG_MAGIC 0xCC265002 - -web_demo_config_t web_demo_config; -/*---------------------------------------------------------------------------*/ -/* A cache of sensor values. Updated periodically or upon key press */ -LIST(sensor_list); -/*---------------------------------------------------------------------------*/ -/* The objects representing sensors used in this demo */ -#define DEMO_SENSOR(name, type, descr, xml_element, form_field, units) \ - web_demo_sensor_reading_t name##_reading = \ - { NULL, 0, 0, descr, xml_element, form_field, units, type, 1, 1 } - -/* CC13xx/CC26xx sensors */ -DEMO_SENSOR(batmon_temp, WEB_DEMO_SENSOR_BATMON_TEMP, - "Battery Temp", "battery-temp", "batmon_temp", - WEB_DEMO_UNIT_TEMP); -DEMO_SENSOR(batmon_volt, WEB_DEMO_SENSOR_BATMON_VOLT, - "Battery Volt", "battery-volt", "batmon_volt", - WEB_DEMO_UNIT_VOLT); - -#if WEB_DEMO_ADC_DEMO -DEMO_SENSOR(adc_dio23, WEB_DEMO_SENSOR_ADC_DIO23, - "ADC DIO23", "adc-dio23", "adc_dio23", - WEB_DEMO_UNIT_VOLT); -#endif - -/* Sensortag sensors */ -#if BOARD_SENSORTAG -DEMO_SENSOR(bmp_pres, WEB_DEMO_SENSOR_BMP_PRES, - "Air Pressure", "air-pressure", "bmp_pres", - WEB_DEMO_UNIT_PRES); -DEMO_SENSOR(bmp_temp, WEB_DEMO_SENSOR_BMP_TEMP, - "Air Temp", "air-temp", "bmp_temp", - WEB_DEMO_UNIT_TEMP); -DEMO_SENSOR(hdc_temp, WEB_DEMO_SENSOR_HDC_TEMP, - "HDC Temp", "hdc-temp", "hdc_temp", - WEB_DEMO_UNIT_TEMP); -DEMO_SENSOR(hdc_hum, WEB_DEMO_SENSOR_HDC_HUMIDITY, - "HDC Humidity", "hdc-humidity", "hdc_hum", - WEB_DEMO_UNIT_HUMIDITY); -DEMO_SENSOR(tmp_amb, WEB_DEMO_SENSOR_TMP_AMBIENT, - "Ambient Temp", "ambient-temp", "tmp_amb", - WEB_DEMO_UNIT_TEMP); -DEMO_SENSOR(tmp_obj, WEB_DEMO_SENSOR_TMP_OBJECT, - "Object Temp", "object-temp", "tmp_obj", - WEB_DEMO_UNIT_TEMP); -DEMO_SENSOR(opt, WEB_DEMO_SENSOR_OPT_LIGHT, - "Light", "light", "light", - WEB_DEMO_UNIT_LIGHT); - -/* MPU Readings */ -DEMO_SENSOR(mpu_acc_x, WEB_DEMO_SENSOR_MPU_ACC_X, - "Acc X", "acc-x", "acc_x", - WEB_DEMO_UNIT_ACC); -DEMO_SENSOR(mpu_acc_y, WEB_DEMO_SENSOR_MPU_ACC_Y, - "Acc Y", "acc-y", "acc_y", - WEB_DEMO_UNIT_ACC); -DEMO_SENSOR(mpu_acc_z, WEB_DEMO_SENSOR_MPU_ACC_Z, - "Acc Z", "acc-z", "acc_z", - WEB_DEMO_UNIT_ACC); - -DEMO_SENSOR(mpu_gyro_x, WEB_DEMO_SENSOR_MPU_GYRO_X, - "Gyro X", "gyro-x", "gyro_x", - WEB_DEMO_UNIT_GYRO); -DEMO_SENSOR(mpu_gyro_y, WEB_DEMO_SENSOR_MPU_GYRO_Y, - "Gyro Y", "gyro-y", "gyro_y", - WEB_DEMO_UNIT_GYRO); -DEMO_SENSOR(mpu_gyro_z, WEB_DEMO_SENSOR_MPU_GYRO_Z, - "Gyro Z", "gyro-z", "gyro_Z", - WEB_DEMO_UNIT_GYRO); -#endif -/*---------------------------------------------------------------------------*/ -#if BOARD_SENSORTAG -static void init_bmp_reading(void *data); -static void init_light_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 -/*---------------------------------------------------------------------------*/ -static void -publish_led_off(void *d) -{ - leds_off(WEB_DEMO_STATUS_LED); -} -/*---------------------------------------------------------------------------*/ -static void -save_config() -{ - /* Dump current running config to flash */ -#if BOARD_SENSORTAG || BOARD_LAUNCHPAD - int rv; - web_demo_sensor_reading_t *reading = NULL; - - rv = ext_flash_open(NULL); - - if(!rv) { - printf("Could not open flash to save config\n"); - ext_flash_close(NULL); - return; - } - - rv = ext_flash_erase(NULL, CONFIG_FLASH_OFFSET, sizeof(web_demo_config_t)); - - if(!rv) { - printf("Error erasing flash\n"); - } else { - web_demo_config.magic = CONFIG_MAGIC; - web_demo_config.len = sizeof(web_demo_config_t); - web_demo_config.sensors_bitmap = 0; - - for(reading = list_head(sensor_list); - reading != NULL; - reading = list_item_next(reading)) { - if(reading->publish) { - web_demo_config.sensors_bitmap |= (1 << reading->type); - } - } - - rv = ext_flash_write(NULL, CONFIG_FLASH_OFFSET, sizeof(web_demo_config_t), - (uint8_t *)&web_demo_config); - if(!rv) { - printf("Error saving config\n"); - } - } - - ext_flash_close(NULL); -#endif -} -/*---------------------------------------------------------------------------*/ -static void -load_config() -{ -#if BOARD_SENSORTAG || BOARD_LAUNCHPAD - /* Read from flash into a temp buffer */ - web_demo_config_t tmp_cfg; - web_demo_sensor_reading_t *reading = NULL; - - int rv = ext_flash_open(NULL); - - if(!rv) { - printf("Could not open flash to load config\n"); - ext_flash_close(NULL); - return; - } - - rv = ext_flash_read(NULL, CONFIG_FLASH_OFFSET, sizeof(tmp_cfg), - (uint8_t *)&tmp_cfg); - - ext_flash_close(NULL); - - if(!rv) { - printf("Error loading config\n"); - return; - } - - if(tmp_cfg.magic == CONFIG_MAGIC && tmp_cfg.len == sizeof(tmp_cfg)) { - memcpy(&web_demo_config, &tmp_cfg, sizeof(web_demo_config)); - } - - for(reading = list_head(sensor_list); - reading != NULL; - reading = list_item_next(reading)) { - if(web_demo_config.sensors_bitmap & (1 << reading->type)) { - reading->publish = 1; - } else { - reading->publish = 0; - snprintf(reading->converted, WEB_DEMO_CONVERTED_LEN, "\"N/A\""); - } - } -#endif -} -/*---------------------------------------------------------------------------*/ -/* Don't start everything here, we need to dictate order of initialisation */ -AUTOSTART_PROCESSES(&web_demo_process); -/*---------------------------------------------------------------------------*/ -int -web_demo_ipaddr_sprintf(char *buf, uint8_t buf_len, - const uip_ipaddr_t *addr) -{ - uint16_t a; - uint8_t len = 0; - int i, f; - for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) { - a = (addr->u8[i] << 8) + addr->u8[i + 1]; - if(a == 0 && f >= 0) { - if(f++ == 0) { - len += snprintf(&buf[len], buf_len - len, "::"); - } - } else { - if(f > 0) { - f = -1; - } else if(i > 0) { - len += snprintf(&buf[len], buf_len - len, ":"); - } - len += snprintf(&buf[len], buf_len - len, "%x", a); - } - } - - return len; -} -/*---------------------------------------------------------------------------*/ -const web_demo_sensor_reading_t * -web_demo_sensor_lookup(int sens_type) -{ - web_demo_sensor_reading_t *reading = NULL; - - for(reading = list_head(sensor_list); - reading != NULL; - reading = list_item_next(reading)) { - if(reading->type == sens_type) { - return reading; - } - } - - return NULL; -} -/*---------------------------------------------------------------------------*/ -const web_demo_sensor_reading_t * -web_demo_sensor_first() -{ - return list_head(sensor_list); -} -/*---------------------------------------------------------------------------*/ -void -web_demo_restore_defaults(void) -{ - web_demo_sensor_reading_t *reading = NULL; - - leds_on(LEDS_ALL); - - for(reading = list_head(sensor_list); - reading != NULL; - reading = list_item_next(reading)) { - reading->publish = 1; - } - -#if WEB_DEMO_MQTT_CLIENT - process_post_synch(&mqtt_client_process, - web_demo_load_config_defaults, NULL); -#endif - -#if WEB_DEMO_NET_UART - process_post_synch(&net_uart_process, web_demo_load_config_defaults, - NULL); -#endif - - save_config(); - - leds_off(LEDS_ALL); -} -/*---------------------------------------------------------------------------*/ -static int -defaults_post_handler(char *key, int key_len, char *val, int val_len) -{ - if(key_len != strlen("defaults") || - strncasecmp(key, "defaults", strlen("defaults")) != 0) { - /* Not ours */ - return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; - } - - web_demo_restore_defaults(); - - return HTTPD_SIMPLE_POST_HANDLER_OK; -} -/*---------------------------------------------------------------------------*/ -static int -sensor_readings_handler(char *key, int key_len, char *val, int val_len) -{ - web_demo_sensor_reading_t *reading = NULL; - int rv; - - for(reading = list_head(sensor_list); - reading != NULL; - reading = list_item_next(reading)) { - if(key_len == strlen(reading->form_field) && - strncmp(reading->form_field, key, strlen(key)) == 0) { - - rv = atoi(val); - - /* Be pedantic: only accept 0 and 1, not just any non-zero value */ - if(rv == 0) { - reading->publish = 0; - snprintf(reading->converted, WEB_DEMO_CONVERTED_LEN, "\"N/A\""); - } else if(rv == 1) { - reading->publish = 1; - } else { - return HTTPD_SIMPLE_POST_HANDLER_ERROR; - } - - return HTTPD_SIMPLE_POST_HANDLER_OK; - } - } - - return HTTPD_SIMPLE_POST_HANDLER_UNKNOWN; -} -/*---------------------------------------------------------------------------*/ -#if 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 < WEB_DEMO_RSSI_MEASURE_INTERVAL_MIN || - rv > WEB_DEMO_RSSI_MEASURE_INTERVAL_MAX) { - return HTTPD_SIMPLE_POST_HANDLER_ERROR; - } - - 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(defaults, defaults_post_handler); - -#if 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, - WEB_DEMO_ECHO_REQ_PAYLOAD_LEN); -} -#endif -/*---------------------------------------------------------------------------*/ -static void -get_batmon_reading(void *data) -{ - int value; - char *buf; - clock_time_t next = SENSOR_READING_PERIOD + - (random_rand() % SENSOR_READING_RANDOM); - - if(batmon_temp_reading.publish) { - value = batmon_sensor.value(BATMON_SENSOR_TYPE_TEMP); - if(value != BATMON_SENSOR_READING_ERROR) { - batmon_temp_reading.raw = value; - - buf = batmon_temp_reading.converted; - memset(buf, 0, WEB_DEMO_CONVERTED_LEN); - snprintf(buf, WEB_DEMO_CONVERTED_LEN, "%d", value); - } - } - - if(batmon_volt_reading.publish) { - value = batmon_sensor.value(BATMON_SENSOR_TYPE_VOLT); - if(value != BATMON_SENSOR_READING_ERROR) { - batmon_volt_reading.raw = value; - - buf = batmon_volt_reading.converted; - memset(buf, 0, WEB_DEMO_CONVERTED_LEN); - snprintf(buf, WEB_DEMO_CONVERTED_LEN, "%d", (value * 125) >> 5); - } - } - - ctimer_set(&batmon_timer, next, get_batmon_reading, NULL); -} -/*---------------------------------------------------------------------------*/ -#if WEB_DEMO_ADC_DEMO -static void -get_adc_reading(void *data) -{ - int value; - char *buf; - - if(adc_dio23_reading.publish) { - value = single_adc_sample; - buf = adc_dio23_reading.converted; - memset(buf, 0, WEB_DEMO_CONVERTED_LEN); - snprintf(buf, WEB_DEMO_CONVERTED_LEN, "%d", (value * 4300) >> 12); - } -} -#endif -/*---------------------------------------------------------------------------*/ -#if BOARD_SENSORTAG -/*---------------------------------------------------------------------------*/ -static void -compare_and_update(web_demo_sensor_reading_t *reading) -{ - if(reading->last == reading->raw) { - reading->changed = 0; - } else { - reading->last = reading->raw; - reading->changed = 1; - } -} -/*---------------------------------------------------------------------------*/ -static void -print_mpu_reading(int reading, char *buf) -{ - char *loc_buf = buf; - - if(reading < 0) { - sprintf(loc_buf, "-"); - reading = -reading; - loc_buf++; - } - - sprintf(loc_buf, "%d.%02d", reading / 100, reading % 100); -} -/*---------------------------------------------------------------------------*/ -static void -get_bmp_reading() -{ - int value; - char *buf; - clock_time_t next = SENSOR_READING_PERIOD + - (random_rand() % SENSOR_READING_RANDOM); - - if(bmp_pres_reading.publish) { - value = bmp_280_sensor.value(BMP_280_SENSOR_TYPE_PRESS); - if(value != BMP_280_READING_ERROR) { - bmp_pres_reading.raw = value; - - compare_and_update(&bmp_pres_reading); - - buf = bmp_pres_reading.converted; - memset(buf, 0, WEB_DEMO_CONVERTED_LEN); - snprintf(buf, WEB_DEMO_CONVERTED_LEN, "%d.%02d", value / 100, - value % 100); - } - } - - if(bmp_temp_reading.publish) { - value = bmp_280_sensor.value(BMP_280_SENSOR_TYPE_TEMP); - if(value != BMP_280_READING_ERROR) { - bmp_temp_reading.raw = value; - - compare_and_update(&bmp_temp_reading); - - buf = bmp_temp_reading.converted; - memset(buf, 0, WEB_DEMO_CONVERTED_LEN); - snprintf(buf, WEB_DEMO_CONVERTED_LEN, "%d.%02d", value / 100, - value % 100); - } - } - - SENSORS_DEACTIVATE(bmp_280_sensor); - - ctimer_set(&bmp_timer, next, init_bmp_reading, NULL); -} -/*---------------------------------------------------------------------------*/ -static void -get_tmp_reading() -{ - int value; - char *buf; - clock_time_t next = SENSOR_READING_PERIOD + - (random_rand() % SENSOR_READING_RANDOM); - - if(tmp_amb_reading.publish || tmp_obj_reading.publish) { - if(tmp_007_sensor.value(TMP_007_TYPE_ALL) == - TMP_007_READING_ERROR) { - - SENSORS_DEACTIVATE(tmp_007_sensor); - ctimer_set(&tmp_timer, next, init_tmp_reading, NULL); - } - } - - if(tmp_amb_reading.publish) { - value = tmp_007_sensor.value(TMP_007_TYPE_AMBIENT); - tmp_amb_reading.raw = value; - - compare_and_update(&tmp_amb_reading); - - buf = tmp_amb_reading.converted; - memset(buf, 0, WEB_DEMO_CONVERTED_LEN); - snprintf(buf, WEB_DEMO_CONVERTED_LEN, "%d.%03d", value / 1000, - value % 1000); - } - - if(tmp_obj_reading.publish) { - value = tmp_007_sensor.value(TMP_007_TYPE_OBJECT); - tmp_obj_reading.raw = value; - - compare_and_update(&tmp_obj_reading); - - buf = tmp_obj_reading.converted; - memset(buf, 0, WEB_DEMO_CONVERTED_LEN); - snprintf(buf, WEB_DEMO_CONVERTED_LEN, "%d.%03d", value / 1000, - value % 1000); - } - - SENSORS_DEACTIVATE(tmp_007_sensor); - - ctimer_set(&tmp_timer, next, init_tmp_reading, NULL); -} -/*---------------------------------------------------------------------------*/ -static void -get_hdc_reading() -{ - int value; - char *buf; - clock_time_t next = SENSOR_READING_PERIOD + - (random_rand() % SENSOR_READING_RANDOM); - - if(hdc_temp_reading.publish) { - value = hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_TEMP); - if(value != HDC_1000_READING_ERROR) { - hdc_temp_reading.raw = value; - - compare_and_update(&hdc_temp_reading); - - buf = hdc_temp_reading.converted; - memset(buf, 0, WEB_DEMO_CONVERTED_LEN); - snprintf(buf, WEB_DEMO_CONVERTED_LEN, "%d.%02d", value / 100, - value % 100); - } - } - - if(hdc_hum_reading.publish) { - value = hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_HUMID); - if(value != HDC_1000_READING_ERROR) { - hdc_hum_reading.raw = value; - - compare_and_update(&hdc_hum_reading); - - buf = hdc_hum_reading.converted; - memset(buf, 0, WEB_DEMO_CONVERTED_LEN); - snprintf(buf, WEB_DEMO_CONVERTED_LEN, "%d.%02d", value / 100, - value % 100); - } - } - - ctimer_set(&hdc_timer, next, init_hdc_reading, NULL); -} -/*---------------------------------------------------------------------------*/ -static void -get_light_reading() -{ - int value; - char *buf; - clock_time_t next = SENSOR_READING_PERIOD + - (random_rand() % SENSOR_READING_RANDOM); - - value = opt_3001_sensor.value(0); - - if(value != OPT_3001_READING_ERROR) { - opt_reading.raw = value; - - compare_and_update(&opt_reading); - - buf = opt_reading.converted; - memset(buf, 0, WEB_DEMO_CONVERTED_LEN); - snprintf(buf, WEB_DEMO_CONVERTED_LEN, "%d.%02d", value / 100, - value % 100); - } - - /* The OPT will turn itself off, so we don't need to call its DEACTIVATE */ - ctimer_set(&opt_timer, next, init_light_reading, NULL); -} -/*---------------------------------------------------------------------------*/ -static void -get_mpu_reading() -{ - clock_time_t next = SENSOR_READING_PERIOD + - (random_rand() % SENSOR_READING_RANDOM); - int raw; - - if(mpu_gyro_x_reading.publish) { - raw = mpu_9250_sensor.value(MPU_9250_SENSOR_TYPE_GYRO_X); - if(raw != MPU_9250_READING_ERROR) { - mpu_gyro_x_reading.raw = raw; - } - } - - if(mpu_gyro_y_reading.publish) { - raw = mpu_9250_sensor.value(MPU_9250_SENSOR_TYPE_GYRO_Y); - if(raw != MPU_9250_READING_ERROR) { - mpu_gyro_y_reading.raw = raw; - } - } - - if(mpu_gyro_z_reading.publish) { - raw = mpu_9250_sensor.value(MPU_9250_SENSOR_TYPE_GYRO_Z); - if(raw != MPU_9250_READING_ERROR) { - mpu_gyro_z_reading.raw = raw; - } - } - - if(mpu_acc_x_reading.publish) { - raw = mpu_9250_sensor.value(MPU_9250_SENSOR_TYPE_ACC_X); - if(raw != MPU_9250_READING_ERROR) { - mpu_acc_x_reading.raw = raw; - } - } - - if(mpu_acc_y_reading.publish) { - raw = mpu_9250_sensor.value(MPU_9250_SENSOR_TYPE_ACC_Y); - if(raw != MPU_9250_READING_ERROR) { - mpu_acc_y_reading.raw = raw; - } - } - - if(mpu_acc_z_reading.publish) { - raw = mpu_9250_sensor.value(MPU_9250_SENSOR_TYPE_ACC_Z); - if(raw != MPU_9250_READING_ERROR) { - mpu_acc_z_reading.raw = raw; - } - } - - SENSORS_DEACTIVATE(mpu_9250_sensor); - - if(mpu_gyro_x_reading.publish) { - compare_and_update(&mpu_gyro_x_reading); - memset(mpu_gyro_x_reading.converted, 0, WEB_DEMO_CONVERTED_LEN); - print_mpu_reading(mpu_gyro_x_reading.raw, mpu_gyro_x_reading.converted); - } - - if(mpu_gyro_y_reading.publish) { - compare_and_update(&mpu_gyro_y_reading); - memset(mpu_gyro_y_reading.converted, 0, WEB_DEMO_CONVERTED_LEN); - print_mpu_reading(mpu_gyro_y_reading.raw, mpu_gyro_y_reading.converted); - } - - if(mpu_gyro_z_reading.publish) { - compare_and_update(&mpu_gyro_z_reading); - memset(mpu_gyro_z_reading.converted, 0, WEB_DEMO_CONVERTED_LEN); - print_mpu_reading(mpu_gyro_z_reading.raw, mpu_gyro_z_reading.converted); - } - - if(mpu_acc_x_reading.publish) { - compare_and_update(&mpu_acc_x_reading); - memset(mpu_acc_x_reading.converted, 0, WEB_DEMO_CONVERTED_LEN); - print_mpu_reading(mpu_acc_x_reading.raw, mpu_acc_x_reading.converted); - } - - if(mpu_acc_y_reading.publish) { - compare_and_update(&mpu_acc_y_reading); - memset(mpu_acc_y_reading.converted, 0, WEB_DEMO_CONVERTED_LEN); - print_mpu_reading(mpu_acc_y_reading.raw, mpu_acc_y_reading.converted); - } - - if(mpu_acc_z_reading.publish) { - compare_and_update(&mpu_acc_z_reading); - memset(mpu_acc_z_reading.converted, 0, WEB_DEMO_CONVERTED_LEN); - print_mpu_reading(mpu_acc_z_reading.raw, mpu_acc_z_reading.converted); - } - - /* We only use the single timer */ - ctimer_set(&mpu_timer, next, init_mpu_reading, NULL); -} -/*---------------------------------------------------------------------------*/ -static void -init_tmp_reading(void *data) -{ - if(tmp_amb_reading.publish || tmp_obj_reading.publish) { - SENSORS_ACTIVATE(tmp_007_sensor); - } else { - ctimer_set(&tmp_timer, CLOCK_SECOND, init_tmp_reading, NULL); - } -} -/*---------------------------------------------------------------------------*/ -static void -init_bmp_reading(void *data) -{ - if(bmp_pres_reading.publish || bmp_temp_reading.publish) { - SENSORS_ACTIVATE(bmp_280_sensor); - } else { - ctimer_set(&bmp_timer, CLOCK_SECOND, init_bmp_reading, NULL); - } -} -/*---------------------------------------------------------------------------*/ -static void -init_hdc_reading(void *data) -{ - if(hdc_hum_reading.publish || hdc_temp_reading.publish) { - SENSORS_ACTIVATE(hdc_1000_sensor); - } else { - ctimer_set(&hdc_timer, CLOCK_SECOND, init_hdc_reading, NULL); - } -} -/*---------------------------------------------------------------------------*/ -static void -init_light_reading(void *data) -{ - if(opt_reading.publish) { - SENSORS_ACTIVATE(opt_3001_sensor); - } else { - ctimer_set(&opt_timer, CLOCK_SECOND, init_light_reading, NULL); - } -} -/*---------------------------------------------------------------------------*/ -static void -init_mpu_reading(void *data) -{ - int readings_bitmap = 0; - - if(mpu_acc_x_reading.publish || mpu_acc_y_reading.publish || - mpu_acc_z_reading.publish) { - readings_bitmap |= MPU_9250_SENSOR_TYPE_ACC; - } - - if(mpu_gyro_x_reading.publish || mpu_gyro_y_reading.publish || - mpu_gyro_z_reading.publish) { - readings_bitmap |= MPU_9250_SENSOR_TYPE_GYRO; - } - - if(readings_bitmap) { - mpu_9250_sensor.configure(SENSORS_ACTIVE, readings_bitmap); - } else { - ctimer_set(&mpu_timer, CLOCK_SECOND, init_mpu_reading, NULL); - } -} -#endif -/*---------------------------------------------------------------------------*/ -static void -init_sensor_readings(void) -{ - /* - * Make a first pass and get all initial sensor readings. This will also - * trigger periodic value updates - */ - get_batmon_reading(NULL); - -#if BOARD_SENSORTAG - init_bmp_reading(NULL); - init_light_reading(NULL); - init_hdc_reading(NULL); - init_tmp_reading(NULL); - init_mpu_reading(NULL); -#endif /* BOARD_SENSORTAG */ - - return; -} -/*---------------------------------------------------------------------------*/ -static void -init_sensors(void) -{ - - list_add(sensor_list, &batmon_temp_reading); - list_add(sensor_list, &batmon_volt_reading); - -#if WEB_DEMO_ADC_DEMO - list_add(sensor_list, &adc_dio23_reading); -#endif - - SENSORS_ACTIVATE(batmon_sensor); - -#if BOARD_SENSORTAG - list_add(sensor_list, &bmp_pres_reading); - list_add(sensor_list, &bmp_temp_reading); - - list_add(sensor_list, &tmp_obj_reading); - list_add(sensor_list, &tmp_amb_reading); - - list_add(sensor_list, &opt_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); - list_add(sensor_list, &mpu_acc_z_reading); - list_add(sensor_list, &mpu_gyro_x_reading); - list_add(sensor_list, &mpu_gyro_y_reading); - list_add(sensor_list, &mpu_gyro_z_reading); -#endif -} -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(web_demo_process, ev, data) -{ - PROCESS_BEGIN(); - - printf("CC13xx/CC26xx Web Demo Process\n"); - - init_sensors(); - - web_demo_publish_event = process_alloc_event(); - web_demo_config_loaded_event = process_alloc_event(); - web_demo_load_config_defaults = process_alloc_event(); - - /* Start all other (enabled) processes first */ - process_start(&httpd_simple_process, NULL); - -#if WEB_DEMO_COAP_SERVER - process_start(&coap_server_process, NULL); -#endif - -#if WEB_DEMO_6LBR_CLIENT - process_start(&cetic_6lbr_client_process, NULL); -#endif - -#if WEB_DEMO_MQTT_CLIENT - process_start(&mqtt_client_process, NULL); -#endif - -#if WEB_DEMO_NET_UART - process_start(&net_uart_process, NULL); -#endif - -#if WEB_DEMO_ADC_DEMO - process_start(&adc_process, NULL); -#endif - - /* - * Now that processes have set their own config default values, set our - * own defaults and restore saved config from flash... - */ - web_demo_config.sensors_bitmap = 0xFFFFFFFF; /* all on by default */ - web_demo_config.def_rt_ping_interval = - WEB_DEMO_DEFAULT_RSSI_MEAS_INTERVAL; - load_config(); - - /* - * Notify all other processes (basically the ones in this demo) that the - * configuration has been loaded from flash, in case they care - */ - process_post(PROCESS_BROADCAST, web_demo_config_loaded_event, NULL); - - init_sensor_readings(); - - httpd_simple_register_post_handler(&sensor_handler); - httpd_simple_register_post_handler(&defaults_handler); - -#if 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, WEB_DEMO_NET_CONNECT_PERIODIC); -#endif - - etimer_set(&et, WEB_DEMO_NET_CONNECT_PERIODIC); - - /* - * Update all sensor readings on a configurable sensors_event - * (e.g a button press / or reed trigger) - */ - while(1) { - if(ev == PROCESS_EVENT_TIMER && etimer_expired(&et)) { - if(uip_ds6_get_global(ADDR_PREFERRED) == NULL) { - leds_on(WEB_DEMO_STATUS_LED); - ctimer_set(&ct, NO_NET_LED_DURATION, publish_led_off, NULL); - etimer_set(&et, WEB_DEMO_NET_CONNECT_PERIODIC); - } - } - -#if 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, WEB_DEMO_NET_CONNECT_PERIODIC); - } else { - ping_parent(); - etimer_set(&echo_request_timer, web_demo_config.def_rt_ping_interval); - } - } -#endif - - if(ev == button_hal_release_event && - ((button_hal_button_t *)data)->unique_id == - WEB_DEMO_SENSOR_READING_TRIGGER) { - init_sensor_readings(); - process_post(PROCESS_BROADCAST, web_demo_publish_event, NULL); - } else if(ev == button_hal_periodic_event && - ((button_hal_button_t *)data)->unique_id == - WEB_DEMO_SENSOR_READING_TRIGGER) { - printf("Restoring defaults!\n"); - web_demo_restore_defaults(); - } else if(ev == httpd_simple_event_new_config) { - save_config(); -#if BOARD_SENSORTAG - } else if(ev == sensors_event && data == &bmp_280_sensor) { - get_bmp_reading(); - } else if(ev == sensors_event && data == &opt_3001_sensor) { - get_light_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) { - get_mpu_reading(); -#endif - } - - PROCESS_YIELD(); - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ -#if WEB_DEMO_ADC_DEMO -PROCESS_THREAD(adc_process, ev, data) -{ - static ADC_Params adc_params; - ADC_Handle adc_handle; - int_fast16_t res; - uint_fast16_t adc_value; - - PROCESS_BEGIN(); - - ADC_init(); - ADC_Params_init(&adc_params); - - etimer_set(&et_adc, CLOCK_SECOND * 5); - - while(1) { - PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et_adc)); - - adc_handle = ADC_open(Board_ADC0, &adc_params); - - if(adc_handle != NULL) { - res = ADC_convert(adc_handle, &single_adc_sample); - - if(res == ADC_STATUS_SUCCESS) { - single_adc_sample = adc_value; - get_adc_reading(NULL); - } - - ADC_close(adc_handle); - } - - etimer_reset(&et_adc); - } - - PROCESS_END(); -} -#endif -/*---------------------------------------------------------------------------*/ -/** - * @} - */ diff --git a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/web-demo.h b/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/web-demo.h deleted file mode 100644 index ab2c88342..000000000 --- a/examples/platform-specific/simplelink/cc13xx-cc26xx/web-demo/web-demo.h +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Copyright (c) 2014, 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 cc13xx-cc26xx-examples - * @{ - * - * \defgroup cc13xx-cc26xx-web-demo CC13xx/CC26xx Web Demo - * @{ - * - * An example demonstrating: - * * how to use a CC13xx/CC26xx-powered node in a deployment driven by a 6LBR - * * how to expose on-device sensors as CoAP resources - * * how to build a small web page which reports networking and sensory data - * * how to configure functionality through the aforementioned web page using - * HTTP POST requests - * * a network-based UART - * - * \file - * Main header file for the CC13xx/CC26xx web demo. - */ -/*---------------------------------------------------------------------------*/ -#ifndef WEB_DEMO_H_ -#define WEB_DEMO_H_ -/*---------------------------------------------------------------------------*/ -#include "dev/leds.h" -#include "sys/process.h" -/*---------------------------------------------------------------------------*/ -#include "mqtt-client.h" -#include "net-uart.h" -/*---------------------------------------------------------------------------*/ -#include -/*---------------------------------------------------------------------------*/ -#ifdef WEB_DEMO_CONF_MQTT_CLIENT -#define WEB_DEMO_MQTT_CLIENT WEB_DEMO_CONF_MQTT_CLIENT -#else -#define WEB_DEMO_MQTT_CLIENT 1 -#endif - -#ifdef WEB_DEMO_CONF_6LBR_CLIENT -#define WEB_DEMO_6LBR_CLIENT WEB_DEMO_CONF_6LBR_CLIENT -#else -#define WEB_DEMO_6LBR_CLIENT 1 -#endif - -#ifdef WEB_DEMO_CONF_COAP_SERVER -#define WEB_DEMO_COAP_SERVER WEB_DEMO_CONF_COAP_SERVER -#else -#define WEB_DEMO_COAP_SERVER 1 -#endif - -#ifdef WEB_DEMO_CONF_NET_UART -#define WEB_DEMO_NET_UART WEB_DEMO_CONF_NET_UART -#else -#define WEB_DEMO_NET_UART 1 -#endif - -#ifdef WEB_DEMO_CONF_ADC_DEMO -#define WEB_DEMO_ADC_DEMO WEB_DEMO_CONF_ADC_DEMO -#else -#define WEB_DEMO_ADC_DEMO 0 -#endif -/*---------------------------------------------------------------------------*/ -/* Active probing of RSSI from our preferred parent */ -#if (WEB_DEMO_COAP_SERVER || WEB_DEMO_MQTT_CLIENT) -#define WEB_DEMO_READ_PARENT_RSSI 1 -#else -#define WEB_DEMO_READ_PARENT_RSSI 0 -#endif - -#define WEB_DEMO_RSSI_MEASURE_INTERVAL_MAX 86400 /* secs: 1 day */ -#define WEB_DEMO_RSSI_MEASURE_INTERVAL_MIN 5 /* secs */ -/*---------------------------------------------------------------------------*/ -/* User configuration */ -/* Take a sensor reading on button press */ -#define WEB_DEMO_SENSOR_READING_TRIGGER BUTTON_HAL_ID_KEY_LEFT - -/* Payload length of ICMPv6 echo requests used to measure RSSI with def rt */ -#define WEB_DEMO_ECHO_REQ_PAYLOAD_LEN 20 - -#if BOARD_SENSORTAG -/* Force an MQTT publish on sensor event */ -#define WEB_DEMO_MQTT_PUBLISH_TRIGGER BUTTON_HAL_ID_REED_RELAY -#elif BOARD_LAUNCHPAD -#define WEB_DEMO_MQTT_PUBLISH_TRIGGER BUTTON_HAL_ID_KEY_LEFT -#else -#define WEB_DEMO_MQTT_PUBLISH_TRIGGER BUTTON_HAL_ID_KEY_DOWN -#endif - -#define WEB_DEMO_STATUS_LED LEDS_GREEN -/*---------------------------------------------------------------------------*/ -/* A timeout used when waiting to connect to a network */ -#define WEB_DEMO_NET_CONNECT_PERIODIC (CLOCK_SECOND >> 3) -/*---------------------------------------------------------------------------*/ -/* Default configuration values */ -#define WEB_DEMO_DEFAULT_ORG_ID "quickstart" -#if defined(DEVICE_LINE_CC13XX) -#define WEB_DEMO_DEFAULT_TYPE_ID "cc13xx" -#elif defined(DEVICE_LINE_CC26XX) -#define WEB_DEMO_DEFAULT_TYPE_ID "cc26xx" -#endif -#define WEB_DEMO_DEFAULT_EVENT_TYPE_ID "status" -#define WEB_DEMO_DEFAULT_SUBSCRIBE_CMD_TYPE "+" -#define WEB_DEMO_DEFAULT_BROKER_PORT 1883 -#define WEB_DEMO_DEFAULT_PUBLISH_INTERVAL (30 * CLOCK_SECOND) -#define WEB_DEMO_DEFAULT_KEEP_ALIVE_TIMER 60 -#define WEB_DEMO_DEFAULT_RSSI_MEAS_INTERVAL (CLOCK_SECOND * 30) -/*---------------------------------------------------------------------------*/ -/* - * You normally won't have to change anything from here onwards unless you are - * extending the example - */ -/*---------------------------------------------------------------------------*/ -/* Sensor types */ -#define WEB_DEMO_SENSOR_BATMON_TEMP 0 -#define WEB_DEMO_SENSOR_BATMON_VOLT 1 -#define WEB_DEMO_SENSOR_BMP_PRES 2 -#define WEB_DEMO_SENSOR_BMP_TEMP 3 -#define WEB_DEMO_SENSOR_TMP_AMBIENT 4 -#define WEB_DEMO_SENSOR_TMP_OBJECT 5 -#define WEB_DEMO_SENSOR_HDC_TEMP 6 -#define WEB_DEMO_SENSOR_HDC_HUMIDITY 7 -#define WEB_DEMO_SENSOR_OPT_LIGHT 8 -#define WEB_DEMO_SENSOR_MPU_ACC_X 9 -#define WEB_DEMO_SENSOR_MPU_ACC_Y 10 -#define WEB_DEMO_SENSOR_MPU_ACC_Z 11 -#define WEB_DEMO_SENSOR_MPU_GYRO_X 12 -#define WEB_DEMO_SENSOR_MPU_GYRO_Y 13 -#define WEB_DEMO_SENSOR_MPU_GYRO_Z 14 -#define WEB_DEMO_SENSOR_ADC_DIO23 15 -/*---------------------------------------------------------------------------*/ -extern process_event_t web_demo_publish_event; -extern process_event_t web_demo_config_loaded_event; -extern process_event_t web_demo_load_config_defaults; -/*---------------------------------------------------------------------------*/ -#define WEB_DEMO_UNIT_TEMP "C" -#define WEB_DEMO_UNIT_VOLT "mV" -#define WEB_DEMO_UNIT_PRES "hPa" -#define WEB_DEMO_UNIT_HUMIDITY "%RH" -#define WEB_DEMO_UNIT_LIGHT "lux" -#define WEB_DEMO_UNIT_ACC "G" -#define WEB_DEMO_UNIT_GYRO "deg per sec" -/*---------------------------------------------------------------------------*/ -/* A data type for sensor readings, internally stored in a linked list */ -#define WEB_DEMO_CONVERTED_LEN 12 - -typedef struct web_demo_sensor_reading { - struct web_demo_sensor_reading *next; - int raw; - int last; - const char *descr; - const char *xml_element; - const char *form_field; - char *units; - uint8_t type; - uint8_t publish; - uint8_t changed; - char converted[WEB_DEMO_CONVERTED_LEN]; -} web_demo_sensor_reading_t; -/*---------------------------------------------------------------------------*/ -/* Global configuration */ -typedef struct web_demo_config_s { - uint32_t magic; - int len; - uint32_t sensors_bitmap; - int def_rt_ping_interval; - mqtt_client_config_t mqtt_config; - net_uart_config_t net_uart; -} web_demo_config_t; - -extern web_demo_config_t web_demo_config; -/*---------------------------------------------------------------------------*/ -/** - * \brief Performs a lookup for a reading of a specific type of sensor - * \param sens_type WEB_DEMO_SENSOR_BATMON_TEMP... - * \return A pointer to the reading data structure or NULL - */ -const web_demo_sensor_reading_t *web_demo_sensor_lookup(int sens_type); - -/** - * \brief Returns the first available sensor reading - * \return A pointer to the reading data structure or NULL - */ -const web_demo_sensor_reading_t *web_demo_sensor_first(void); - -/** - * \brief Print an IPv6 address into a buffer - * \param buf A pointer to the buffer where this function will print the IPv6 - * address - * \param buf_len the length of the buffer - * \param addr A pointer to the IPv6 address - * \return The number of bytes written to the buffer - * - * It is the caller's responsibility to allocate enough space for buf - */ -int web_demo_ipaddr_sprintf(char *buf, uint8_t buf_len, - const uip_ipaddr_t *addr); - -/** - * \brief Resets the example to a default configuration - */ -void web_demo_restore_defaults(void); -/*---------------------------------------------------------------------------*/ -#endif /* WEB_DEMO_H_ */ -/*---------------------------------------------------------------------------*/ -/** - * @} - * @} - */