forked from nongkrek/Riset-IoT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hasil Kerja Iqbal 3 September 2019
52 lines (45 loc) · 1.3 KB
/
Hasil Kerja Iqbal 3 September 2019
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
import stomp
import os
import time
import mysql.connector
#global msgs
class MyListener(object):
def on_error(self,headers, msg1):
global vartest1
vartest1=msg1
print('received an error "%s"' % vartest1)
def on_message(self, headers, msg1):
# print('received a message "%s"' % message)
global vartest1
vartest1=msg1
#vartest2=msg2
print('message "%s"' % vartest1)
#print('message "%s"' % vartest2)
#msgs=[(var1,var2)]
"""mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="123456",
database="db_mikon"
)
mycursor = mydb.cursor()
# Insert data
sql = "INSERT INTO arduinotest (hum,temp) VALUES (%s, %s)"
val = [(var1,var2)]
#Update data
#sql = "UPDATE arduino1 SET ultra = %s WHERE temp = %s"
#val = ("10 ultra", "10 derajat")
mycursor.execute(sql,val)
mydb.commit()"""
"""msgtest=""
headerstest=""
uac = MyListener()
uac.on_message(headerstest,msgtest)"""
conn = stomp.Connection([('127.0.0.1', 61613)])
conn.set_listener('', MyListener())
conn.start()
conn.connect('admin', '123456', wait=True)
conn.subscribe(destination='/queue/ms02.hum', id=1, ack='auto')
conn.subscribe(destination='/queue/ms02.temp', id=2, ack='auto')
time.sleep(1)
conn.disconnect()