注册 登录
电子工程世界-论坛 返回首页 EEWORLD首页 频道 EE大学堂 下载中心 Datasheet 专题
dan158185的个人空间 https://home.eeworld.com.cn/space-uid-349284.html [收藏] [复制] [分享] [RSS]
日志

CC2538之TinyOS例程实验:10-CoAPServer zigbee灯光无线控制实验

已有 1260 次阅读2016-1-5 16:11 |个人分类:CC2538之TinyOS例程| 无线

本例程的实验需要9-Ppprouter实验节点;通过边界路由来实现CoAPServer 的节点LED控制;

先烧写一个Ppprouter节点,连接PC,pppd拨号连接后;进行下面的操作;不清楚的朋友大家可以去看看视频部分;


例程目录:

tinyos-main-release_tinyos_2_1_2\apps\cc2538_Test\CoapBlip

Makefile文件;任性的忽略

CoapBlipC.nc文件:

  1. #ifdef COAP_RESOURCE_KEY  
  2. #include "StorageVolumes.h"  
  3. #endif  
  4.   
  5. #include <iprouting.h>  
  6.   
  7. #include "tinyos_coap_resources.h"  
  8.   
  9. configuration CoapBlipC {  
  10.   
  11. } implementation {  
  12.   components MainC;  
  13.   components LedsC;  
  14.   components CoapBlipP;  
  15.   components LibCoapAdapterC;  
  16.   components IPStackC;  
  17.   
  18.   CoapBlipP.Boot -> MainC;  
  19.   CoapBlipP.Leds -> LedsC;  
  20.   CoapBlipP.RadioControl ->  IPStackC;  
  21.   
  22. #ifdef IN6_PREFIX  
  23.  components StaticIPAddressTosIdC;  
  24. #endif  
  25.   
  26. #ifdef RPL_ROUTING  
  27.   components RPLRoutingC;  
  28. #endif  
  29.   
  30. #ifdef COAP_SERVER_ENABLED  
  31.   components CoapUdpServerC;  
  32.   components new UdpSocketC() as UdpServerSocket;  
  33.   CoapBlipP.CoAPServer -> CoapUdpServerC;  
  34.   CoapUdpServerC.LibCoapServer -> LibCoapAdapterC.LibCoapServer;  
  35.   LibCoapAdapterC.UDPServer -> UdpServerSocket;  
  36.   
  37. #if defined (COAP_CONTENT_TYPE_JSON) || defined (COAP_CONTENT_TYPE_XML)  
  38.   components LocalIeeeEui64C;  
  39. #endif  
  40.   
  41. #ifdef COAP_RESOURCE_DEFAULT  
  42.   components new CoapDefaultResourceC(INDEX_DEFAULT);  
  43.   CoapUdpServerC.CoapResource[INDEX_DEFAULT] -> CoapDefaultResourceC.CoapResource;  
  44.   CoapDefaultResourceC.Leds -> LedsC;  
  45.   CoapDefaultResourceC.CoAPServer ->  CoapUdpServerC;//for POST/DELETE  
  46. #endif  
  47.   
  48. #if defined (COAP_RESOURCE_TEMP)  || defined (COAP_RESOURCE_HUM) || defined (COAP_RESOURCE_ALL)  
  49.   components new SensirionSht11C() as HumTempSensor;  
  50. #endif  
  51.   
  52. #ifdef COAP_RESOURCE_TEMP  
  53.   components new CoapReadResourceC(uint16_t, INDEX_TEMP) as CoapReadTempResource;  
  54.   components new CoapBufferTempTranslateC() as CoapBufferTempTranslate;  
  55.   CoapReadTempResource.Read -> CoapBufferTempTranslate.ReadTemp;  
  56.   CoapBufferTempTranslate.Read -> HumTempSensor.Temperature;  
  57.   CoapUdpServerC.CoapResource[INDEX_TEMP] -> CoapReadTempResource.CoapResource;  
  58. #if defined (COAP_CONTENT_TYPE_JSON) || defined (COAP_CONTENT_TYPE_XML)  
  59.   CoapReadTempResource.LocalIeeeEui64 -> LocalIeeeEui64C;  
  60. #endif  
  61. #endif  
  62.   
  63. #ifdef COAP_RESOURCE_HUM  
  64.   components new CoapReadResourceC(uint16_t, INDEX_HUM) as CoapReadHumResource;  
  65.   components new CoapBufferHumTranslateC() as CoapBufferHumTranslate;  
  66.   CoapReadHumResource.Read -> CoapBufferHumTranslate.ReadHum;  
  67.   CoapBufferHumTranslate.Read -> HumTempSensor.Humidity;  
  68.   CoapUdpServerC.CoapResource[INDEX_HUM] -> CoapReadHumResource.CoapResource;  
  69. #if defined (COAP_CONTENT_TYPE_JSON) || defined (COAP_CONTENT_TYPE_XML)  
  70.   CoapReadHumResource.LocalIeeeEui64 -> LocalIeeeEui64C;  
  71. #endif  
  72. #endif  
  73.   
  74. #if defined (COAP_RESOURCE_VOLT)  || defined (COAP_RESOURCE_ALL) || defined (COAP_RESOURCE_IPSO_DEV_BAT)  
  75.   components new VoltageC() as VoltSensor;  
  76. #endif  
  77.   
  78. #ifdef COAP_RESOURCE_VOLT  
  79.   components new CoapReadResourceC(uint16_t, INDEX_VOLT) as CoapReadVoltResource;  
  80.   components new CoapBufferVoltTranslateC() as CoapBufferVoltTranslate;  
  81.   CoapReadVoltResource.Read -> CoapBufferVoltTranslate.ReadVolt;  
  82.   CoapBufferVoltTranslate.Read -> VoltSensor.Read;  
  83.   CoapUdpServerC.CoapResource[INDEX_VOLT] -> CoapReadVoltResource.CoapResource;  
  84. #if defined (COAP_CONTENT_TYPE_JSON) || defined (COAP_CONTENT_TYPE_XML)  
  85.   CoapReadVoltResource.LocalIeeeEui64 -> LocalIeeeEui64C;  
  86. #endif  
  87. #endif  
  88.   
  89. #ifdef COAP_RESOURCE_ALL  
  90.   components new CoapReadResourceC(val_all_t, INDEX_ALL) as CoapReadAllResource;  
  91.   components new SensirionSht11C() as HumTempSensorAll;  
  92.   components CoapResourceCollectorC;  
  93.   CoapReadAllResource.Read -> CoapResourceCollectorC.ReadAll;  
  94.   components new CoapBufferTempTranslateC() as CoapBufferTempTranslateAll;  
  95.   CoapResourceCollectorC.ReadTemp -> CoapBufferTempTranslateAll.ReadTemp;  
  96.   CoapBufferTempTranslateAll.Read -> HumTempSensorAll.Temperature;  
  97.   components new CoapBufferHumTranslateC() as CoapBufferHumTranslateAll;  
  98.   CoapResourceCollectorC.ReadHum -> CoapBufferHumTranslateAll.ReadHum;  
  99.   CoapBufferHumTranslateAll.Read -> HumTempSensorAll.Humidity;  
  100.   components new CoapBufferVoltTranslateC() as CoapBufferVoltTranslateAll;  
  101.   CoapResourceCollectorC.ReadVolt -> CoapBufferVoltTranslateAll.ReadVolt;  
  102.   CoapBufferVoltTranslateAll.Read -> VoltSensor.Read;  
  103.   CoapUdpServerC.CoapResource[INDEX_ALL] -> CoapReadAllResource.CoapResource;  
  104. #if defined (COAP_CONTENT_TYPE_JSON) || defined (COAP_CONTENT_TYPE_XML)  
  105.   CoapReadAllResource.LocalIeeeEui64 -> LocalIeeeEui64C;  
  106. #endif  
  107. #endif  
  108.   
  109. #ifdef COAP_RESOURCE_KEY  
  110.   components new CoapFlashResourceC(INDEX_KEY) as CoapFlashResource;  
  111.   components new ConfigStorageC(VOLUME_CONFIGKEY);  
  112.   CoapFlashResource.ConfigStorage -> ConfigStorageC.ConfigStorage;  
  113.   CoapBlipP.Mount  -> ConfigStorageC.Mount;  
  114.   CoapUdpServerC.CoapResource[INDEX_KEY]  -> CoapFlashResource.CoapResource;  
  115. #endif  
  116.   
  117. #ifdef COAP_RESOURCE_LED  
  118.   components new CoapLedResourceC(INDEX_LED) as CoapLedResource;  
  119.   CoapLedResource.Leds -> LedsC;  
  120.   CoapUdpServerC.CoapResource[INDEX_LED]  -> CoapLedResource.CoapResource;  
  121. #endif  
  122.   
  123. #ifdef COAP_RESOURCE_ROUTE  
  124.   components new CoapRouteResourceC(uint16_t, INDEX_ROUTE) as CoapReadRouteResource;  
  125.   CoapReadRouteResource.ForwardingTable -> IPStackC;  
  126.   CoapUdpServerC.CoapResource[INDEX_ROUTE] -> CoapReadRouteResource.CoapResource;  
  127. #endif  
  128.   
  129. #ifdef COAP_RESOURCE_ETSI_IOT_VALIDATE  
  130.   components new CoapEtsiValidateResourceC(INDEX_ETSI_VALIDATE);  
  131.   CoapUdpServerC.CoapResource[INDEX_ETSI_VALIDATE] -> CoapEtsiValidateResourceC.CoapResource;  
  132.   CoapEtsiValidateResourceC.Leds -> LedsC;  
  133.   CoapEtsiValidateResourceC.CoAPServer ->  CoapUdpServerC;  
  134. #endif  
  135.   
  136. #ifdef COAP_RESOURCE_ETSI_IOT_SEPARATE  
  137.   components new CoapEtsiSeparateResourceC(INDEX_ETSI_SEPARATE);  
  138.   CoapUdpServerC.CoapResource[INDEX_ETSI_SEPARATE] -> CoapEtsiSeparateResourceC.CoapResource;  
  139. #endif  
  140.   
  141. #ifdef COAP_RESOURCE_ETSI_IOT_SEGMENT  
  142.   components new CoapEtsiSegmentResourceC(INDEX_ETSI_SEGMENT);  
  143.   CoapUdpServerC.CoapResource[INDEX_ETSI_SEGMENT] -> CoapEtsiSegmentResourceC.CoapResource;  
  144. #endif  
  145.   
  146. #ifdef COAP_RESOURCE_ETSI_IOT_LARGE  
  147.   components new CoapEtsiLargeResourceC(INDEX_ETSI_LARGE);  
  148.   CoapEtsiLargeResourceC.Leds -> LedsC;  
  149.   CoapUdpServerC.CoapResource[INDEX_ETSI_LARGE] -> CoapEtsiLargeResourceC.CoapResource;  
  150. #endif  
  151.   
  152. #ifdef COAP_RESOURCE_ETSI_IOT_OBSERVE  
  153.   components new CoapEtsiObserveResourceC(INDEX_ETSI_OBSERVE);  
  154.   CoapEtsiObserveResourceC.Leds -> LedsC;  
  155.   CoapUdpServerC.CoapResource[INDEX_ETSI_OBSERVE] -> CoapEtsiObserveResourceC.CoapResource;  
  156. #endif  
  157.   
  158. #ifdef COAP_RESOURCE_ETSI_IOT_MULTI_FORMAT  
  159.   components new CoapEtsiMultiFormatResourceC(INDEX_ETSI_MULTI_FORMAT);  
  160.   CoapEtsiMultiFormatResourceC.Leds -> LedsC;  
  161.   CoapUdpServerC.CoapResource[INDEX_ETSI_MULTI_FORMAT] -> CoapEtsiMultiFormatResourceC.CoapResource;  
  162. #if defined (COAP_CONTENT_TYPE_JSON) || defined (COAP_CONTENT_TYPE_XML)  
  163.   CoapEtsiMultiFormatResourceC.LocalIeeeEui64 -> LocalIeeeEui64C;  
  164. #endif  
  165. #endif  
  166.   
  167. #ifdef COAP_RESOURCE_ETSI_IOT_LINK  
  168.   components new CoapEtsiLinkResourceC(INDEX_ETSI_LINK1) as Link1Resource;  
  169.   CoapUdpServerC.CoapResource[INDEX_ETSI_LINK1] -> Link1Resource.CoapResource;  
  170.   components new CoapEtsiLinkResourceC(INDEX_ETSI_LINK2) as Link2Resource;  
  171.   CoapUdpServerC.CoapResource[INDEX_ETSI_LINK2] -> Link2Resource.CoapResource;  
  172.   components new CoapEtsiLinkResourceC(INDEX_ETSI_LINK3) as Link3Resource;  
  173.   CoapUdpServerC.CoapResource[INDEX_ETSI_LINK3] -> Link3Resource.CoapResource;  
  174.   components new CoapEtsiLinkResourceC(INDEX_ETSI_LINK4) as Link4Resource;  
  175.   CoapUdpServerC.CoapResource[INDEX_ETSI_LINK4] -> Link4Resource.CoapResource;  
  176.   components new CoapEtsiLinkResourceC(INDEX_ETSI_LINK5) as Link5Resource;  
  177.   CoapUdpServerC.CoapResource[INDEX_ETSI_LINK5] -> Link5Resource.CoapResource;  
  178.   components new CoapEtsiLinkResourceC(INDEX_ETSI_PATH) as PathResource;  
  179.   CoapUdpServerC.CoapResource[INDEX_ETSI_PATH] -> PathResource.CoapResource;  
  180.   components new CoapEtsiLinkResourceC(INDEX_ETSI_PATH1) as Path1Resource;  
  181.   CoapUdpServerC.CoapResource[INDEX_ETSI_PATH1] -> Path1Resource.CoapResource;  
  182.   components new CoapEtsiLinkResourceC(INDEX_ETSI_PATH2) as Path2Resource;  
  183.   CoapUdpServerC.CoapResource[INDEX_ETSI_PATH2] -> Path2Resource.CoapResource;  
  184.   components new CoapEtsiLinkResourceC(INDEX_ETSI_PATH3) as Path3Resource;  
  185.   CoapUdpServerC.CoapResource[INDEX_ETSI_PATH3] -> Path3Resource.CoapResource;  
  186. #endif  
  187. #ifdef COAP_RESOURCE_ETSI_IOT_LOCATION_QUERY  
  188.   components new CoapEtsiLocationQueryResourceC(INDEX_ETSI_LOCATION_QUERY) as LocationQueryResource;  
  189.   CoapUdpServerC.CoapResource[INDEX_ETSI_LOCATION_QUERY] -> LocationQueryResource.CoapResource;  
  190. #endif  
  191. #ifdef COAP_RESOURCE_ETSI_IOT_QUERY  
  192.   components new CoapEtsiLocationQueryResourceC(INDEX_ETSI_QUERY) as QueryResource;  
  193.   CoapUdpServerC.CoapResource[INDEX_ETSI_QUERY] -> QueryResource.CoapResource;  
  194. #endif  
  195.   
  196.   
  197. //IPSO  
  198. #ifdef COAP_RESOURCE_IPSO_DEV_MFG  
  199.   components new CoapIpsoDevMfgResourceC(INDEX_IPSO_DEV_MFG) as DevMfgResource;  
  200.   CoapUdpServerC.CoapResource[INDEX_IPSO_DEV_MFG] -> DevMfgResource.CoapResource;  
  201. #endif  
  202. #ifdef COAP_RESOURCE_IPSO_DEV_MDL  
  203.   components new CoapIpsoDevMdlResourceC(INDEX_IPSO_DEV_MDL) as DevMdlResource;  
  204.   CoapUdpServerC.CoapResource[INDEX_IPSO_DEV_MDL] -> DevMdlResource.CoapResource;  
  205. #endif  
  206. #ifdef COAP_RESOURCE_IPSO_DEV_SER  
  207.   components new CoapIpsoDevSerialResourceC(INDEX_IPSO_DEV_SER) as DevSerialResource;  
  208.   CoapUdpServerC.CoapResource[INDEX_IPSO_DEV_SER] -> DevSerialResource.CoapResource;  
  209. #endif  
  210. #ifdef COAP_RESOURCE_IPSO_DEV_N  
  211.   components new CoapIpsoDevNameResourceC(INDEX_IPSO_DEV_N) as DevNameResource;  
  212.   CoapUdpServerC.CoapResource[INDEX_IPSO_DEV_N] -> DevNameResource.CoapResource;  
  213. #endif  
  214. #ifdef COAP_RESOURCE_IPSO_DEV_BAT  
  215.   components new CoapIpsoDevBatteryResourceC(uint16_t, INDEX_IPSO_DEV_BAT) as DevBatteryResource;  
  216.   components new CoapBufferVoltTranslateC() as CoapBufferVoltTranslate;  
  217.   CoapUdpServerC.CoapResource[INDEX_IPSO_DEV_BAT] -> DevBatteryResource.CoapResource;  
  218.   DevBatteryResource.Read -> CoapBufferVoltTranslate.ReadVolt;  
  219.   CoapBufferVoltTranslate.Read -> VoltSensor.Read;  
  220. #endif  
  221.   
  222. #endif  
  223.   
  224. #ifdef COAP_CLIENT_ENABLED  
  225.   components CoapUdpClientC;  
  226.   components new UdpSocketC() as UdpClientSocket;  
  227.   CoapBlipP.CoAPClient -> CoapUdpClientC;  
  228.   CoapUdpClientC.LibCoapClient -> LibCoapAdapterC.LibCoapClient;  
  229.   LibCoapAdapterC.UDPClient -> UdpClientSocket;  
  230.   CoapBlipP.ForwardingTableEvents -> IPStackC.ForwardingTableEvents;  
  231. #endif  
  232.   
  233. #ifdef PRINTFUART_ENABLED  
  234.   /* This component wires printf directly to the serial port, and does  
  235.    * not use any framing.  You can view the output simply by tailing  
  236.    * the serial device.  Unlike the old printfUART, this allows us to  
  237.    * use PlatformSerialC to provide the serial driver.  
  238.    *  
  239.    * For instance:  
  240.    * $ stty -F /dev/ttyUSB0 115200  
  241.    * $ tail -f /dev/ttyUSB0  
  242.   */  
  243.   // components SerialPrintfC;  
  244.   
  245.   /* This is the alternative printf implementation which puts the  
  246.    * output in framed tinyos serial messages.  This lets you operate  
  247.    * alongside other users of the tinyos serial stack.  
  248.    */  
  249.   components PrintfC;  
  250.   components SerialStartC;  
  251. #endif  
  252.   }  

看着这是蛮多的,但是TinyOS的官方例程在Makefile指定了只有LED资源


CoapBlipP.nc文件:

  1. /********************************************************************************************************************************************************  
  2.  *实验8----zigbee CoAP实验(路由为roll)  
  3.  *节点需求数 >= 2  
  4.  *编译命令make cc2538cb blip coap id.xx (xx为1~65533,注意此实验需要用到实验7,id勿与实验7重复)  
  5.  *测试命令:  
  6.  *1,先下载实验7的边界路由,sudo /usr/bin/pppd-hack/sbin/pppd debug passive noauth nodetach 115200 /dev/ttyUSB0 nocrtscts nocdtrcts lcp-echo-interval 0 noccp noip ipv6 ::23,::24 连接边界路由  
  7.  *2,新打开shell,执行sudo ifconfig ppp0 add fec0::100/64  
  8.  *3,烧写实验8的bin到节点  
  9.  *4,ping6 ff02::xx(xx为1~65533,且为烧写的测试节点号 (该步骤可省略)  
  10.  *5,参考网页测试;http://tinyos.stanford.edu/tinyos-wiki/index.php/CoAP_-17   
  11.  *   shell进入tinyos-main-release_tinyos_2_1_2\support\sdk\c\coap\examples目录     
  12.  * 5.1   GET request测试:  ./coap-client coap://[fec0::xx]/l             其中xx为实验8 的编译id  
  13.  * 5.2   PUT request:测试: ./coap-client -m put coap://[fec0::xx]/l -e 7  其中xx为实验8 的编译id,其中7为bit操作  
  14.  * 对应bit2:bit0分别为led2,led1,led0,置0为灭置1位亮,用户可以put以后再get一次,看看值是否正确,故7为全亮,0为全灭  
  15.  *也可以参考\apps\cc2538_Test\PppRouter下的README.blip进行测试,但是注意第一步命令pppd的区别  
  16.  *  
  17.  *通过例程的学习可以自己注册资源,如传感器,电机控制等,进行应用拓展  
  18.  *******************************************************************************************************************************************************/  
  19.   
  20. #include <IPDispatch.h>  
  21. #include <lib6lowpan/lib6lowpan.h>  
  22. #include <lib6lowpan/ip.h>  
  23. #include "blip_printf.h"  
  24.   
  25. #include "net.h"  
  26. #include "resource.h"  
  27.   
  28. #ifdef COAP_CLIENT_ENABLED  
  29. #include "tinyos_net.h"  
  30. #include "option.h"  
  31. #include "address.h"  
  32. #endif  
  33.   
  34. #ifndef COAP_SERVER_PORT  
  35. #define COAP_SERVER_PORT COAP_DEFAULT_PORT  
  36. #endif  
  37.   
  38. module CoapBlipP {  
  39.   uses {  
  40.     interface Boot;  
  41.     interface SplitControl as RadioControl;  
  42.     interface Leds;  
  43.   
  44. #ifdef COAP_SERVER_ENABLED  
  45.     interface CoAPServer;  
  46. #ifdef COAP_RESOURCE_KEY  
  47.     interface Mount;  
  48. #endif  
  49. #endif  
  50.   
  51. #ifdef COAP_CLIENT_ENABLED  
  52.     interface CoAPClient;  
  53.     interface ForwardingTableEvents;  
  54. #endif  
  55.   }  
  56.   
  57. } implementation {  
  58. #ifdef COAP_CLIENT_ENABLED  
  59.   uint8_t node_integrate_done = FALSE;  
  60. #endif  
  61.   
  62.   event void Boot.booted() {  
  63.   
  64.     call RadioControl.start();  
  65.     printf("booted %i start\n", TOS_NODE_ID);  
  66. #ifdef COAP_SERVER_ENABLED  
  67. #ifdef COAP_RESOURCE_KEY  
  68.     if (call Mount.mount() == SUCCESS) {  
  69.       printf("CoapBlipP.Mount successful\n");  
  70.     }  
  71. #endif  
  72.   
  73.     // needs to be before registerResource to setup context:  
  74.     call CoAPServer.setupContext(COAP_SERVER_PORT);  
  75.     call CoAPServer.registerResources();  
  76.   
  77. #endif  
  78.   
  79. #ifdef COAP_CLIENT_ENABLED  
  80.     // needs to be before registerResource to setup context:  
  81.     call CoAPClient.setupContext(COAP_CLIENT_PORT);  
  82. #endif  
  83.   
  84.   }  
  85.   
  86. #if defined (COAP_SERVER_ENABLED) && defined (COAP_RESOURCE_KEY)  
  87.   event void Mount.mountDone(error_t error) {  
  88.   }  
  89. #endif  
  90.   
  91.   event void RadioControl.startDone(error_t e) {  
  92.     printf("radio startDone: %i\n", TOS_NODE_ID);  
  93.   }  
  94.   
  95.   event void RadioControl.stopDone(error_t e) {  
  96.   }  
  97.   
  98. #ifdef COAP_CLIENT_ENABLED  
  99.   event void ForwardingTableEvents.defaultRouteAdded() {  
  100.       //struct sockaddr_in6 sa6;  
  101.       coap_address_t dest;  
  102.       coap_list_t *optlist = NULL;  
  103.   
  104.       if (node_integrate_done == FALSE) {  
  105.       node_integrate_done = TRUE;  
  106.   
  107.       inet_pton6(COAP_CLIENT_DEST, &dest.addr.sin6_addr);  
  108.       dest.addr.sin6_port = htons(COAP_CLIENT_PORT);  
  109.   
  110.       coap_insert( &optlist, new_option_node(COAP_OPTION_URI_PATH, sizeof("ni") - 1, "ni"), order_opts);  
  111.   
  112.       // this stuff should most likely be POST!  
  113.       call CoAPClient.request(&dest, COAP_REQUEST_PUT, optlist, 0, NULL);  
  114.       }  
  115.   }  
  116.   
  117.   event void ForwardingTableEvents.defaultRouteRemoved() {  
  118.   }  
  119.   
  120.   event error_t CoAPClient.streamed_next_block (uint16_t blockno, uint16_t *len, void **data)  
  121.   {  
  122.     return FAIL;  
  123.   }  
  124.   
  125.   event void CoAPClient.request_done(uint8_t code, uint16_t len, void *data) {  
  126.       //event void CoAPClient.request_done(uint8_t code, uint8_t mediatype, uint16_t len, void *data, bool more) {  
  127.     //TODO: handle the request_done  
  128.   };  
  129. #endif  
  130.   
  131.   }  

一般来说我们在2538上都是运行CoAP Server,PC端运行client,通过边界路由来获取资源;get/put方法


tinyos_coap_resources.h文件:

太长了,只是弄出LED部分,让大家知道为什么测试的时候是coap  ...l;这个"l"字符;

  1. #ifdef COAP_RESOURCE_LED  
  2.   {  
  3.       INDEX_LED,  
  4.       "l", sizeof("l"),  
  5. #if defined (COAP_CONTENT_TYPE_JSON) || defined (COAP_CONTENT_TYPE_XML)  
  6.       "", "",  
  7. #endif  
  8.       {0,0,0,0}, // uri_key will be set later  
  9.       COAP_DEFAULT_MAX_AGE,  
  10.       (GET_SUPPORTED | PUT_SUPPORTED),  
  11.       1  
  12.   },  
  13. #endif  


测试部分大家可以参考TinyOS的官网,搜索CoAP部分测试方法,注意编译时候的CoapBlip的节点号(id.xx)


测试我们通过tinyos-main-release_tinyos_2_1_2\support\sdk\c\coap\examples下的coap-client;测试命令参考TinyOS官网;我们也可以按照视频介绍在shell输入命令get方法,通过zigbee获取CoapBlip节点的三个LED的状态;也可以控制三个LED的亮灭(put方法),当然你也可以使用ping6命令来玩,或者路由读取命令查看网络;


tinyos-main-release_tinyos_2_1_2\support\sdk\c\coap是已经编译过的,用户无需再进行make;这是CoAP的C语言版本--libcoap,可以通过他学习使用,注册资源,自己动手注册温度或其他传感器资源;参考哥伦比亚大学的COAP框架(JAVA版本),或者其他你擅长的语言版本,可以去我的那篇帖子找见支持CoAP的其他语言开源版本,自己编写PC端或安卓的浏览器插件,或者浏览器界面,应用软件界面,最近事情有点多,先放着,以后补充!

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

热门文章