编译示例-mesh.c Contiki.


如何

修复此错误:

undefined reference to button sensor

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

这是我的代码,我在微尘输出窗口中运行模拟,只发送 3 条消息,其余的为"数据包超时",如何解决该问题以根据计时器值发送消息?

#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 sentn");
}
static void
timedout(struct mesh_conn *c)
{
     
  printf("packet timedoutn");
}
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();
}
/*---------------------------------------------------------------------------*/

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

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

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

#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 sentn");
}
static void
timedout(struct mesh_conn *c)
{
  printf("packet timedoutn");
}
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();
}
/*---------------------------------------------------------------------------*/

最新更新