-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e2fc7a3
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from django.shortcuts import render, redirect | ||
from django.http import HttpResponse, JsonResponse | ||
import paho.mqtt.client as mqtt | ||
import manage_system.gloabl_var as global_var | ||
|
||
|
||
mqttBroker = "mqtt.eclipseprojects.io" | ||
|
||
|
||
def index(request): | ||
# if request.session.get('is_login', None) is None: | ||
# return HttpResponse("尚未登录") | ||
return render(request, 'index.html') | ||
|
||
|
||
def publishMsg(request): | ||
if request.method == 'POST': | ||
control_msg = request.POST.get('publish_msg', None) | ||
print('control_msg: ', control_msg) | ||
if control_msg: | ||
client = mqtt.Client("Temperature_Inside") | ||
client.connect(mqttBroker) | ||
client.publish("control_msg", control_msg) | ||
|
||
# return redirect('/index/') | ||
return JsonResponse({"msg": "success"}) | ||
|
||
|
||
def get_info(request): | ||
return JsonResponse({"msg": global_var.get_value("msg")}) |