from flask import Flask, render_template, request, session, redirect
from flask_mqtt import Mqtt
import numpy as np
import json
import re
from utils import query
from utils import getData
app = Flask(__name__)
app.secret_key = 'nongpi'
app.config['MQTT_BROKER_URL'] = '101.43.164.154'
app.config['MQTT_BROKER_PORT'] = 1883
app.config['MQTT_USERNAME'] = 'admin' # 当你需要验证用户名和密码时,请设置该项
app.config['MQTT_PASSWORD'] = 'zhangxinke233' # 当你需要验证用户名和密码时,请设置该项
app.config['MQTT_KEEPALIVE'] = 5 # 设置心跳时间,单位为秒
app.config['MQTT_CLIENT_ID'] = 'something'
topic = 'test'
mqtt_client = Mqtt(app)
@mqtt_client.on_connect()
def handle_connect(client, userdata, flags, rc):
if rc == 0:
print('Connected successfully')
mqtt_client.subscribe(topic)
else:
print('Bad connection. Code:', rc)
@mqtt_client.on_message()
def handle_mqtt_message(client, userdata, message):
print("client: ", client)
jsondata = json.loads(message.payload)
print("msg payload", jsondata)
query.sqlsave(jsondata)
@app.route('/')
def all_request():
return redirect('/login')
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'GET':
return render_template('login.html')
elif request.method == 'POST':
request.form = dict(request.form)
def filter_fn(item):
return request.form['email'] in item and request.form['password'] in item
users = query.querys('select * from user', [], 'select')
filter_user = list(filter(filter_fn, users))
if len(filter_user):
session['email'] = request.form['email']
return redirect('/home')
else:
return render_template('error.html', message='邮箱或密码错误')
@app.route('/loginOut')
def login_out():
session.clear()
return redirect('/login')
@app.route('/register', methods=['GET', 'POST'])
def register():
if request.method == 'GET':
return render_template('register.html')
elif request.method == 'POST':
request.form = dict(request.form)
print(request.form)
if request.form['password'] != request.form['passwordChecked']:
return render_template("error.html", message="两次密码不匹配")
def filter_fn(item):
return request.form['email'] in item
users = query.querys('select * from user', [], 'select')
filter_list = list(filter(filter_fn, users))
if len(filter_list):
return render_template('error.html', message='该用户已被注册')
else:
query.querys('insert into user(email,password) values(%s,%s)',
[request.form['email'], request.form['password']])
return redirect('/login')
@app.route('/home', methods=['GET', 'POST'])
def home():
email = session.get('email')
df = query.read_sql()
device_num, device_data = getData.get_device_data(df)
return render_template(
'index.html',
email=email,
devicenum=device_num,
device_id=device_data.tolist(),
)
@app.route('/system_chart_refresh', methods=['GET', 'POST'])
def system_chart_refresh():
df = query.read_sql()
device_num, device_data = getData.get_device_data(df)
timenow = query.gettime()
num = getData.get_alarm_num(df)
return [[timenow, device_num],
[timenow, device_num*8],
[timenow, int(num)]]
@app.route('/tables', methods=['GET', 'POST'])
def tables():
email = session.get('email')
df = query.read_sql()
device_num, device_data = getData.get_device_data(df)
return render_template(
'tables.html',
email=email,
devicenum=device_num,
device_id=device_data.tolist(),
sqldata=df,
)
@app.route('/table_refresh')
def table_refresh():
df = query.read_sql()
X = np.array(df).tolist()
# print(df)
return X
@app.route('/date')
def get_date():
return getData.get_date()
@app.route('/time')
def get_time():
return getData.get_time()
@app.route('/device')
def get_device():
df = query.read_sql()
device_num, device_data = getData.get_device_data(df)
return str(device_num)
@app.route('/alarm')
def get_alarm():
df = query.read_sql()
num = getData.get_alarm_num(df)
return str(num)
@app.route('/device_card_refresh')
def device_card_refresh():
df = query.read_sql()
device_num, device_data = getData.get_device_data(df)
return [device_num, device_data.tolist()]
@app.route('/devicepage/<int:deviceid>')
def devicepage(deviceid, methods=['GET', 'POST']):
email = session.get('email')
df = query.read_sql()
device_num, device_data = getData.get_device_data(df)
return render_template(
'devicepage.html',
email=email,
deviceid=deviceid,
devicenum=device_num,
device_id=device_data.tolist(),
)
@app.route('/device_chart_refresh/<string:id>')
def device_chart_refresh(id):
df = query.read_sql()
df = getData.alive(df)
df = df[df['id'] == id]
na = np.array(df).tolist()
k = []
for i in range(2, 10):
p = []
for j in na:
p = p + [[j[0], j[i]]]
k = k + [p]
return k
@app.route('/alarm_svg_refresh/<string:id>')
def alarm_svg_refresh(id):
df = query.read_sql()
df = getData.get_alarm(df)
return np.array(df.loc[df['id'] == id]).tolist()[0]
@app.before_request
def before_requre():
pat = re.compile(r'^/static')
if re.search(pat, request.path):
return
if request.path == "/login":
return
if request.path == '/register':
return
email = session.get('email')
if email:
return None
return redirect('/login')
if __name__ == '__main__':
app.run(host='0.0.0.0')
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于Web和物联网技术的远程分布式智慧农业环境监测系统源码(高分项目).zip个人经导师指导并认可通过的98分大作业设计项目,主要针对计算机相关专业的正在做课程设计、期末大作业的学生和需要项目实战练习的学习者。 基于Web和物联网技术的远程分布式智慧农业环境监测系统源码(高分项目).zip基于Web和物联网技术的远程分布式智慧农业环境监测系统源码(高分项目).zip基于Web和物联网技术的远程分布式智慧农业环境监测系统源码(高分项目).zip基于Web和物联网技术的远程分布式智慧农业环境监测系统源码(高分项目).zip基于Web和物联网技术的远程分布式智慧农业环境监测系统源码(高分项目).zip基于Web和物联网技术的远程分布式智慧农业环境监测系统源码(高分项目).zip基于Web和物联网技术的远程分布式智慧农业环境监测系统源码(高分项目).zip基于Web和物联网技术的远程分布式智慧农业环境监测系统源码(高分项目).zip基于Web和物联网技术的远程分布式智慧农业环境监测系统源码(高分项目).zip基于Web和物联网技术的远程分布式智慧农业环境监测系统源码(高分项目).zip
资源推荐
资源详情
资源评论
收起资源包目录
基于Web和物联网技术的远程分布式智慧农业环境监测系统源码(高分项目).zip (1643个子文件)
sb-admin-2.css 199KB
sb-admin-2.min.css 161KB
all.css 68KB
fontawesome.css 67KB
all.min.css 55KB
fontawesome.min.css 54KB
v4-shims.css 40KB
v4-shims.min.css 26KB
svg-with-js.css 8KB
svg-with-js.min.css 6KB
dataTables.bootstrap4.css 6KB
dataTables.bootstrap4.min.css 5KB
regular.css 733B
solid.css 726B
brands.css 714B
regular.min.css 676B
solid.min.css 668B
brands.min.css 661B
fa-solid-900.eot 188KB
fa-brands-400.eot 127KB
fa-regular-400.eot 34KB
.gitignore 198B
devicepage.html 36KB
index.html 18KB
tables.html 16KB
login.html 3KB
register.html 3KB
error.html 211B
flaskProject.iml 715B
loginimg.jpg 1.53MB
registerimg.jpg 653KB
echarts.js 2.24MB
all.js 1.14MB
all.min.js 1.08MB
solid.js 570KB
solid.min.js 557KB
jquery.dataTables.js 437KB
brands.js 418KB
brands.min.js 411KB
jquery.js 274KB
jquery.slim.js 222KB
bootstrap.bundle.js 218KB
bootstrap.js 129KB
regular.js 105KB
regular.min.js 101KB
jquery-1.12.4.min.js 95KB
jquery.min.js 86KB
jquery.dataTables.min.js 80KB
bootstrap.bundle.min.js 77KB
fontawesome.js 76KB
jquery.slim.min.js 69KB
bootstrap.min.js 57KB
fontawesome.min.js 36KB
conflict-detection.js 33KB
v4-shims.js 17KB
v4-shims.min.js 15KB
conflict-detection.min.js 13KB
dataTables.bootstrap4.js 5KB
jquery.easing.js 4KB
chart-area-demo.js 3KB
chart-bar-demo.js 3KB
jquery.easing.min.js 2KB
dataTables.bootstrap4.min.js 2KB
jquery.easing.compatibility.js 2KB
sb-admin-2.js 1KB
sb-admin-2.min.js 1KB
chart-pie-demo.js 1KB
datatables-demo.js 103B
bootstrap.bundle.js.map 393KB
bootstrap.bundle.min.js.map 305KB
bootstrap.js.map 245KB
bootstrap.min.js.map 186KB
jquery.min.map 133KB
jquery.slim.min.map 106KB
app.py 6KB
mqtt_receive.py 2KB
getData.py 2KB
query.py 1KB
app.cpython-38.pyc 6KB
mqtt_receive.cpython-38.pyc 2KB
getData.cpython-38.pyc 2KB
query.cpython-38.pyc 2KB
fa-solid-900.svg 820KB
fa-brands-400.svg 675KB
solid.svg 602KB
brands.svg 431KB
fa-regular-400.svg 141KB
regular.svg 107KB
old-republic.svg 11KB
wizards-of-the-coast.svg 8KB
critical-role.svg 7KB
the-red-yeti.svg 6KB
mandalorian.svg 6KB
grunt.svg 5KB
reacteurope.svg 5KB
optin-monster.svg 5KB
d-and-d.svg 4KB
jenkins.svg 4KB
salesforce.svg 4KB
d-and-d-beyond.svg 4KB
共 1643 条
- 1
- 2
- 3
- 4
- 5
- 6
- 17
资源评论
程序员张小妍
- 粉丝: 1w+
- 资源: 3474
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功