【Raspberry Pi】webpy+mysql+GPIO 实现手机控制
1、mysql
http://dev.mysql.com/doc/refman/5.5/en/index.html
安装
sudo apt-get install update
sudo apt-get install mysql-server-5.5 mysql-client-5.5
2、安装web.py
sudo apt-get install python-pip
sudo pip install web.py
html模板
$def with(todos)
$if todos=='me':
<html>
<body>
<h1>My test</h1>
<p>Hello World</p>
<hr />
<form name='input' action="www.baidu.com" method="get">
<input type="text" name="user">
<input type="submit" value="sub_mit">
</form>
</body>
</html>
$else:
<html>
<body>
<ul heigh="">
$for word in todos:
<li id="$word.id">$word.title</li>
</ul>
<hr />
<form method="post" action="add">
<input type="text" name="title"/>
<input type="submit" value="Add" />
</form>
<hr />
<h1>control LED</h1>
<form method="post" action="led">
<input type="radio" name='open_close' value="1" /> OPEN LED
<br />
<br />
<br />
<input type="radio" name='open_close' value="0" /> CLOSE LED
<br />
<br />
<br />
<input type="submit" value="submit" />
</form>
</body>
</html>
主程序
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 25 03:08:25 2014 @author: pi
""" import web
import RPi.GPIO as gpio gpio.setwarnings(False)
gpio.setmode(gpio.BOARD)
gpio.setup(7,gpio.OUT)
gpio.setup(11,gpio.OUT) gpio.output(7,gpio.HIGH)
gpio.output(11,gpio.HIGH) render=web.template.render('templates/') urls = (
'/','index',
'/add','add',
'/led','led'
) app = web.application(urls,globals()) db=web.database(dbn='mysql',user='root',pw='******',db='myweb') class index:
def GET(self):
todos=db.select('todo')
return render.index(todos) class add:
def POST(self):
i=web.input()
if i.title=='open':
gpio.output(7,gpio.LOW)
elif i.title=="close":
gpio.output(7,gpio.HIGH) db.insert('todo',title=i.title)
raise web.seeother('/') class led:
def POST(self):
i=web.input()
if i.open_close=="":
gpio.output(11,gpio.LOW)
if i.open_close=="":
gpio.output(11,gpio.HIGH)
raise web.seeother("/") if __name__=="__main__":
app.run()
【Raspberry Pi】webpy+mysql+GPIO 实现手机控制的更多相关文章
- 【Raspberry pi+python+mysql】红外传感器-发邮件-存数据库
1.mysql http://dev.mysql.com/doc/refman/5.5/en/tutorial.html mysql+python http://dev.mysql.com/doc/c ...
- Raspberry Pi GPIO Protection
After damaging the GPIO port on our raspberry pi while designing a new solar monitoring system we de ...
- 用树莓派Raspberry Pi和Micro:bit做一个自拍器
在这个项目中,我们将使用Python来构建一个由Micro:bit触发树莓派Raspberry Pi和相机模块的自拍器.这是开始使用硬件和简单文本编程的好方法. 我们将学习: 如何设置Raspberr ...
- Raspberry Pi & GPIO
Raspberry Pi & GPIO pinout === pin out / p in out pi@raspberrypi:~ $ pinout ,------------------- ...
- Pi# - Raspberry Pi GPIO Library for .NET
Project Description Pi# (pronounced “Pi Sharp”) is a library to expose the GPIO functionality of the ...
- (RaspBerry Pi) Python GPIO 基本操作
目前打算由潛入深慢慢學習RaspBerry Pi, 所以先由最容易下手的Python進入樹莓派的世界 首先要使用 GPIO 需要利用RPI.GPIO package想當然爾必須先安裝 所以先執行下列命 ...
- 在 树莓派(Raspberry PI) 中使用 Docker 运行 MySQL
在 树莓派(Raspberry PI) 中使用 Docker 运行 MySQL 本文主要利用 biarms 提供的 Dockerfile 进行安装. 笔者最新发现! MySQL 5.7 Docker ...
- 树莓派 Raspberry PI之GPIO
树莓派 Raspberry PI之GPIO 树莓派各版本硬件原理图:https://www.raspberrypi.org/documentation/hardware/raspberrypi/REA ...
- How To Install Linux & Nginx & MySQL & PHP (LEMP) stack on Raspberry Pi 3,Raspberry Pi 3,LEMP,Nginx,PHP, LEMP (not LNMP)
1. How To Install Linux & Nginx & MySQL & PHP (LEMP) stack on Raspberry Pi 3 R ...
随机推荐
- vue - utils.js
exports:导出功能函数或变量 module.exports:默认导出{} ------------------------------------------------------------ ...
- Android app启动耗时分析
前言 app启动耗时过长的话,无论你的app里面的内容多么丰富有趣,作为一个用户,首先是没有耐心去等待的,如果我是一个用户,我会这样想:这是什么垃圾公司出的什么烂app,再等2s不进来就卸载,黑人问号 ...
- 关于comet
Comet是彗星的意思,这一技术之所以借用这个名字,是因为这里的每一次请求都有一个长长的“尾巴”.这个长尾巴就是我们感兴趣的长连接. 因为长连接的实现,Comet可以不需要安装浏览器插件就可以向客户端 ...
- Android版俄罗斯方块的实现
学习Android的基本开发也有一段时间了,可是由于没有常常使用Android渐渐的也就忘记了. Android编程学的不深,不过为了对付逆向,可是有时还是会感到力不从心的.毕竟不是一个计算机专业毕业 ...
- centOS7 安装redis-3.2.6
0.下载tar.gz包并解压到某个位置,然后cd进入解压后的目录(redis-3.2.6)下 1.安装 make MALLOC=libc 关于为什么这样做,参考redis-3.2.6目录下的READM ...
- 基于Python-Flask实现的网站例子
概述 使用Flask写的体育网站 包括(注册 论坛 文章评论 组建战队 后台管理)等功能 示例地址文中有写 萌新 请多指教 详细 代码下载:http://www.demodashi.com/demo/ ...
- 深入浅出REST架构 REST架构概述
http://www.nowamagic.net/librarys/veda/detail/885何为REST? REST是英文Representational State Transfer的缩写,中 ...
- IDEA启动服务慢的问题处理
问题描述: 微服务模式下统一启动服务,很慢如下图: 这种情况是IDEA工作环境有问题. 解决方法: 从SVN或者Git重新检出项目,即可解决.
- 关于JSP和HTML
工作中,发现非常多同事不清楚JSP与HTML的生命周期.以至于出现"JavaScript为啥不能调用JSTL标签(或EL表达式)?"的笑话问题. 以下以流程图的方式.简单说明一下过 ...
- Linux - 进程控制 代码(C)
进程控制 代码(C) 本文地址:http://blog.csdn.net/caroline_wendy 输出进程ID.getpid(). 代码: /*By C.L.Wang * Eclipse CDT ...