Wednesday, March 29, 2017

Build TI Z-Stack Linux Home Gateway reference design for x86 Linux

The following steps show you hot to build TI Z-Stack Linux Home Gateway reference design for x86 Linux.

1. Download Z-Stack_Linux_Gateway-1.0.1-src-linux-installer.run from http://www.ti.com/tool/z-stack-archive.

2. Setup a 32 bit Ubuntu and run Z-Stack_Linux_Gateway-1.0.1-src-linux-installer.run to extract Z-Stack Linux Gateway source code to your Linux Home folder\Z-Stack_Linux_Gateway-1.0.1-src

3. Revise the build script package_builder_bbb (in red) under “your Linux Home folder\Z-Stack_Linux_Gateway-1.0.1-src\Source\scripts\”

...
#Target platform:
    #export TARGET_PLATFORM="BEAGLEBONE_BLACK"
    export TARGET_PLATFORM="x86"

...
    cd $NPI_SOURCE/Projects/tools/LinuxHost
    make clean
    make create_output
    #make arch-all-armBeagleBone CC_armBeagleBone=$COMPILER |& tee -a $MAKE_LOG_FILE
    make $BUILD_TYPE |& tee -a $MAKE_LOG_FILE

...
# *** Copy resources ***********************************************************************************

#cp $NPI_SOURCE/Projects/tools/LinuxHost/out/NPI_lnx_armBeagleBone_server $BINARIES_SERVERS_DIR/NPI_lnx_${PLATFORM_SUBSTRING}_server
cp $NPI_SOURCE/Projects/tools/LinuxHost/out/NPI_lnx_${PLATFORM_SUBSTRING}_server $BINARIES_SERVERS_DIR/NPI_lnx_${PLATFORM_SUBSTRING}_server

4. Install protobuf by doing the following two apt-get install

       sudo apt-get install protobuf-c-compiler
       sudo apt-get install protobuf-compiler

5. Switch to your Linux Home folder\Z-Stack_Linux_Gateway-1.0.1-src\Source\ and run ./build_all

6. The output will be at "your Linux Home folder\Z-Stack_Linux_Gateway-1.0.1-src\Source\ERROR_out\z-stack_linux_gateway_x86_binaries.tar". The build error is due to the lack of comparison file but the output binaries still work on x86 environment.

7. Copy and untar “z-stack_linux_gateway_x86_binaries.tar” to your working directory on x86 (called ). Please follow the (Z-Stack Linux Gateway User Guide.pdf, Chap 6.3) to start the application. Please note you have to specify x86 when you run zigbeeHAgw like "./zigbeeHAgw x86"

8. If you run it successfully, you will see the results like the following screen shot.


Thursday, March 9, 2017

SPI connection between LAUNCHXL-CC1310/LAUNCHXL-CC2650 and ENC28J60 to run 6lbr

You can do the following SPI connection between ENC28J60 and LAUNCHXL-CC1310/LAUNCHXL-CC2650 to run 6lbr
  • SCLK : LaunchPad DIO10
  • MOSI : LaunchPad DIO9
  • MISO : LaunchPad DIO8
  • CS : LaunchPad DIO14
  • GND :  LaunchPad GND
  • VCC : LaunchPad 3V3

6lbr SW can be built by following steps in http://sunmaysky.blogspot.tw/2017/01/build-6lbr-for-cc2650dk-or-cc1310dk.html . After run 6lbr on LAUNCHXL-CC1310/LAUNCHXL-CC2650, you can see the following UART output.



Friday, March 3, 2017

How to run Contiki udp-server/udp-client on LAUNCHXL-CC2650.

The following steps show you how to run Contiki udp-server/udp-client on LAUNCHXL-CC2650.

1. Do "make TARGET=srf06-cc26xx BOARD=launchpad/cc2650 udp-server.bin" under /contiki/examples/ipv6/rpl-udp to build udp-server.bin and download it to one of LAUNCHXL-CC2650 using Flash Programmer 2.


2. Do "make TARGET=srf06-cc26xx BOARD=launchpad/cc2650 udp-client.bin" under /contiki/examples/ipv6/rpl-udp to build udp-client.bin and download it to another LAUNCHXL-CC2650 using Flash Programmer 2.

3. Start 6lbr on Raspberry Pi or BeagleBone and power on udp-server and udp-client on two different LAUNCHXL-CC2650. You will see two LAUNCHXL-CC2650 show on sensor list of 6lbr web page.


4. On UART output of two LAUNCHXL-CC2650, you can see udp-client sends Hello messages to udp-server.

Wednesday, February 15, 2017

How to do settings to allow access 6lbr from Internet

The following steps show you how to do settings to allow access 6lbr from Internet. Let's say we have a Internet router (mine is Asus RT-N12HP_B1) and the LAN address is 192.168.1.xxx.

1. Access to 6lbr web page (http://[bbbb::100]) inside LAN and go to configuration page of 6lbr. Select IP64: on, DHCP: off, input a IPv4 address 192.168.1.2 (this might be different if you don't use 192.168.1.xxx as LAN address on your Internet router and you can use other IP such as 192.168.1.123 if you like it more.), and set Gateway as 192.168.1.1 (this might be also different if you don't use 192.168.1.xxx as LAN address on your Internet router). Then, press "Submit" to restart 6lbr.



2.  After restarting, you can check IP64 Address is 192.168.1.2 now on 6lbr Info page.


3. Next, let's check settings on Internet router (mine is Asus RT-N12HP_B1). We can see the external IP of this router is 220.136.172.175.



4.I add a port forwarding rule (assign http service port to 6lbr IPv4 address 192.168.1.2) to this Internet router and restart it.



5. Now, I can access 6lbr from another desktop from elsewhere on Internet by http://220.136.172.175



Conversion between RSSI and LQI in Z-Stack

Z-Stack uses the following formula to convert RSSI and LQI.

LinkQuality = [255* (RSSI-MIN_ED)]/[MAX_ED-MIN_ED]

Therefore with simple algebra

RSSI = MIN_ED+LinkQuality*( MAX_ED-MIN_ED)/255

Default values for MIN_ED and MAX_ED are -87 and 10 respectively.

Then, maybe you can convert RSSI to distance...

Friday, February 10, 2017

Use ZTool + Z-Stack 3.0 ZNP to set up a basic Zigbee 3.0 network

The following steps show you how to use ZTool + Z-Stack 3.0 ZNP to set up Zigbee 3.0 network:

1. You have to prepare two CC253x EVBs (CC2530DK, CC2531EMK, or CC2538EM) and run Z-Stack ZNP 3.0 FW on it.

2. You can run the following MT commands (TX in red) to setup Zigbee 3.0 coordinator.

10:36:58.53 COM1 SYS_OSAL_NV_WRITE (0x2109) --> Write startup option to clear NV when reset
    Id: 0x0003
    Offset: 0x00
    Len: 0x01
    Value: . (0x03)

10:36:58.55 COM1 SYS_OSAL_NV_WRITE_SRSP (0x6109)
    Status: SUCCESS (0x0)

10:37:06.11 COM1 SYS_RESET (0x4100) --> Do reset to clear NV
    Type: 0x00 (HARD RESET) (0x0)

10:37:08.18 COM1 SYS_RESET_RESPONSE (0x4180)
    Reason: 0x02
    TransportRev: 0x02
    Product: 0x00
    MajorRel: 0x02
    MinorRel: 0x07
    HwRev: 0x00

10:37:42.94 COM1 SYS_OSAL_NV_WRITE (0x2109) --> Write ZCD_NV_LOGICAL_TYPE to 0 which means coordinator
    Id: 0x0087
    Offset: 0x00
    Len: 0x01
    Value: . (0x00)

10:37:42.97 COM1 SYS_OSAL_NV_WRITE_SRSP (0x6109)
    Status: SUCCESS (0x0)



10:38:32.55 COM1 APP_CNF_BDB_SET_CHANNEL (0x2F08) --> Set Primary channel mask to channel 13 only
    isPrimary: TRUE (0x1)
    Channel: CHNL_0x00002000 (0x2000)

1
0:38:32.55 COM1 APP_CNF_BDB_SET_CHANNEL_SRSP (0x6F08)
    Status: SUCCESS (0x0)

10:38:34.43 COM1 APP_CNF_BDB_SET_CHANNEL (0x2F08) --> Set Secondary channel to 0x0 to disable secondary channel mask
    isPrimary: FALSE (0x0)
    Channel: NONE (0x0)

10:49:01.44 COM1 APP_CNF_BDB_SET_CHANNEL_SRSP (0x6F08)
    Status: SUCCESS (0x0)

10:38:45.58 COM1 APP_CNF_BDB_START_COMMISSIONING (0x2F05)
--> Start commissioning using network formation as parameter to start coordinator
    CommissioningMode: (0x04) Network Formation (0x4)

10:38:47.35 COM1 APP_CNF_BDB_START_COMMISSIONING_SRSP (0x6F05)
    Status: SUCCESS (0x0)

10:38:47.35 COM1 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 8 (0x8)

10:38:47.36 COM1 APP_CNF_BDB_COMMISSIONING_NOTIFICATION (0x4F80)
    Status: 1 (0x1)
    Commissioning Mode: 0x02 (Formation) (0x2)
    Commissioning Mode: 254 (0xFE)

10:38:47.62 COM1 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 8 (0x8)

10:38:47.88 COM1 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 8 (0x8)

10:38:48.15 COM1 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 8 (0x8)

10:38:48.41 COM1 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 8 (0x8)

10:38:48.68 COM1 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 8 (0x8)

10:38:48.94 COM1 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 8 (0x8)

10:38:49.49 COM1 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 9 (0x9)

10:38:49.49 COM1 APP_CNF_BDB_COMMISSIONING_NOTIFICATION (0x4F80)
    Status: 0x00 (Success) (0x0)
    Commissioning Mode: 0x02 (Formation) (0x2)
    Commissioning Mode: 69 (0x45)

10:39:11.49 COM1 UTIL_GET_DEVICE_INFO (0x2700) --> Get device info to confirm coordinator is setup correctly

10:39:11.5 COM1 UTIL_GET_DEVICE_INFO_RESPONSE (0x6700)
    Status: SUCCESS (0x0)
    IEEEAddr: 0x00124B0001025822
    ShortAddress: 0x0000
    DeviceType: COORDINATOR, ROUTER, END_DEVICE (0x7)
    DeviceState: DEV_ZB_COORD (0x9)
    NumAssocDevices: 0x00
    AssocDevicesList

10:39:26.7 COM1 SYS_OSAL_NV_WRITE (0x2109) --> Write ZCD_NV_ZDO_DIRECT_CB to 1 to receive ZDO related messages
    Id: 0x008F
    Offset: 0x00
    Len: 0x01
    Value: . (0x01)

10:39:26.71 COM1 SYS_OSAL_NV_WRITE_SRSP (0x6109)
    Status: SUCCESS (0x0) 


10:44:16.54 COM1 APP_CNF_BDB_START_COMMISSIONING (0x2F05) --> Start commissioning using network steering as parameter to be ready for device to join
    CommissioningMode: (0x02) Network Steering (0x2)

10:44:16.55 COM1 APP_CNF_BDB_START_COMMISSIONING_SRSP (0x6F05)
    Status: SUCCESS (0x0)

10:44:16.56 COM1 ZDO_MGMT_PERMIT_JOIN_RSP (0x45B6)
    SrcAddr: 0x0000
    Status: ZDP_SUCCESS (0x0)

10:44:16.57 COM1 APP_CNF_BDB_COMMISSIONING_NOTIFICATION (0x4F80)
    Status: 0x00 (Success) (0x0)
    Commissioning Mode: 0x01 (Network Steering) (0x1)
    Commissioning Mode: 67 (0x43)


3. You can run the following MT commands to setup Zigbee 3.0 router.

10:43:43.75 COM99 SYS_OSAL_NV_WRITE (0x2109) --> Write ZCD_NV_LOGICAL_TYPE to 1 which means router
    Id: 0x0087
    Offset: 0x00
    Len: 0x01
    Value: . (0x01)

10:43:59.35 COM1 APP_CNF_BDB_SET_CHANNEL (0x2F08) --> Set Primary channel mask to channel 13 only
    isPrimary: TRUE (0x1)
    Channel: CHNL_0x00002000 (0x2000)
10:43:59.35 COM1 APP_CNF_BDB_SET_CHANNEL_SRSP (0x6F08)
    Status: SUCCESS (0x0)

10:44:11.43 COM1 APP_CNF_BDB_SET_CHANNEL (0x2F08) --> Set Secondary channel to 0x0 to disable secondary channel mask
    isPrimary: FALSE (0x0)
    Channel: NONE (0x0)
10:44:11.45 COM1 APP_CNF_BDB_SET_CHANNEL_SRSP (0x6F08)
    Status: SUCCESS (0x0)

10:44:26.46 COM99 APP_CNF_BDB_START_COMMISSIONING (0x2F05) --> Start commissioning using network steering as parameter to make device to start scan Zigbee network to join
    CommissioningMode: (0x02) Network Steering (0x2)

10:44:26.46 COM99 APP_CNF_BDB_START_COMMISSIONING_SRSP (0x6F05)
    Status: SUCCESS (0x0)

10:44:26.56 COM99 APP_CNF_BDB_COMMISSIONING_NOTIFICATION (0x4F80)
    Status: 1 (0x1)
    Commissioning Mode: 0x01 (Network Steering) (0x1)
    Commissioning Mode: 0 (0x0)

10:44:26.8 COM99 ZDO_STATE_CHANGE_IND (0x45C0)
    State: INVALID_PARAMETER (0x2)

10:44:27.11 COM99 ZDO_STATE_CHANGE_IND (0x45C0)
    State: INVALID_PARAMETER (0x2)

10:44:27.37 COM99 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 3 (0x3)

10:44:27.88 COM99 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 5 (0x5)

10:44:28.24 COM99 ZDO_STATE_CHANGE_IND (0x45C0)
    State: 7 (0x7)

10:44:28.9 COM99 APP_CNF_BDB_COMMISSIONING_NOTIFICATION (0x4F80)
    Status: 0x00 (Success) (0x0)
--> Router joins coordinator successfully
    Commissioning Mode: 0x01 (Network Steering) (0x1)
    Commissioning Mode: 0 (0x0)

11:03:22.81 COM99 UTIL_GET_DEVICE_INFO (0x2700)--> Get device info to confirm router is setup correctly

11:03:22.81 COM99 UTIL_GET_DEVICE_INFO_RESPONSE (0x6700)
    Status: SUCCESS (0x0)
    IEEEAddr: 0x00124B0000E50127
    ShortAddress: 0x4EE6
    DeviceType: COORDINATOR, ROUTER, END_DEVICE (0x7)
    DeviceState: DEV_ROUTER (0x7)
    NumAssocDevices: 0x00
    AssocDevicesList
 

4. On Ztool of coordinator, you should see ZDO_END_DEVICE_ANNCE_IND pops when router joins coordinator.

10:44:28.84 COM1 ZDO_END_DEVICE_ANNCE_IND (0x45C1)
    SrcAddr: 0x4EE6
    NwkAddr: 0x4EE6
    IEEEAddr: 0x00124B0000E50127
    Capabilities: 0x8E

Thursday, February 9, 2017

How to add a COAP resource to read ADC input from DIO23 in Contiki cc26xx-web-demo on CC2650 LaunchPad.

To add a COAP resource to read ADC input from DIO23 in Contiki cc26xx-web-demo on CC2650 LaunchPad, you have to add the following code with "+" into your cc26xx-web-demo.c, cc26xx-web-demo.h, coap-server.c, and res-sensors.c.

1. /examples/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c
@@ -55,9 +55,15 @@
 #include
 #include
 #include
+
+#include "ti-lib.h"
+#include "driverlib/aux_adc.h"
+#include "driverlib/aux_wuc.h"
+

 /*---------------------------------------------------------------------------*/
 PROCESS_NAME(cetic_6lbr_client_process);
 PROCESS(cc26xx_web_demo_process, "CC26XX Web Demo");
+PROCESS(adc_process, "ADC process");
 /*---------------------------------------------------------------------------*/
 /*
  * Update sensor readings in a staggered fashion every SENSOR_READING_PERIOD
@@ -84,6 +90,9 @@ static struct uip_icmp6_echo_reply_notification echo_reply_notification;
 static struct etimer echo_request_timer;
 int def_rt_rssi = 0;
 #endif
+
+uint16_t singleSample;
+

 /*---------------------------------------------------------------------------*/
 process_event_t cc26xx_web_demo_publish_event;
 process_event_t cc26xx_web_demo_config_loaded_event;
@@ -110,6 +119,9 @@ DEMO_SENSOR(batmon_temp, CC26XX_WEB_DEMO_SENSOR_BATMON_TEMP,
 DEMO_SENSOR(batmon_volt, CC26XX_WEB_DEMO_SENSOR_BATMON_VOLT,
             "Battery Volt", "battery-volt", "batmon_volt",
             CC26XX_WEB_DEMO_UNIT_VOLT);
+DEMO_SENSOR(adc_dio23, CC26XX_WEB_DEMO_SENSOR_ADC_DIO23,
+            "ADC DIO23", "adc-dio23", "adc_dio23",
+            CC26XX_WEB_DEMO_UNIT_VOLT);

 /* Sensortag sensors */
 #if BOARD_SENSORTAG
@@ -464,6 +476,14 @@ get_batmon_reading(void *data)
     }
   }

+  if(adc_dio23_reading.publish) {
+    if(1) {
+      buf = adc_dio23_reading.converted;
+      memset(buf, 0, CC26XX_WEB_DEMO_CONVERTED_LEN);
+      snprintf(buf, CC26XX_WEB_DEMO_CONVERTED_LEN, "%d", singleSample);
+    }
+  }
+

   ctimer_set(&batmon_timer, next, get_batmon_reading, NULL);
 }
 /*---------------------------------------------------------------------------*/
@@ -825,6 +845,7 @@ init_sensors(void)

   list_add(sensor_list, &batmon_temp_reading);
   list_add(sensor_list, &batmon_volt_reading);
+  list_add(sensor_list, &adc_dio23_reading);
   SENSORS_ACTIVATE(batmon_sensor);

 #if BOARD_SENSORTAG
@@ -864,6 +885,7 @@ PROCESS_THREAD(cc26xx_web_demo_process, ev, data)

   /* Start all other (enabled) processes first */
   process_start(&httpd_simple_process, NULL);
+  process_start(&adc_process, NULL);
 #if CC26XX_WEB_DEMO_COAP_SERVER
   process_start(&coap_server_process, NULL);
 #endif
@@ -966,6 +988,56 @@ PROCESS_THREAD(cc26xx_web_demo_process, ev, data)

   PROCESS_END();
 }
+
+PROCESS_THREAD(adc_process, ev, data)
+{
+  PROCESS_BEGIN();
+  static struct etimer et_adc;
+  while(1)
+  {
+         etimer_set(&et_adc, CLOCK_SECOND*5);
+         PROCESS_WAIT_EVENT();
+         if(etimer_expired(&et_adc)) {
+               //intialisation of ADC
+               ti_lib_aon_wuc_aux_wakeup_event(AONWUC_AUX_WAKEUP);
+               while(!(ti_lib_aon_wuc_power_status_get() & AONWUC_AUX_POWER_ON))
+               { }
+
+               // Enable clock for ADC digital and analog interface (not currently enabled in driver)
+               // Enable clocks
+               ti_lib_aux_wuc_clock_enable(AUX_WUC_ADI_CLOCK | AUX_WUC_ANAIF_CLOCK | AUX_WUC_SMPH_CLOCK);
+               while(ti_lib_aux_wuc_clock_status(AUX_WUC_ADI_CLOCK | AUX_WUC_ANAIF_CLOCK | AUX_WUC_SMPH_CLOCK) != AUX_WUC_CLOCK_READY)
+               { }
+               //printf("clock selected\r\n");
+
+               // Connect AUX IO7 (DIO23, but also DP2 on XDS110) as analog input.
+               AUXADCSelectInput(ADC_COMPB_IN_AUXIO7);
+               //printf("input selected\r\n");
+
+               // Set up ADC range
+               // AUXADC_REF_FIXED = nominally 4.3 V
+               AUXADCEnableSync(AUXADC_REF_FIXED,  AUXADC_SAMPLE_TIME_2P7_US, AUXADC_TRIGGER_MANUAL);
+               //printf("init adc --- OK\r\n");
+
+               //Trigger ADC converting
+               AUXADCGenManualTrigger();
+               //printf("trigger --- OK\r\n");
+
+               //reading adc value
+               singleSample = AUXADCReadFifo();
+
+               printf("%d mv on ADC\r\n",singleSample);
+
+               //shut the adc down
+               AUXADCDisable();
+               //printf("disable --- OK\r\n");
+               get_batmon_reading(NULL);
+
+               etimer_reset(&et_adc);
+               }
+  }
+  PROCESS_END();
+}

 

2./examples/cc26xx/cc26xx-web-demo/cc26xx-web-demo.h
@@ -146,6 +146,7 @@
 #define CC26XX_WEB_DEMO_SENSOR_MPU_GYRO_X    12
 #define CC26XX_WEB_DEMO_SENSOR_MPU_GYRO_Y    13
 #define CC26XX_WEB_DEMO_SENSOR_MPU_GYRO_Z    14
+#define CC26XX_WEB_DEMO_SENSOR_ADC_DIO23     15
 /*---------------------------------------------------------------------------*/
 extern process_event_t cc26xx_web_demo_publish_event;
 extern process_event_t cc26xx_web_demo_config_loaded_event;

3. /examples/cc26xx/cc26xx-web-demo/coap-server.c
@@ -50,6 +50,7 @@ extern resource_t res_leds;

 extern resource_t res_batmon_temp;
 extern resource_t res_batmon_volt;
+extern resource_t res_adc_dio23;

 extern resource_t res_device_sw;
 extern resource_t res_device_hw;
@@ -133,6 +134,7 @@ PROCESS_THREAD(coap_server_process, ev, data)

   rest_activate_resource(&res_batmon_temp, "sen/batmon/temp");
   rest_activate_resource(&res_batmon_volt, "sen/batmon/voltage");
+  rest_activate_resource(&res_adc_dio23, "adc/dio23");

   rest_activate_resource(&res_device_hw, "dev/mdl/hw");
   rest_activate_resource(&res_device_sw, "dev/mdl/sw");

4. examples/cc26xx/cc26xx-web-demo/resources/res-sensors.c
@@ -111,12 +111,24 @@ res_get_handler_batmon_volt(void *request, void *response, uint8_t *buffer,
                       buffer, preferred_size, offset);
 }
 /*---------------------------------------------------------------------------*/
+static void
+res_get_handler_adc_dio23(void *request, void *response, uint8_t *buffer,
+                            uint16_t preferred_size, int32_t *offset)
+{
+  res_get_handler_all(CC26XX_WEB_DEMO_SENSOR_ADC_DIO23, 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);
 /*---------------------------------------------------------------------------*/
+/*---------------------------------------------------------------------------*/
+RESOURCE(res_adc_dio23, "title=\"ADC DIO23\";rt=\"mV\"",
+         res_get_handler_adc_dio23, NULL, NULL, NULL);
+/*---------------------------------------------------------------------------*/

 #if BOARD_SENSORTAG
 /*---------------------------------------------------------------------------*/
 /* MPU resources and handler: Accelerometer and Gyro */

Build cc26xx-web-demo for CC2650 LaunchPad by "make TARGET=srf06-cc26xx BOARD=launchpad/cc2650 cc26xx-web-demo.bin" and download cc26xx-web-demo.bin to your CC2650 LaunchPad. Let it join 6lbr and you should see resource adc/dio23 on COAP interface. You can press Get button to get the ADC reading from DIO23. Try to connect different voltage (0-3.6V) to test.