如何修复此错误:
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 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();
}
/*---------------------------------------------------------------------------*/
发布于 2015-03-11 04:07:37
据我所知,Micaz微尘没有按钮,因此对button_sensor传感器的引用是无效的。
该示例被设计为在每次按下按钮时发送一条消息,因此,如果希望该示例正常工作,则需要重写该示例以基于计时器值发送消息。
发布于 2015-03-18 17:25:45
这就是我的写作方式。但是,此节点依赖于需要接受消息的另一个节点!
#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();
}
/*---------------------------------------------------------------------------*/https://stackoverflow.com/questions/28930617
复制相似问题