资源描述
网络工程(物联网技术)
课程设计报告
题 目: 基于温湿度传感器物联网应用实时数据解决系统开发
院(系) 别: 数学与信息工程学院
专业: 网络工程(物联网技术) 班级 1 班
学 号: 099914
姓 名: 小 明
指引教师: 职称 博士
填表日期: 年 5 月 11 日
前 言
一、选题根据及意义
1. 根据
物联网是一种新概念和新技术,它使新一代IT技术更加充分地应用于各行各业之中。它问世打破了过去将基本设施与IT设施分开老式观念,将建筑物、公路、铁路和网站、网络、数据中心合为一体,是信息化和工业化融合重要切入点。温湿度与人们生活关系密切,因此物联网在温湿度实时数据解决系统开发将有很大前景。
2. 意义
在咱们寻常生活中无处不在,控制好温湿度可以使咱们生活、生产更好。温湿度传感器物联网应用实时数据解决系统开发可以帮咱们实现对温湿度以实时数据让咱们明了懂得。从而更好控制温湿度、达到咱们所需原则。
二、本课程设计内容简介
1. 通过ubuntu连接传感器实验箱收集由传感器测得实时数据存入sqlite3数据库。
2. 然后通过ubuntu发送到linux、接受并用动态网页显示代表数据变化曲线。
三、要达到目的
1.可以在ubuntu上实现自动接受由传感器获得、传来实时数据。
2. 并ubuntu上能边接受边持续往linux发送从传感器获得实时数据。
3.还要保证发送过数据不会再次发送。
4. Linux能接受到ubuntu发过来实时数据并通过动态网页曲线图实时显示接受过来数据。
实 现 方 案
一、开发环境
1.硬件(详细简介所涉及硬件详细内容)
Pc机、温湿度传感器、传感器实验箱、连接所需各种线。
2.软件(详细简介所涉及软件详细内容)
MDK414(arm平台编译烧录代码软件)、KeilC51v750a_Full(C51平台编译软件)、STC手动下载(C51烧录代码软件)、R340(串口线连接USB驱动)、ubuntu操作系统、linux操作系统。
3.其他
二、开发内容
1.项目开发详细内容(涉及传感器配备、传感器烧录、数据实时收集、实时数据存储、实时数据传播、实时数据在服务器端接受及存储-TCPServer及MySql、数据库及Web服务器安装、运用JSP曲线动态显示实时数据)
一方面烧录整合好温湿度传感器代码。接着连接传感器获得数据。然后在ubuntu中编译并运营Com_Sensor程序获取传感器实验箱数据。
在Ubuntu11编译并运营senddata.c把数据发送到linux.Linux通过TCPServer服务器接受数据并存入MySQL数据库。
最后将接受到数据通过Linuxweb服务器以jsp曲线动态显示实时数据。
2.网络拓扑图(涉及传感器、网关、传播网络、TCPServer服务器、数据库服务器、静态及动态Web服务器、Web服务器客户端;并详细标注设备名称及IP地址等详细信息;并详细论述网络拓扑图流程)
三、技术路线
1. 传感器数据解决(给出详细传感器烧录代码 )
代码如下:
/*********************************************************/
//中软吉大信息技术有限公司
//物联网传感技术教学实验系统
/*********************************************************/
#include <intrins.h> //Keil library (is used for _nop()_ operation)
#include <math.h> //Keil library
#include"Lcmdisplay.h"
#define FOSC 11059200
#define BAUD 14400
typedef union
{ unsigned int i;
float f;
} value;
//----------------------------------------------------------------------------------
// modul-var
//----------------------------------------------------------------------------------
enum {TEMP,HUMI};
#define noACK 0
#define ACK 1
//adr command r/w
#define STATUS_REG_W 0x06 //000 0011 0
#define STATUS_REG_R 0x07 //000 0011 1
#define MEASURE_TEMP 0x03 //000 0001 1
#define MEASURE_HUMI 0x05 //000 0010 1
#define RESET 0x1e //000 1111 0
sbit DATA=P2^2;
sbit SCK=P2^1;
sbit POWER=P2^5;
sbit flag1=P0^7;
sbit flag2=P4^6;
sbit flag3=P2^7;
sbit flag4=P2^6;
void delay(unsigned int nTimeDelay)
{
unsigned int i;
while (nTimeDelay--)
for (i=0;i<125;i++);
}
void Serial_Init()
{
TMOD = 0x01;
TR0 = 1;
EA = 1;
ET0 = 0;
TF0 = 0;
S2CON = 0x50; //8位可变波特率 (无校验位)
BRT = -(FOSC/32/BAUD); //设立独立波特率发生器重载初值
AUXR = 0x14; //独立波特率发生器工作在1T模式
//IE2 = 0x01; //使能串口2中断
}
void IO_Init(void)
{
P2M1=P2M1&0xdf;
P2M0=P2M0&0xdf;
P0M1=P0M1&0x7f;
P0M0=P0M0&0x7f;
P4M1=P4M1&0xbf;
P4M0=P4M0&0xbf;
P2M1=P2M1&0x3f;
P2M0=P2M0&0x3f;
P4SW=P4SW|0x40;
}
void Power_Identify(void)
{
while(1)
{
if(POWER==0)
{
delay(4000);
LcmPrintf("请给传感器模块上电!\n");
}
else break;
}
}
void Module_Identify(unsigned int xuhao)
{
unsigned int abc=0;
if(flag4==1)abc=abc+1;
abc=abc<<1;
if(flag3==1)abc=abc+1;
abc=abc<<1;
if(flag2==1)abc=abc+1;
abc=abc<<1;
if(flag1==1)abc=abc+1;
if(abc!=xuhao)
{
delay(3000);
LcmPrintf("提示:您插入模块不对的!\n");
}
while(1)
{
if(abc!=xuhao);
else
{
delay();
LcmPrintf("连接模块是M%u\n",xuhao);
delay(5000);
break;
}
}
}
//----------------------------------------------------------------------------------
char s_write_byte(unsigned char value)
//----------------------------------------------------------------------------------
// writes a byte on the Sensibus and checks the acknowledge
{
unsigned char i,error=0;
for (i=0x80;i>0;i/=2) //shift bit for masking
{ if (i & value)
DATA=1; //masking value with i ,write to SENSI-BUS
else DATA=0;
_nop_(); //observe setup time
SCK=1; //clk for SENSI-BUS
_nop_();_nop_();_nop_(); //pulswith approx. 5 us
SCK=0;
_nop_(); //observe hold time
}
DATA=1; //release DATA-line
_nop_(); //observe setup time
SCK=1; //clk #9 for ack
error=DATA; //check ack (DATA will be pulled down by SHT11)
SCK=0;
return error; //error=1 in case of no acknowledge
}
//----------------------------------------------------------------------------------
char s_read_byte(unsigned char ack)
//----------------------------------------------------------------------------------
// reads a byte form the Sensibus and gives an acknowledge in case of "ack=1"
{
unsigned char i,val=0;
DATA=1; //release DATA-line
for (i=0x80;i>0;i/=2) //shift bit for masking
{ SCK=1; //clk for SENSI-BUS
if (DATA) val=(val | i); //read bit
SCK=0;
}
DATA=!ack; //in case of "ack==1" pull down DATA-Line
_nop_(); //observe setup time
SCK=1; //clk #9 for ack
_nop_();_nop_();_nop_(); //pulswith approx. 5 us
SCK=0;
_nop_(); //observe hold time
DATA=1; //release DATA-line
return val;
}
//----------------------------------------------------------------------------------
void s_transstart(void)
//----------------------------------------------------------------------------------
// generates a transmission start
// _____ ________
// DATA: |_______|
// ___ ___
// SCK :___| |___| |______
{
DATA=1;SCK=0; //Initial state
_nop_();
SCK=1;
_nop_();
DATA=0;
_nop_();
SCK=0;
_nop_();_nop_();_nop_();
SCK=1;
_nop_();
DATA=1;
_nop_();
SCK=0;
}
//----------------------------------------------------------------------------------
void s_connectionreset(void)
//----------------------------------------------------------------------------------
// communication reset:DATA-line=1 and at least 9 SCK cycles followed by transstart
// _____________________________________________________ ________
// DATA: |_______|
// _ _ _ _ _ _ _ _ _ ___ ___
// SCK :__| |__| |__| |__| |__| |__| |__| |__| |__| |______| |___| |______
{
unsigned char i;
DATA=1;SCK=0; //Initial state
for(i=0;i<9;i++) //9 SCK cycles
{ SCK=1;
SCK=0;
}
s_transstart(); //transmission start
}
//----------------------------------------------------------------------------------
char s_softreset(void)
//----------------------------------------------------------------------------------
// resets the sensor by a softreset
{
unsigned char error=0;
s_connectionreset(); //reset communication
error+=s_write_byte(RESET); //send RESET-command to sensor
return error; //error=1 in case of no response form the sensor
}
//----------------------------------------------------------------------------------
char s_read_statusreg(unsigned char *p_value,unsigned char *p_checksum)
//----------------------------------------------------------------------------------
// reads the status register with checksum (8-bit)
{
unsigned char error=0;
s_transstart(); //transmission start
error=s_write_byte(STATUS_REG_R);//send command to sensor
*p_value=s_read_byte(ACK); //read status register (8-bit)
*p_checksum=s_read_byte(noACK); //read checksum (8-bit)
return error; //error=1 in case of no response form the sensor
}
//----------------------------------------------------------------------------------
char s_write_statusreg(unsigned char *p_value)
//----------------------------------------------------------------------------------
// writes the status register with checksum (8-bit)
{
unsigned char error=0;
s_transstart(); //transmission start
error+=s_write_byte(STATUS_REG_W);//send command to sensor
error+=s_write_byte(*p_value); //send value of status register
return error; //error>=1 in case of no response form the sensor
}
//----------------------------------------------------------------------------------
char s_measure(unsigned char *p_value,unsigned char *p_checksum,unsigned char
mode)
//----------------------------------------------------------------------------------
// makes a measurement (humidity/temperature) with checksum
{
unsigned char error=0;
unsigned int i;
s_transstart(); //transmission start
switch(mode){ //send command to sensor
case TEMP :error+=s_write_byte(MEASURE_TEMP);break;
case HUMI :error+=s_write_byte(MEASURE_HUMI);break;
default :break;
}
for (i=0;i<65535;i++) if(DATA==0) break;//wait until sensor has finished the measurement
if(DATA) error+=1; // or timeout (~2 sec.) is reached
*(p_value) =s_read_byte(ACK); //read the first byte (MSB)
*(p_value+1)=s_read_byte(ACK); //read the second byte (LSB)
*p_checksum =s_read_byte(noACK); //read checksum
return error;
}
//----------------------------------------------------------------------------------
void calc_sth11(float *p_humidity ,float *p_temperature)
//----------------------------------------------------------------------------------
// calculates temperature [°C] and humidity [%RH]
// input : humi [Ticks] (12 bit)
// temp [Ticks] (14 bit)
// output: humi [%RH]
// temp [°C]
{ const float C1=-2.0468; // for 12 Bit RH
const float C2=+0.0367; // for 12 Bit RH
const float C3=-0.; // for 12 Bit RH
const float T1=+0.01; // for 12 Bit RH
const float T2=+0.00008; // for 12 Bit RH
float rh=*p_humidity; // rh: Humidity [Ticks] 12 Bit
float t=*p_temperature; // t: Temperature [Ticks] 14 Bit
float rh_lin; // rh_lin: Humidity linear
float rh_true; // rh_true:Temperature compensated humidity
float t_C; // t_C : Temperature [°C]
t_C=t*0.01 - 40.1; //calc. temperature[°C]from 14 bit temp.ticks @5V
rh_lin=C3*rh*rh + C2*rh + C1; //calc. humidity from ticks to [%RH]
rh_true=(t_C-25)*(T1+T2*rh)+rh_lin; //calc. temperature compensated humidity [%RH]
if(rh_true>100)rh_true=100; //cut if the value is outside of
if(rh_true<0.1)rh_true=0.1; //the physical possible range
*p_temperature=t_C; //return temperature [°C]
*p_humidity=rh_true; //return humidity[%RH]
}
//--------------------------------------------------------------------
float calc_dewpoint(float h,float t)
//--------------------------------------------------------------------
// calculates dew point
// input: humidity [%RH],temperature [°C]
// output: dew point [°C]
{ float k,dew_point ;
k = (log10(h)-2)/0.4343 + (17.62*t)/(243.12+t);
dew_point = 243.12*k/(17.62-k);
return dew_point;
}
//----------------------------------------------------------------------------------
void main()
//----------------------------------------------------------------------------------
// sample program that shows how to use SHT11 functions
// 1. connection reset
// 2. measure humidity [ticks](12 bit) and temperature [ticks](14 bit)
// 3. calculate humidity [%RH] and temperature [°C]
// 4. calculate dew point [°C]
// 5. print temperature,humidity,dew point
{ value humi_val,temp_val;
float dew_point;
unsigned char error,checksum;
unsigned int i;
Serial_Init();
IO_Init();
Power_Identify();
Module_Identify(3);
s_connectionreset();
while(1)
{ error=0;
error+=s_measure((unsigned char*) &humi_val.i,&checksum,HUMI); //measure humidity
error+=s_measure((unsigned char*) &temp_val.i,&checksum,TEMP); //measure temperature
if(error!=0) s_connectionreset(); //in case of an error:connection reset
else
{ humi_val.f=(float)humi_val.i; //converts integer to float
temp_val.f=(float)temp_val.i; //converts integer to float
calc_sth11(&humi_val.f,&temp_val.f); //calculate humidity,temperature
dew_point=calc_dewpoint(humi_val.f,temp_val.f);//calculate dew point
Power_Identify();
LcmDisplaySHT10(humi_val.f,temp_val.f);
//LcmPrintf("温度:%5.1f℃ 湿度:%5.1f 露点:%3.1f\n",temp_val.f,humi_val.f,dew_point); //temp :温度
// for (i=0;i<40000;i++); //延迟
// LcmPrintf("",humi_val.f); //humi:湿度
// for (i=0;i<40000;i++); //延迟
// LcmPrintf("",dew_point); //dewpoint:露点(点在此温度时,空气饱和并产生露水)
}
//----------wait approx. 0.8s to avoid heating up SHTxx-----------------------------
for (i=0;i<50000;i++);//(be sure that the compiler doesn't eliminate this line!)
//----------------------------------------------------------------------------------
}
}
Lcmdisplay.c:
#include "Lcmdisplay.h"
typedef enum {
LCMPRTF = 0, // 字符串打印
// 1 磁感应及环境光传感器模块
LCMHALL, // 霍尔接近开关
LCMREED, // 干簧管
LCMMETAL, // 金属接近开关
LCMLUX, // 环境光强度
LCMLDR, // 光敏电阻
// 2 震动及mems麦克传感器模块
LCMSHOCKDS, // 双珠单向
LCMSHOCKDD, // 双珠双向
LCMSHOCKSPRING, // 弹簧
LCMSHOCK, // 全向震动
LCMMIC, // MEMS麦克风
// 3 测距测障类及温湿度类传感器模块
LCMIR, // 红外对管测距
LCMIRSWITCH, // 红外接近开关
LCMULTR, // 超声波测距
LCMTEMP, // 温度// DS18b20
LCMSHT10, // 温湿度传感器SHT10
LCMHUMI,
展开阅读全文