使用 Contiki 的 Http 客户端模式?

Http client mode with Contiki?

我想使用 http 从传感器进行 webAPI 调用,是否可以使用 Contiki OS 进行 http 请求?

就我的搜索而言,我只找到了 coap 客户端示例。

是的,你可以这样做:

据我了解,您正在 Contiki OS 中查找 Websense Example。它使用 HTTP 协议。

答:所以找到这个文件。

~/contiki/examples/zolertia/z1/ipv6/z1-websense/z1-websense.c
  1. 在 Sender Mote 上刻录它。
  2. 刻录位于 /home/superuser/contiki/examples/ipv6/rpl-border-router/
  3. border-router.c 文件
  4. 使用命令 make connect-router 连接边界路由器与 tunnelslip
  5. 使用 HTTP IPV6 url 连接时显示的 tunnelslip
  6. 浏览器中的这个 url 会给你连接到它的微尘地址。
  7. 在 Web 浏览器中使用该发件人微尘地址并查看微尘输出。

B: 或来自 contiki/cooja 模拟器:

启动这个项目文件。这是 websense 的工作演示。

~contiki/examples/zolertia/z1/ipv6/z1-websense/example-z1-websense.csc

并从第 3 步开始重复。

更多的可以问我

检查 examples/http-socket 示例,它显示了如何使用 PUT、GET 等 CRUD 方法

这是link to the example (working with the latest master commit)

此示例依赖于 IP64,但可以更改为使用 IPv6,基本上您需要包含 http-socket 库。以下是示例中更相关的部分:

#include "contiki-net.h"
#include "http-socket.h"
#include "ip64-addr.h"
#include <stdio.h>

static struct http_socket s;
static int bytes_received = 0;

static void
callback(struct http_socket *s, void *ptr,
         http_socket_event_t e,
         const uint8_t *data, uint16_t datalen)
{
  if(e == HTTP_SOCKET_ERR) {
    printf("HTTP socket error\n");
  } else if(e == HTTP_SOCKET_DATA) {
    bytes_received += datalen;
    printf("HTTP socket received %d bytes of data\n", datalen);
  }
}

PROCESS_THREAD(http_example_process, ev, data)
{
  PROCESS_BEGIN();

  /* Initializes the socket */
  http_socket_init(&s);

  /* GET request */
  http_socket_get(&s, "http://www.contiki-os.org/", 0, 0,
                  callback, NULL);

  /* Waits forever for the HTTP callback */
  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(0);
  }

  PROCESS_END();
}