-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmtqq_backend.py
70 lines (50 loc) · 1.8 KB
/
mtqq_backend.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import json
import paho.mqtt.client as mqtt #import the client1
from flask import Flask
from flask_mqtt import Mqtt
from flask_socketio import SocketIO
stringToBeSent = 'aaaaaaaaaaaa'
# app = Flask(__name__)
# app.config['MQTT_BROKER_URL'] = 'test.mosquitto.org'
# app.config['MQTT_BROKER_PORT'] = 1883
# app.config['MQTT_USERNAME'] = ''
# app.config['MQTT_PASSWORD'] = ''
# app.config['MQTT_KEEPALIVE'] = 5
# app.config['MQTT_TLS_ENABLED'] = False
# app.config['MQTT_REFRESH_TIME'] = 1.0 # refresh time in seconds
# mqtt = Mqtt()
import paho.mqtt.client as mqtt #import the client1
def updateMail(gibberish):
words = gibberish.split(',')
word = ' '.join(words)
broker_address="test.mosquitto.org"
client = mqtt.Client("P1") #create new instance
client.connect(broker_address) #connect to broker
client.subscribe("home/nodered")
client.publish("home/nodered", word)
# @mqtt.on_connect()
# def handle_connect(client, userdata, flags, rc):
# mqtt.subscribe('home/nodered')
# def create_app():
# app = Flask(__name__)
# mqtt.init_app(app)
# socketio = SocketIO(app)
# # @socketio.on('publish')
# def handle_publish(json_str):
# # data = json.loads(json_str)
# # print('asdasd')
# # mqtt.publish(data['name'], data[stringToBeSent])
# mqtt.publish('home', 'hello world')
# if __name__ == '__main__':
# socketio.run(app, host='0.0.0.0', port=5000, use_reloader=False, debug=False)
# @mqtt.on_publish()
# def handle_publish(client, userdata, mid):
# mqtt.publish("home/nodered","OFF")
# if __name__ == '__main__':
# client = mqtt.Client()
#client.username_pw_set(username, password)
# client.on_connect = on_connect
# client.on_message = on_message
# client.connect('localhost')
# client.loop_start()
# app.run(host='0.0.0.0', port=5000)