【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 ...
随机推荐
- 【转】maven常见问题问答
转自:http://www.iteye.com/topic/973166 前言 Maven,发音是[`meivin],"专家"的意思.它是一个很好的项目管理工具,很早就进入了我的必 ...
- Android 文件存储 和 权限管理
转载请标明出处: :http://blog.csdn.net/huaiyiheyuan/article/details/52473984 android SD卡主要有两种存储方式 Internal . ...
- 【小程序】微信小程序开发—弹出框
1. <span style="font-family:Comic Sans MS;font-size:18px;color:#333333;"><view cl ...
- c# webbrowser 清除cookie和缓存
由于缓存文件是特殊的文件,以及WebBrowser与IE版本有关因此删除缓存绝对不可能用一些IO函数就总可以解决的因此我的这些函数在IO操作的基础上,又针对环境进行相应的清理. static clas ...
- vs2017安装过程问题及解决方法
1. 问题:C++ 无法打开 源 文件 "errno.h"等文件 解决方法:https://jingyan.baidu.com/article/8ebacdf0167b2249f6 ...
- LaTex的注释
在LaTex中的注释有以下3种 1.注释一行:使用%注释一行文字, 在%后的文字都不予编译: 2.注释一段:使用\iffalse .... \fi 包含一段文字,被包含的文字被注释掉了: 3.注释一段 ...
- 阿里云视频服务SDK
原文地址:https://help.aliyun.com/document_detail/51992.html?spm=5176.doc52200.6.668.Sn3AjC SDK下载 更新时间:20 ...
- 【转】C# 视频监控系列(12):H264播放器——播放录像文件
原文地址:http://www.cnblogs.com/over140/archive/2009/03/23/1419643.html?spm=5176.100239.blogcont51182.16 ...
- ajax 参数data问题 data中的 参数名 参数值为string 提交到后台后,会自动转换参数名相同的 类型 和 js字符串拼接
latlng"14.6005238,100.43635419999998"Cusid"accb5c1b-6aef-4f3b-a4eb-d60ea1ca5f54" ...
- 利用python进行泰坦尼克生存预测——数据探索分析
最近一直断断续续的做这个泰坦尼克生存预测模型的练习,这个kaggle的竞赛题,网上有很多人都分享过,而且都很成熟,也有些写的非常详细,我主要是在牛人们的基础上,按照数据挖掘流程梳理思路,然后通过练习每 ...