【毕设_11】终端完成&数据库设计

一、终端代码
单片机程序已全部完成,本着开源的思想,虽然还未答辩,毕竟也不是什么重要的代码程序。下载链接
二、数据库设计
目前已完成获取终端信息状态,并保存到数据库中。
下面是数据表设计
| 数据表 | ||||
|---|---|---|---|---|
| 表名 | redata | |||
| 功能说明 | 保存智能开关插座状态信息 | |||
| 数据库用户 | 智能开关插座管理人员 | |||
| 主键 | id | |||
| 其他字段 | intensity, heat, light, state, opentime, closetime | |||
| 索引字段 | ||||
| 名称 | 数据类型 | 长度 | 主键 | 注释 |
| id | int | 2 | true | 主键 |
| intensity | varchar | 6 | false | 光照强度 |
| heat | int | 2 | false | 热感 1 有人 0 无人 |
| light | int | 2 | false | 亮度 1 亮 0 暗 |
| state | int | 2 | false | 开关状态 1 开 0 关 |
| opentime | time | 0 | false | 定时打开时间 |
| closetime | time | 0 | false | 定时关闭时间 |
保存数据代码程序已完成。下载链接
public class stmstart {
public static final String IP_ADDR = "192.168.2.1";//服务器地址
public static final int PORT = 8000;//服务器端口号
public static Socket s=null;
public static RecvThread rth=null;
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
s = new Socket(IP_ADDR, PORT);
rth = new RecvThread();
rth.start();
while (true);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
rth.interrupt();
try {
s.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static class RecvThread extends Thread{
@Override
public void run() {
// TODO Auto-generated method stub
while(true){
try {
InputStream in=s.getInputStream();
byte[] data=new byte[1024];
int len=in.read(data);
String res = new String(data,0,len,"GBK");
String intensity = res.substring(3, 8);
int heat = Integer.parseInt(res.substring(8, 9));
int light = Integer.parseInt(res.substring(9, 10));
int state = Integer.parseInt(res.substring(10, 11));
String opentime = res.substring(11, 13)+":"+res.substring(13, 15)+":"+res.substring(15, 17);
String closetime = res.substring(17, 19)+":"+res.substring(19, 21)+":"+res.substring(21, 23);
update(intensity,heat,light,state, opentime,closetime);
}
catch (Exception e) {
}
}
}
}
public static String byteArrayToStr(byte[] byteArray) {
if (byteArray == null) {
return null;
}
String str = null;
try {
str = new String(byteArray,"GBK");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return str;
}
public static void update(String intensity,int heat,int light,int state,String opentime,String closetime){
String sql="update redata set intensity=?,heat=?,light=?,state=?,opentime=?,closetime=? where id=1";
Connection conn = DBUtil.open();
try {
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, intensity);
pstmt.setInt(2, heat);
pstmt.setInt(3, light);
pstmt.setInt(4, state);
pstmt.setString(5, opentime);
pstmt.setString(6, closetime);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally{
DBUtil.close(conn);
}
}
}
三、B/S 控制端
UI初步已完成,待完善。
四、Server 端
响应式控制终端未实现。
今天你努力了吗
评论
0 评论