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 实现手机控制的更多相关文章

  1. 【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 ...

  2. Raspberry Pi GPIO Protection

    After damaging the GPIO port on our raspberry pi while designing a new solar monitoring system we de ...

  3. 用树莓派Raspberry Pi和Micro:bit做一个自拍器

    在这个项目中,我们将使用Python来构建一个由Micro:bit触发树莓派Raspberry Pi和相机模块的自拍器.这是开始使用硬件和简单文本编程的好方法. 我们将学习: 如何设置Raspberr ...

  4. Raspberry Pi & GPIO

    Raspberry Pi & GPIO pinout === pin out / p in out pi@raspberrypi:~ $ pinout ,------------------- ...

  5. Pi# - Raspberry Pi GPIO Library for .NET

    Project Description Pi# (pronounced “Pi Sharp”) is a library to expose the GPIO functionality of the ...

  6. (RaspBerry Pi) Python GPIO 基本操作

    目前打算由潛入深慢慢學習RaspBerry Pi, 所以先由最容易下手的Python進入樹莓派的世界 首先要使用 GPIO 需要利用RPI.GPIO package想當然爾必須先安裝 所以先執行下列命 ...

  7. 在 树莓派(Raspberry PI) 中使用 Docker 运行 MySQL

    在 树莓派(Raspberry PI) 中使用 Docker 运行 MySQL 本文主要利用 biarms 提供的 Dockerfile 进行安装. 笔者最新发现! MySQL 5.7 Docker ...

  8. 树莓派 Raspberry PI之GPIO

    树莓派 Raspberry PI之GPIO 树莓派各版本硬件原理图:https://www.raspberrypi.org/documentation/hardware/raspberrypi/REA ...

  9. 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 ...

随机推荐

  1. 在UNC(通用命名规范)路径和URL中使用IPv6地址

    转自:http://www.ipv6bbs.cn/thread-348-1-1.html   虽然微软在支持IPv6上表现得很积极,但Windows却并没有完整地支持IPv6,例如,在Windows中 ...

  2. git 的简单用法

    在服务器上建立空白库 ssh 70.0.0.236 mkdir /home/git/[proj_dir] cd /home/git/[proj_dir] git --bare init 将本地代码推送 ...

  3. 织梦程序中plus文件作用介绍及安全设置

    官方网站下载了Dedecms安装包以后,解压出来,有一个uploads文件,这里面的文件夹才是网站的安装文件,里面文件很多,今天无忧小编就主要介绍下plus文件夹里面的各个功能模块,如果你只是做一个宣 ...

  4. 带有key参数的函数filter,map,max,min

    内置函数———filter def is_not_empty(s): return s and len(s.strip()) > 0 filter(is_not_empty, ['test', ...

  5. .net core 控制台程序使用依赖注入(Autofac)

    1.Autofac IOC 容器 ,便于在其他类获取注入的对象 using System; using System.Collections.Generic; using System.Linq; u ...

  6. js 时间戳

    https://www.cnblogs.com/crf-Aaron/archive/2017/11/16/7844462.html var time = '2018-03-22 00:00:00'.r ...

  7. unity, Global和Local编辑模式

    下图表示是在Local模式下: 下图表示是在Global模式下: 不要搞反.

  8. Unity向量投影使用

    官方例图 测试: code: public Transform point1; public Transform point2; public Transform humanPoint; public ...

  9. vivado设计三:一步一步生成自己的自定义IP核

    开发环境:xp  vivado2013.4 基于AXI-Lite的用户自定义IP核设计 这里以用户自定义led_ip为例: 1.建立工程 和设计一过程一样,见vivado设计一http://blog. ...

  10. HTTP 用户认证

    HTTP 常见的用户认证可以分为下面三种: 基于IP,子网的访问控制(ACL) 基本用户验证(Basic Authentication) 消息摘要式身份验证(Digest Authentication ...