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
#-*- coding: UTF-8 -*-
import RFM69_POCSAG
from RFM69_POCSAGregisters import *
import datetime
from threading import Timer
import time
from ConfigParser import SafeConfigParser
import pika
import os
import json
config = SafeConfigParser()
config.read('config.ini')
config.add_section('main')
config.set('main', 'amqpURI', 'amqp://user:pw@host:port')
with open('config.ini', 'w') as f:
if not config.has_section('main'):
config.add_section('main')
config.set('main', 'amqpURI', 'amqp://user:pw@host:port')
try:
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.shutdown()
@ -28,23 +34,78 @@ rfmModule.setFreqeuncy(freqHz)
rfmModule.rcCalibration()
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):
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:
try:
connection = pika.BlockingConnection(pika.ConnectionParameters( config.get('main', 'amqpURI') ))
print(' [*] Connecting')
connection = pika.BlockingConnection(pika.URLParameters( config.get('main', 'amqpURI') ))
channel = connection.channel()
queue = channel.queue_declare(queue='input')
queue_ttl60 = channel.queue_declare(queue='input_ttl60')
queue = channel.queue_declare(queue='input', durable=True)
queue_ttl60 = channel.queue_declare(queue='input_ttl60', durable=True, arguments={ "x-message-ttl": 60000 })
channel.basic_consume(queue='input',
auto_ack=True,
on_message_callback=msgCallback)
@ -53,22 +114,24 @@ while True:
on_message_callback=msgCallback)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
except KeyboardInterrupt:
break
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:
time.sleep(.5)
pass
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, "133742", '1234567890^12w3e4rt5zu<yxcvf1qwerdftgzhj123we4rwt5dezghqwertwe6456e5n6er6n45w6n456n45'])
msgs.append([True, "133782", "1234567890U-()"])
"""
msgs.append([False, "133702", my_random_string(80)])
#msgs.append([False, "133702", my_random_string(80)])
data = encodeTXBatch(msgs)
rfmModule.sendBuffer(data)
time.sleep(2000)
#time.sleep(2000)
#rfmModule.shutdown()

@ -24,7 +24,7 @@ BATCH_SIZE = 16
#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
#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
#one for a data word

Loading…
Cancel
Save