编译example-mesh.c Contiki

时间:2015-03-08 19:03:22

标签: contiki

如何解决此错误:

undefined reference to button sensor

在contiki中使用Micaz mote编译example-mesh.c

这是我的代码我在mote输出窗口中运行模拟只发送了3条消息,其余的是“packet timedout”我如何根据定时器值解决发送消息的问题?

#include "contiki.h"
#include "net/rime.h"
#include "net/rime/mesh.h"

#include "contiki-conf.h"
#include "sys/etimer.h"
#include "sys/process.h"
#include "sys/ctimer.h"


#include "dev/leds.h"

#include <stdio.h>
#include <string.h>


#define MESSAGE "Hello"

static struct mesh_conn mesh;
/*---------------------------------------------------------------------------*/
PROCESS(example_mesh_process, "Mesh example");
AUTOSTART_PROCESSES(&example_mesh_process);
/*---------------------------------------------------------------------------*/
static void
sent(struct mesh_conn *c)
{
  printf("packet sent\n");
}

static void
timedout(struct mesh_conn *c)
{
     
  printf("packet timedout\n");
}

static void
recv(struct mesh_conn *c, const rimeaddr_t *from, uint8_t hops)
{
  printf("Data received from %d.%d: %.*s (%d)\n",
	 from->u8[0], from->u8[1],
	 packetbuf_datalen(), (char *)packetbuf_dataptr(), packetbuf_datalen());

  packetbuf_copyfrom(MESSAGE, strlen(MESSAGE));
  mesh_send(&mesh, from);
}

const static struct mesh_callbacks callbacks = {recv, sent, timedout};
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(example_mesh_process, ev, data)
{

   static struct etimer et;

  PROCESS_EXITHANDLER(mesh_close(&mesh);)

  PROCESS_BEGIN();

  mesh_open(&mesh, 132, &callbacks);

 

  while(1) {
   rimeaddr_t addr;
 etimer_set(&et, 5 * CLOCK_SECOND);
 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
 etimer_reset(&et); 

 
    /* Send a message to node number 1. */
    
    packetbuf_copyfrom(MESSAGE, strlen(MESSAGE));
    addr.u8[0] = 1;
    addr.u8[1] = 0;
    mesh_send(&mesh, &addr);
}
  PROCESS_END();
}
/*---------------------------------------------------------------------------*/

2 个答案:

答案 0 :(得分:0)

据我所知,Micaz mote没有按钮,因此对 button_sensor 传感器的引用无效。

该示例旨在每次按下按钮时发送消息,因此如果您希望此示例正常工作,则需要重写示例以根据计时器值发送消息。

答案 1 :(得分:0)

这就是我写它的方式。但是,此节点依赖于需要接受消息的另一个节点!

#include "contiki.h"
#include "net/rime.h"
#include "net/rime/mesh.h"

#include <stdio.h>
#include <string.h>


#define MESSAGE "Hello"

static struct mesh_conn mesh;
/*---------------------------------------------------------------------------*/
PROCESS(example_mesh_process, "Mesh example");
AUTOSTART_PROCESSES(&example_mesh_process);
/*---------------------------------------------------------------------------*/
static void
sent(struct mesh_conn *c)
{
  printf("packet sent\n");
}

static void
timedout(struct mesh_conn *c)
{

  printf("packet timedout\n");
}

static void
recv(struct mesh_conn *c, const rimeaddr_t *from, uint8_t hops)
{
  printf("Data received from %d.%d: %.*s (%d)\n",
     from->u8[0], from->u8[1],
     packetbuf_datalen(), (char *)packetbuf_dataptr(), packetbuf_datalen());

  packetbuf_copyfrom(MESSAGE, strlen(MESSAGE));
  mesh_send(&mesh, from);
}

const static struct mesh_callbacks callbacks = {recv, sent, timedout};
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(example_mesh_process, ev, data)
{
  static struct etimer et;

  PROCESS_EXITHANDLER(mesh_close(&mesh);)
  PROCESS_BEGIN();

  mesh_open(&mesh, 132, &callbacks);

  while(1) {
   linkaddr_t addr;
   etimer_set(&et, 5 * CLOCK_SECOND);
   PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

    /* Send a message to node number 1. */

    packetbuf_copyfrom(MESSAGE, strlen(MESSAGE));
    addr.u8[0] = 1;
    addr.u8[1] = 0;
    mesh_send(&mesh, &addr);
  }
  PROCESS_END();
}
/*---------------------------------------------------------------------------*/