-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserialpythonpublischer.py
More file actions
40 lines (33 loc) · 1.35 KB
/
serialpythonpublischer.py
File metadata and controls
40 lines (33 loc) · 1.35 KB
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
import serial
import time
import pika
import sys
ser = serial.Serial(port='/dev/ttyAMA0',baudrate=115200,timeout=0.2)
#ser.write("100")
#ser.open()
try:
credentials = pika.PlainCredentials('admin', 'pass')
parameters = pika.ConnectionParameters('localhost',5672,'shost',credentials)
connection = pika.BlockingConnection(parameters)
channel= connection.channel()
while 1:
if (ser.inWaiting() > 0):
response = ser.readline(None)
ser.flushInput() ##flush input after reading
#ser.flushOutput()
response=response.strip()
if response :
#channel.exchange_declare(exchange='node2',type='topic',durable='true', arguments={"arg1":"test"})
channel.exchange_declare(exchange='node2',type='topic')
message= response
channel.basic_publish(exchange='node2',routing_key='',body=message)
#channel.basic_publish(exchange='node1',routing_key='light',body=message)
#channel.queue_declare(queue='temperature',exclusive='true')
#channel.queue_declare(queue='light',exclusive='true')
#channel.queue_bind(exchange='node1',queue='temperature',routing_key='temperature')
#channel.queue_bind(exchange='node1',queue='light',routing_key='light')
print " [x] Sent %r" % (message,)
connection.close()
#print time.ctime(time.time())
except KeyboardInterrupt:
ser.close()