tinyos CTP温湿度采集 android终端显示
来源:互联网 发布:恢复数据多少钱 编辑:程序博客网 时间:2024/04/19 23:34
最近玩了一下android,又弄了一下tinyos,一直都想做出点东西,把所学的东西串起来,所以就做了一个温湿度采集的小系统,通过ARM开发板的usb-host来直接连接telosb节点,实现数据的显示,根节点作为数据中转,生产节点做数据采集,并引入CTP组网,测试了一下,效果还可以,在这里奉上代码,闲话休聊,上图上代码
代码:()
tinyos:
#include <Timer.h>
module CTPsensorC {
uses interface Boot;
uses interface SplitControl as RadioControl;
uses interface StdControl as RoutingControl;
uses interface Send;
uses interface Leds;
uses interface Timer<TMilli>;
uses interface RootControl;
uses interface Receive;
uses interface Read<uint16_t> as Read1;
uses interface Read<uint16_t> as Read2;
}
implementation {
message_t packet;
bool sendBusy = FALSE;
bool type=FALSE;
typedef nx_struct EasyCollectionMsg {
nx_uint16_t data;
nx_uint16_t data2;
} EasyCollectionMsg;
event void Boot.booted() {
call RadioControl.start();
}
event void RadioControl.startDone(error_t err) {
if (err != SUCCESS)
call RadioControl.start();
else {
call RoutingControl.start();
if (TOS_NODE_ID == 1)
call RootControl.setRoot();
else
call Timer.startPeriodic(2000);
}
}
event void RadioControl.stopDone(error_t err) {}
event void Timer.fired() {
call Leds.led0Toggle();
if(type==FALSE)
{
call Read1.read();//read Humidity
type=TRUE;
}
else
{
call Read2.read();//read Temperature
type=FALSE;
}
}
event void Read1.readDone(error_t result, uint16_t val){
if(result == SUCCESS) {
EasyCollectionMsg* msg = (EasyCollectionMsg*)call Send.getPayload(&packet);
msg->data =5;
msg->data2 =-4+0.0405*val+(-2.8/1000000)*(val*val);
if (call Send.send(&packet, sizeof(EasyCollectionMsg)) != SUCCESS)
call Leds.led1On();
else
sendBusy = TRUE;
}
}
event void Read2.readDone(error_t result, uint16_t val){
if(result == SUCCESS) {
EasyCollectionMsg* msg = (EasyCollectionMsg*)call Send.getPayload(&packet);
msg->data =6;
msg->data2 =-39.6+0.01*val;
if (call Send.send(&packet, sizeof(EasyCollectionMsg)) != SUCCESS)
call Leds.led1On();
else
sendBusy = TRUE;
}
}
event void Send.sendDone(message_t* m, error_t err) {
if (err != SUCCESS)
call Leds.led1On();
sendBusy = FALSE;
}
event message_t*
Receive.receive(message_t* msg, void* payload, uint8_t len) {
call Leds.led1Toggle();
return msg;
}
}
configuration CTPsensorAppC {}
implementation {
components CTPsensorC, MainC, LedsC, ActiveMessageC;
components CollectionC as Collector;
components new CollectionSenderC(0xee);
components new TimerMilliC();
components new SensirionSht11C() as Sense;
CTPsensorC.Boot -> MainC;
CTPsensorC.RadioControl -> ActiveMessageC;
CTPsensorC.RoutingControl -> Collector;
CTPsensorC.Leds -> LedsC;
CTPsensorC.Timer -> TimerMilliC;
CTPsensorC.Send -> CollectionSenderC;
CTPsensorC.RootControl -> Collector;
CTPsensorC.Receive -> Collector.Receive[0xee];
CTPsensorC.Read2->Sense.Temperature;
CTPsensorC.Read1->Sense.Humidity;
}
android:
package my.lchmcu.CtpSensorTH;
import java.util.Arrays;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;
import com.friendlyarm.AndroidSDK.HardwareControler;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */
TextView T1;
TextView H1;
TextView T2;
TextView H2;
EditText ET1;
private int fd;
private int flag;
private int readS;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
T1=(TextView) findViewById(R.id.T1);
H1=(TextView) findViewById(R.id.H1);
T2=(TextView) findViewById(R.id.T2);
H2=(TextView) findViewById(R.id.H2);
ET1=(EditText) findViewById(R.id.ET1);
fd=HardwareControler.openSerialPort("/dev/ttyUSB1", 115200, 8, 1);
//HardwareControler.setLedState(0,1);
Log.i("sensor", "fd"+fd);
handler.post(runnable);
}
Handler handler = new Handler();
Runnable runnable = new Runnable()
{
public void run()
{
// 要做的事情
flag=HardwareControler.select(fd, 2, 20);
//Log.i("sensor", "flag"+flag);
if(flag==1)
{
//Log.i("sensor", "read data now!");
byte[] buf =new byte[25];
//String buf2[] =new String[16];
//int i;
readS=HardwareControler.read(fd, buf, buf.length);
if(readS>0)
{
//Log.i("sensor", "read successful!");
if(buf[0]==126 && buf[24]==126)
//if(buf[0]==126)
{
/* for(i=0;i<16;i++)
{
buf2[i]=Integer.toHexString(buf[i]);
}
//Log.i("sensor","data"+Arrays.toString(buf));
//Log.i("sensor","data"+Integer.toHexString(buf[15]));
Log.i("sensor","data"+Arrays.toString(buf2));*/
//Log.i("sensor","data"+Arrays.toString(buf));
/* if(buf[10]==5)
{
H1.setText("湿度值: "+buf[12]);
}
else if(buf[10]==6)
{
T1.setText("温度值: "+buf[12]);
}*/
ET1.setText("Sensor Data:"+Arrays.toString(buf));
if(buf[15]==2)
{
if(buf[19]==5)
{
H1.setText("湿度值:"+buf[21]);
}
else if(buf[19]==6)
{
T1.setText("温度值: "+buf[21]);
}
}
if(buf[15]==3)
{
if(buf[19]==5)
{
H2.setText("湿度值:"+buf[21]);
}
else if(buf[19]==6)
{
T2.setText("温度值: "+buf[21]);
}
}
}
}
}
//HardwareControler.read(fd, buf, 16);
//Log.i("sensor","data"+buf);
handler.postDelayed(this, 100);
}
};
}
- tinyos CTP温湿度采集 android终端显示
- TinyOS CTP协议分析
- TinyOS CTP协议分析
- 利用arduino采集温湿度,客户端程序显示实时曲线图
- TinyOS下TOSSIM仿真CTP
- arduino采集温湿度
- ESP8266采集SHT10温湿度
- Tinyos 采集noise floor
- tinyos下TestNetwork实例的数据解析--CTP数据格式
- Tinyos中CC2420和CTP协议的数据包格式
- 无线传感器网络-仓库温湿度采集系统
- STM32 SHT10温湿度传感器的信号采集
- 巧用LoRa无线网络 远距离采集温湿度
- 【BLE】CC2541之DHT11温湿度采集
- (单片机)显示温湿度程序
- 嵌入式多路温湿度监控系统(十51单片机温湿度采集模块)
- 【物联网智能网关-01】通过AD采集获取温湿度
- 基于FSIOT_A 实验平台SAM3S4B cortex-M3的温湿度采集
- 三元表达式
- UIView相关方法
- 严重: Parse Fatal Error at line 154 column 33: Invalid byte 2 of 2-byte UTF-8 sequence.
- 程序员编程艺术:第九章、闲话链表追赶问题
- C#多线程参数传递
- tinyos CTP温湿度采集 android终端显示
- quest3d Lua script中的字符串函数库
- (5)[Bx]及loop
- java网络异常类型
- android 探索首选项框架 ListPreference
- vs2005 QT4.7.1编译 详细
- 程序员编程艺术:第十章、如何给10^7个数据量的磁盘文件排序
- Java、JavaScript、php、mysql、oracle生成uuid(32位)
- printk 运行级别定义