【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 ...
随机推荐
- vs2012升级到vs2013后,sql server 无法通过IP登录解决方案
因项目需要,vs升级到2013,可是数据库通过IP却无法连接,一直报内存异常,困扰许久,原来是.net框架出了问题,可以通过用管理员身份运行:netsh winsock reset解决!
- background-position 之剑走偏锋
转自:http://www.cnblogs.com/yizuierguo/archive/2009/03/10/1407860.html 在设置background-image属性时,经常会遇到一个b ...
- Mysql中的排序规则utf8_unicode_ci、utf8_general_ci的区别
utf8_unicode_ci和utf8_general_ci对中.英文来说没有实质的差别.utf8_general_ci 校对速度快,但准确度稍差.utf8_unicode_ci 准确度高,但校对速 ...
- <转>得到其它进程的命令行
#include <windows.h> #include <stdio.h> #define ProcessBasicInformation 0 typedef struct ...
- php 删除文件夹下的所有文件
$patch = dirname(__FILE__).'/Cookie/';//获取文件目录 $files = scandir($patch); foreach ($files as $filenam ...
- FreeSWITCH技巧:如何向通话的另一方号码发送dtmf?
注:这里的文章都是本人的日常总结,请尊重下个人的劳动成果,转载的童鞋请注明出处,谢谢. 如您转载的文章发生格式错乱等问题而影响阅读,可与本人联系,无偿提供本文的markdown源代码. 联系邮箱:ji ...
- unity, trail renderer gone black on iOS
给物体加了个trail renderer,使用了Legacy Shaders/Transparent/Diffuse,并将颜色调成白色半透明.在编辑器里效果是对的,但在ios上真机测试变成黑色的.然后 ...
- C语言第十一回合:预处理命令的集中营
C语言第十一回合:预处理命令的集中营 [学习目标] 1. 宏定义 2. 文件包括"处理 3. 条件编译 预处理命令:能够改进程序设计的 ...
- update-alternatives
转自: http://lingavin.com/blog/2013/03/07/alternatives-gcc/ Ubuntu-gcc版本切换 MAR 7TH, 2013 随着ubuntu版本的更新 ...
- builtroot make menuconfig流程
本文主要介绍一下,buildroot(buildroot-2018.02.1)的make menuconfig.众所周知,在我们执行menuconfig时,会生成一个图形化界面,然后进行相关的配置.同 ...