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. FPS计算New

    using UnityEngine; using System.Collections; public class CarGUI : MonoBehaviour { private const flo ...

  2. 百度URL參数解析

    百度URL參数解析 在用Python爬取百度搜索的内容时,发现百度搜索的url非常的长.往往会跟一大段的參数,但事实上非常多參数都是没有必要的,如相同是搜索javakeyword,能够通过 http: ...

  3. Manual close is not allowed over a Spring managed SqlSession(转)

    最近用junit测试spring项目的时候,报错: Manual close is not allowed over a Spring managed SqlSession 意思是不允许手动关闭spr ...

  4. css定位positon

    值 描述 absolute 生成绝对定位的元素,相对于 static 定位以外的第一个父元素进行定位. 元素的位置通过 "left", "top", " ...

  5. TypeScript 映射类型

    typescript支持定义类型加入推导式后产生新的类型 属性不变 但会改变对象的使用方式 这个是类型Person中加入ReadOnly推导出的新类型 他的属性全部是只读的 这个是推导出部分属性 这是 ...

  6. 測试赛C - Eqs(哈希)

    C - Eqs Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  7. jQuery国际化插件 jQuery.i18n.properties 【轻量级】

    jQuery.i18n.properties是一款轻量级的jQuery国际化插件,能实现Web前端的国际化. 国际化英文单词为:Internationalization,又称i18n,“i”为单词的第 ...

  8. Atom打开报错:"Cannot load the system dictionary for zh-CN"

    1. 问题描述 最近每次使用atom打开文件,总是报错"Cannot load the system dictionary for zh-CN" 2. 解决方法 File --&g ...

  9. Memcache应用场景介绍,说明[zz]

    转于:http://www.cnblogs.com/literoad/archive/2012/12/23/2830178.html 面临的问题 对于高并发高访问的 Web应用程序来说,数据库存取瓶颈 ...

  10. 点滴积累【other】---Windows 7 IIS (HTTP Error 500.21 - Internal Server Error)解决方案(转载)

    此文来自:http://blog626.blog.163.com/blog/static/105610732201051591450870/ 搭建IIS时出现如下错误: HTTP Error 500. ...