一、实验目的
实现用户的在线浏览监测数据消息,能够迅速准确地将城市信息实施传输和提现,便于市民出行选择,便于相关部门处理突发事件,进而为城市中的人创造更美好的生活,促进城市的和谐、可持续成长。
二、实验任务
1.实时采集温湿度,光照。
2.实现对LCD的自动控制,当OneNET平台发送1时lcd平白屏,当OneNET平台发送0时LCD屏黑屏。
三、 实验步骤(在项目一 智慧城市环境监测系统编码中添加修改程序)
1.头文件添加和相应的变量
#include "Lcd_Driver.h" /* LCD */
nbiot_value_t illumi; //光照
nbiot_value_t led; // led
2.写回调函数(添加、调用lcd屏函数)
void write_callback(
uint16_t objid,
uint16_t instid,
uint16_t resid,
nbiot_value_t *data)
{
printf("write /%d/%d/%d:%d\r\n",
objid,
instid,
resid, data->value.as_bool);
if(objid == 3311 && instid == 0 && resid == 5850)
{
if(data->value.as_bool)
{
//打开白色背景光以模拟led灯开
Lcd_Clear(WHITE);
ledStatus.Led1Sta=1;
}
else
{
//打开黑色背景光以模拟led灯开
Lcd_Clear(BLACK);
ledStatus.Led1Sta=0;
}
}
}
3.添加读回调函数(把湿度修改成光照的参数值)
if(objid == 3303 && instid == 0 && resid == 5700)
{
SHT20_INFO sht20 = { 0 };
sht20 = SHT20_GetValue();
temp.value.as_float = sht20.tempreture;
}
else if(objid == 3301 && instid == 0 && resid == 5700)
{
BH1750_test();
illumi.value.as_float = result_lx;
}
4.更新资源(使平台实时更新数据)
void res_update(time_t interval)
{
SHT20_INFO sht20;
if (cur_time >= last_time + interval) {
cur_time = 0;
last_time = 0;
/* 更新温湿度光照数值 */
temp.flag |= NBIOT_UPDATED;
humi.flag |= NBIOT_UPDATED;
illumi.flag |= NBIOT_UPDATED;
led.flag |= NBIOT_UPDATED;
led.value.as_bool = ledStatus.Led1Sta;
BH1750_test();
sht20 = SHT20_GetValue();
temp.value.as_float = sht20.tempreture;
humi.value.as_float = sht20.humidity;
illumi.value.as_float = result_lx;
} else if (cur_time == 0 && last_time == 0) {
cur_time = nbiot_time();
last_time = cur_time;
} else {
cur_time = nbiot_time();
}
}
4.添加光照和lcd屏资源
illumi.type = NBIOT_FLOAT;
illumi.flag = NBIOT_READABLE;
ret = nbiot_resource_add(dev,
3301,
0,
5700,
&illumi);
if (ret)
{
nbiot_device_destroy(dev);
printf("device add resource(illumi) failed, code = %d.\r\n", ret);
}
led.type = NBIOT_BOOLEAN;
led.flag = NBIOT_READABLE | NBIOT_WRITABLE;
ret = nbiot_resource_add(dev,
3311,
0,
5850,
&led);
if (ret)
{
nbiot_device_destroy(dev);
printf("device add resource(led) failed, code = %d.\r\n", ret);
}