first release fo the working code

master
Cuddly Cheetah 5 years ago
parent 18aad8a5ba
commit ea8947757c

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

@ -1,20 +1,26 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
#-*- coding: UTF-8 -*-
import RFM69_POCSAG import RFM69_POCSAG
from RFM69_POCSAGregisters import * from RFM69_POCSAGregisters import *
import datetime import datetime
from threading import Timer
import time import time
from ConfigParser import SafeConfigParser from ConfigParser import SafeConfigParser
import pika import pika
import os
import json
config = SafeConfigParser() config = SafeConfigParser()
config.read('config.ini') config.read('config.ini')
config.add_section('main') if not config.has_section('main'):
config.set('main', 'amqpURI', 'amqp://user:pw@host:port') config.add_section('main')
config.set('main', 'amqpURI', 'amqp://user:pw@host:port')
with open('config.ini', 'w') as f: try:
config.write(f) with open('config.ini', 'w') as f:
config.write(f)
except Exception:
pass
rfmModule = RFM69_POCSAG.RFM69_POCSAG(RF69_433MHZ, pocsagBaudRate=1200, isRFM69HW = True) rfmModule = RFM69_POCSAG.RFM69_POCSAG(RF69_433MHZ, pocsagBaudRate=1200, isRFM69HW = True)
#rfmModule.shutdown() #rfmModule.shutdown()
@ -28,47 +34,104 @@ rfmModule.setFreqeuncy(freqHz)
rfmModule.rcCalibration() rfmModule.rcCalibration()
rfmModule.setHighPower(True) rfmModule.setHighPower(True)
import uuid
def my_random_string(string_length=10):
"""Returns a random string of length string_length."""
random = str(uuid.uuid4())+str(uuid.uuid4())+str(uuid.uuid4())+str(uuid.uuid4())+str(uuid.uuid4())+str(uuid.uuid4())+str(uuid.uuid4())+str(uuid.uuid4()) # Convert UUID format to a Python string.
random = random.upper() # Make all characters uppercase.
random = random.replace("-","") # Remove the UUID '-'.
return random[0:string_length] # Return the random string.
os.system("echo heartbeat | sudo tee /sys/class/leds/led0/trigger")
def byteify(input):
if isinstance(input, dict):
return {byteify(key): byteify(value)
for key, value in input.iteritems()}
elif isinstance(input, list):
return [byteify(element) for element in input]
elif isinstance(input, unicode):
return input.encode('utf-8')
else:
return input
from pocsag import encodeTXBatch
inputQueue = []
txQueue = []
def batchFinal():
global t
global inputQueue
global txQueue
#print(" [x] Batch Final")
txQueue = inputQueue
inputQueue = []
#print(txQueue)
if len(txQueue) > 0:
os.system("echo timer | sudo tee /sys/class/leds/led0/trigger")
data = encodeTXBatch(txQueue, repeatNum=2)
rfmModule.sendBuffer(data)
os.system("echo heartbeat | sudo tee /sys/class/leds/led0/trigger")
resetTimer()
t = Timer(.5, batchFinal)
t.start()
def resetTimer():
global t
if t.is_alive():
t.cancel()
t = Timer(.5, batchFinal)
t.start()
def msgCallback(ch, method, properties, body): def msgCallback(ch, method, properties, body):
print(" [x] Received %r" % body) global inputQueue
msg = byteify(json.loads(body))
print(msg)
address = '13370' + msg[0]
message = msg[1]
""".encode('ascii', 'ignore')
message = message.replace("Ä", '[')
message = message.replace("Ü", '[')
message = message.replace("Ö", '\\')
message = message.replace("ä", '{')
message = message.replace("ö", '|')
message = message.replace("ü", '}')
message = message.replace("ß", '~')
message = str(message.encode('ascii', 'ignore'))
#message = message.replace(/(\r\n|\n|\r)/gm, '')
"""
print(" [x] Received", address, message)
inputQueue.append([False, address, message])
#resetting timer
resetTimer()
while True: while True:
try: try:
connection = pika.BlockingConnection(pika.ConnectionParameters( config.get('main', 'amqpURI') )) print(' [*] Connecting')
channel = connection.channel() connection = pika.BlockingConnection(pika.URLParameters( config.get('main', 'amqpURI') ))
queue = channel.queue_declare(queue='input') channel = connection.channel()
queue_ttl60 = channel.queue_declare(queue='input_ttl60') queue = channel.queue_declare(queue='input', durable=True)
channel.basic_consume(queue='input', queue_ttl60 = channel.queue_declare(queue='input_ttl60', durable=True, arguments={ "x-message-ttl": 60000 })
auto_ack=True, channel.basic_consume(queue='input',
on_message_callback=msgCallback) auto_ack=True,
channel.basic_consume(queue='input_ttl60', on_message_callback=msgCallback)
auto_ack=True, channel.basic_consume(queue='input_ttl60',
on_message_callback=msgCallback) auto_ack=True,
print(' [*] Waiting for messages. To exit press CTRL+C') on_message_callback=msgCallback)
channel.start_consuming() print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
except Exception: except KeyboardInterrupt:
time.sleep(.5) break
pass except pika.exceptions.ConnectionClosed:
print 'oops. lost connection. trying to reconnect.'
# avoid rapid reconnection on longer RMQ server outage
time.sleep(0.5)
except Exception:
print 'oops. fail.'
# avoid rapid reconnection on longer RMQ server outage
time.sleep(0.5)
from pocsag import encodeTXBatch
msgs = []
""" """
msgs = []
msgs.append([False, "133722", 'Zeile 1\nZeile 2\nZeile 3\nZeile 4']) msgs.append([False, "133722", 'Zeile 1\nZeile 2\nZeile 3\nZeile 4'])
msgs.append([False, "133742", '1234567890^12w3e4rt5zu<yxcvf1qwerdftgzhj123we4rwt5dezghqwertwe6456e5n6er6n45w6n456n45']) msgs.append([False, "133742", '1234567890^12w3e4rt5zu<yxcvf1qwerdftgzhj123we4rwt5dezghqwertwe6456e5n6er6n45w6n456n45'])
msgs.append([True, "133782", "1234567890U-()"]) msgs.append([True, "133782", "1234567890U-()"])
""" """
msgs.append([False, "133702", my_random_string(80)]) #msgs.append([False, "133702", my_random_string(80)])
data = encodeTXBatch(msgs) #time.sleep(2000)
rfmModule.sendBuffer(data) #rfmModule.shutdown()
time.sleep(2000)
#rfmModule.shutdown()

@ -24,7 +24,7 @@ BATCH_SIZE = 16
#The preamble comes before a message, is a series of alternating #The preamble comes before a message, is a series of alternating
#1,0,1,0... bits, at least 576 bits. It exists to allow the receiver #1,0,1,0... bits, at least 576 bits. It exists to allow the receiver
#to synchronize with the transmitter #to synchronize with the transmitter
PREAMBLE_LENGTH = 576 PREAMBLE_LENGTH = 576*3
#These bits appear as the first bit of a word, for an address word and #These bits appear as the first bit of a word, for an address word and
#one for a data word #one for a data word

Loading…
Cancel
Save