wifi遥控小车的制作

时间:2021-06-01 17:11:22

第一步:装上op系统,将路由器连接上网,然后安装stty

opkg update
opkg install coreutils-stty

在CC的系统中可能安装后无法使用,可以使用BB系统,如无法下载软件可直接前往官网下载或wget网页上相关软件。

第二步:修改串口波特率

stty -F /dev/ttyAth0 raw speed 9600

第四步:页面控制

lua控制部分(文件名web2ser,放在/www/cgi-bin目录下)

#!/usr/bin/lua
io.output("/dev/ttyATH0")
c =  os.getenv("QUERY_STRING")

io.write("ZY")
io.write(c)
io.write("WV")

网页代码(放在/www/目录下)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
div#buttons{width:1200px; height:500px; float:left;}
input#forward{width: 200px; height: 200px; position: fixed; left: 500px;top: 20px}
input#left{width: 200px; height: 200px; position: fixed; left: 100px;top: 150px}
input#right{width: 200px; height: 200px; position: fixed; left: 900px;top: 150px}
input#back{width: 200px; height: 200px; position: fixed; left: 500px;top: 360px}
input#stop{width: 200px; height: 200px; position: fixed; left: 900px;top: 360px}
</style>
	<script>
	function sendSer(value){
	document.getElementById("ser").src="http://192.168.10.1/cgi-bin/web2ser?"+value;
	}
	</script>
</head>


<body>
	
<div id="container">
	<div id="buttons">
		<img id="ser" width="1" height="1" />
		<input id="forward"type="button" ontouchstart="sendSer('B')" ontouchend="sendSer('S')" value="前进" align="left" />
		<input id="left"type="button" ontouchstart="sendSer('L')" ontouchend="sendSer('S')"  value="向左" align="left" />
		<input id="right"type="button" ontouchstart="sendSer('R')" ontouchend="sendSer('S')"  value="向右" align="left" />
		<input id="back"type="button" ontouchstart="sendSer('F')" ontouchend="sendSer('S')"  value="后退"align="left" />
		<input id="stop"type="button" ontouchstart="sendSer('S')" onmousedown="sendSer('S')" value="停止" align="left" />
	</div>
</div>
</body>

</html>

修改index.html让其指向控制页面

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="refresh" content="0; URL=/car.html" />
</head>
<body style="background-color: black">
<a style="color: white; text-decoration: none" href="/car.html">LuCI - Lua Configuration Interface</a>
</body>
</html>