如何使用Contiki-OS读取温度、湿度和光照测量数据? [英] How to read temperature, humidity and light measures with contiki-OS?
本文介绍了如何使用Contiki-OS读取温度、湿度和光照测量数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何使用Contiki程序测量温度、光线和湿度。
我使用的是TelosB微尘(天空微尘),因此这三个传感器集成在微尘本身中。
PS:我正在使用Contiki-OS 2.7
推荐答案
为了使用光和温度传感器,您需要添加下一个:
#include "dev/sht11-sensor.h"
#include "dev/light-sensor.h"
然后您可以使用下面的函数:
static int
get_light(void)
{
return 10 * light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC) / 7;
}
static int
get_temp(void)
{
return ((sht11_sensor.value(SHT11_SENSOR_TEMP) / 10) - 396) / 10;
}
例如,显示这些传感器的值的最小应用程序为:
#include "contiki.h"
#include "dev/sht11-sensor.h"
#include "dev/light-sensor.h"
#include "dev/leds.h"
#include <stdio.h>
//Declare the process
PROCESS(send_sensor_info_process, "Print the Sensors Information");
//Make the process start when the module is loaded
AUTOSTART_PROCESSES(&send_sensor_info_process);
/*---------------------------------------------------------------------------*/
static int
get_light(void)
{
return 10 * light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC) / 7;
}
/*---------------------------------------------------------------------------*/
static int
get_temp(void)
{
return ((sht11_sensor.value(SHT11_SENSOR_TEMP) / 10) - 396) / 10;
}
/*---------------------------------------------------------------------------*/
//Define the process code
PROCESS_THREAD(send_sensor_info_process, ev, data)
{
PROCESS_BEGIN();
SENSORS_ACTIVATE(light_sensor);
SENSORS_ACTIVATE(sht11_sensor);
printf("Light: %d
", get_light());
printf("Temperature: %d
", get_temp());
PROCESS_END();
}
这篇关于如何使用Contiki-OS读取温度、湿度和光照测量数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文