예제 #1
0
파일: fs20tx.py 프로젝트: RichiH/RaspyRFM
#!/usr/bin/env python2.7

from rfm69 import Rfm69
import rfm69
import sensors
import sys
import time

rfm = Rfm69()  #when using a single single 868 MHz RaspyRFM
#rfm = Rfm69(1, 24) #when using the RaspyRFM twin
rfm.SetParams(Freq=868.350,
              Datarate=5.0,
              TXPower=-10,
              ModulationType=rfm69.OOK,
              SyncPattern=[0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x38],
              Preamble=0)

data = []
bitcnt = 0


def AddBit(bit):
    global data
    global bitcnt
    if bit:
        if ((len(data) * 8) - bitcnt) < 6:
            data.append(0)

        data[bitcnt / 8] |= 0xE0 >> (bitcnt % 8)

        if (bitcnt % 8) > 2:
예제 #2
0
파일: rcs1000.py 프로젝트: difu/RaspyRFM
ch = ord(sys.argv[2][0]) - ord('1')
for i in range(4):
    if i == ch:
        str += '0'
    else:
        str += 'F'

str += 'FF'

if sys.argv[3] == 'on':
    str += 'F'
else:
    str += '0'

print "Sending", str

data = xx2262.MakeFrame(str, 8)

if not Rfm69.Test(0):
    print "RFM69 not found!"
    exit()

rfm = Rfm69()
rfm.SetParams(Freq=433.92,
              Datarate=2.666666,
              TXPower=13,
              ModulationType=rfm69.OOK,
              SyncPattern=[])
rfm.SendPacket(data)
예제 #3
0
httpServices = {}
# HTTPService for every sensor in actual usage not needed
# for vKey in dictSensors:
#    #print dictSensors
#    if dictSensors[vKey]['port'] > 0:
#        httpServices[vKey] = httpservice.Service(dictSensors[vKey]['port'])
#        if (vVerbose == 'test'):
#            print str(dictSensors[vKey]['name']) + ': '+ str(ip) + ':' + str(dictSensors[vKey]['port'])

# One HTTPService for all sensors
httpDall = httpservice.Service(httpdport)
if vDebug:
    fileHandle.write(str(httpDall.provideData('test')) + '\n')

# Empfaenger Modul starten
rfm = Rfm69()

rfm.SetParams(
    Freq=868.300,  # MHz center frequency
    Datarate=9.579,  # 17.241, #kbit/s baudrate
    ModulationType=rfm69.FSK,  # modulation
    SyncPattern=[0x2d, 0xd4],  # syncword
    Bandwidth=200,  # kHz bandwidth
    LnaGain=0x88)
if vDebug:
    print 'sensorTool: Rfm69 initialized'
    fileHandle.write(
        str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) + ': ' +
        'sensorTool: Rfm69 initialized\n')

data = []
예제 #4
0
#!/usr/bin/env python2.7

from rfm69 import Rfm69
import rfm69
import sensors
import sys
import time

if Rfm69.Test(1):
    rfm = Rfm69(1, 24) #when using the RaspyRFM twin
elif Rfm69.Test(0):
    rfm = Rfm69() #when using a single single 868 MHz RaspyRFM
else:
    print "No RFM69 module found!"
    exit()

rfm.SetParams(
    Freq = 868.350,
    Datarate = 5.0,
    TXPower = -10,
    ModulationType = rfm69.OOK,
    SyncPattern = [0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x38],
    Preamble = 0
    )

data = []
bitcnt = 0

def AddBit(bit):
    global data
    global bitcnt
예제 #5
0
def threadSensors(out_q, vVerbose=''):
    #def threadSensors(vVerbose=''):
    vDebug = vVerbose
    vDebug = 'test'
    print str(datetime.datetime.now().strftime(
        '%Y-%m-%d %H:%M:%S')) + '- Anfang -' + '\n'
    if vDebug.startswith('test'):
        fileHandle = open('/var/sensorTool/sServiceErr.log', 'w')
        fileHandle.write(
            str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) +
            '- Anfang -' + '\n')
        fileHandle.close()
    # Empfaenger Modul starten
    rfm = Rfm69()

    rfm.SetParams(
        Freq=868.300,  # MHz center frequency
        Datarate=9.579,  # 17.241, #kbit/s baudrate
        ModulationType=rfm69.FSK,  # modulation
        SyncPattern=[0x2d, 0xd4],  # syncword
        Bandwidth=200,  # kHz bandwidth
        LnaGain=0x88)

    if vDebug.startswith('test'):
        fileHandle = open('/var/sensorTool/sServiceErr.log', 'a')
        fileHandle.write(
            str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) +
            'RFM initialized' + '\n')
        fileHandle.close()
        pass

    data = []
    dictSensors = {}
    dictSensors['bme280'] = {}

    # Werte empfangene Daten bis MAXTIME aus
    # while time.strftime('%H%M') < MAXTIME:
    refreshTime = 0
    refreshTX35 = 18
    refreshTX29 = 10
    #if vVerbose.startswith('test'):
    #    refreshTX35 = 9
    #    refreshTX29 = 5

    refreshTime = 0

    iInterval = refreshTX35 + refreshTX29 + 1
    refreshTime2 = time.time() + iInterval
    boolTX35 = True
    boolRun = True
    #iCountRuns = 0
    #    while 1:
    if vDebug.startswith('test'):
        fileHandle = open('/var/sensorTool/sServiceErr.log', 'a')
        fileHandle.write(
            str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) +
            'SensorService starts while' + '\n')
        fileHandle.close()
        pass

    while boolRun:
        print 'while'
        #if not boolRunQ.empty():
        #    boolRun = boolRunQ.get()
        #    if vVerbose.startswith('test'):
        #        print 'T1: boolRun = ' + str(boolRun)

        if time.time() > refreshTime:

            if boolTX35:
                try:
                    if vDebug.startswith('test'):
                        fileHandle = open('/var/sensorTool/sServiceErr.log',
                                          'a')
                        fileHandle.write(
                            str(datetime.datetime.now().strftime(
                                '%Y-%m-%d %H:%M:%S')) + ': TX 35' + '\n')
                        fileHandle.close()
                        print 'TX35'
                        rfm.SetParams(
                            Datarate=9.579),  # 17.241, #kbit/s baudrate
                except Exception as e:
                    if vDebug.startswith('test'):
                        fileHandle = open('/var/sensorTool/sServiceErr.log',
                                          'a')
                        fileHandle.write(
                            str(datetime.datetime.now().strftime(
                                '%Y-%m-%d %H:%M:%S')) + ': TX35 ' + str(e) +
                            '\n')
                        fileHandle.close()
                    pass
                refreshTime = time.time() + refreshTX35
                boolTX35 = False
            else:
                try:
                    if vDebug.startswith('test'):
                        fileHandle = open('/var/sensorTool/sServiceErr.log',
                                          'a')
                        fileHandle.write(
                            str(datetime.datetime.now().strftime(
                                '%Y-%m-%d %H:%M:%S')) + ': TX 29' + '\n')
                        fileHandle.close()
                        print 'TX29'
                        rfm.SetParams(
                            Datarate=17.241),  # 17.241, #kbit/s baudrate
                except Exception as e:
                    if vDebug.startswith('test'):
                        fileHandle = open('/var/sensorTool/sServiceErr.log',
                                          'a')
                        fileHandle.write(
                            str(datetime.datetime.now().strftime(
                                '%Y-%m-%d %H:%M:%S')) + ': TX29 ' + str(e) +
                            '\n')
                        fileHandle.close()
                        print str(e)
                    pass
                refreshTime = time.time() + refreshTX29
                boolTX35 = True

            #iCountRuns = iCountRuns + 1

        obj = None
        data = rfm.ReceivePacket(7)
        obj = rawsensor.CreateSensor(data)
        try:
            pass
        except Exception as e:
            if vDebug.startswith('test'):
                fileHandle = open('/var/sensorTool/sServiceErr.log', 'a')
                fileHandle.write(
                    str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
                    + ': ' + str(e) + '\n')
                fileHandle.close()
            print str(e)
            pass

        vNow = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

        # bme280 values to dictsensor
        try:
            (degC, hPa, hRel) = bme280.readData()
            dictSensors['bme280']['Time'] = vNow
            dictSensors['bme280']['T'] = round(degC, 2)
            dictSensors['bme280']['RH'] = round(hRel, 2)
            dictSensors['bme280']['hPa'] = round(hPa, 2)
            vNew = False
        except Exception as e:
            if vDebug.startswith('test'):
                fileHandle = open('/var/sensorTool/sServiceErr.log', 'a')
                fileHandle.write(
                    str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
                    + ': ' + str(e) + '\n')
                fileHandle.close()
            print str(e)
            pass

        # Betrachte nur La Crosse Daten
        if str(obj)[0:3] == 'La ':
            vSensor = ast.literal_eval(str(obj)[10:])

            if vSensor['ID'] not in dictSensors:
                dictSensors[vSensor['ID']] = {}

            dictSensors[vSensor['ID']]['Time'] = vNow
            if 'T' in vSensor:
                dictSensors[vSensor['ID']]['T'] = vSensor['T']
            if 'RH' in vSensor:
                dictSensors[vSensor['ID']]['RH'] = vSensor['RH']

        if vDebug.startswith('test'):
            fileHandle = open('/var/sensorTool/sServiceErr.log', 'a')
            fileHandle.write(
                str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) +
                ': T1 Sensors:' + '\n')
            for vKey in dictSensors:
                fileHandle.write(
                    str(datetime.datetime.now().strftime(
                        '%Y-%m-%d %H:%M:%S')) + ': T1:  ' + str(vKey) + ': ' +
                    str(dictSensors[vKey]) + '\n')
                print ': T1:  ' + str(vKey) + ': ' + str(
                    dictSensors[vKey]) + '\n'
            fileHandle.write(
                str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) +
                ': T1: out_q leer: ' + str(out_q.empty()) + '\n')
            fileHandle.close()

        if time.time() > refreshTime2:

            if vDebug.startswith('test'):
                fileHandle = open('/var/sensorTool/sServiceErr.log', 'a')
                fileHandle.write(
                    str(datetime.datetime.now().strftime(
                        '%Y-%m-%d %H:%M:%S')) + ': ' + 'T1: Q.PUT nach ' +
                    str(refreshTime2) + 's' + '\n')
                fileHandle.close()
                pass
            refreshTime2 = time.time() + iInterval
            try:
                if not out_q.empty():
                    out_q.get()
                    out_q.task_done()

                out_q.put(dictSensors)
            except Exception as e:
                if vDebug.startswith('test'):
                    fileHandle = open('/var/sensorTool/sServiceErr.log', 'a')
                    fileHandle.write(
                        str(datetime.datetime.now().strftime(
                            '%Y-%m-%d %H:%M:%S')) + ': ' + str(e) + '\n')
                    fileHandle.close()
                print str(e)
        time.sleep(0.1)

    if vDebug.startswith('test'):
        fileHandle = open('/var/sensorTool/sServiceErr.log', 'w')
        fileHandle.write(
            str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) +
            '- Ende -\n')
        fileHandle.close()
예제 #6
0
#!/usr/bin/env python2.7

import socket
import time
import rfm69
from rfm69 import Rfm69
import xx2262
import it32
import threading

PORT = 5052

rfm = Rfm69(1, 24)
rfm.SetParams(
    Freq=868.300,  #MHz center frequency
    ModulationType=rfm69.FSK,  #modulation
    Datarate=9.992,  #kbit/s baudrate
    Deviation=19.042,  #kHz frequency deviation -> OBW = 48 kHz, h = 3.81
    SyncPattern=[0xc6, 0x26, 0xc6, 0x26],  #syncword
    Bandwidth=100,  #kHz bandwidth (101.5)
    RssiThresh=-100,  #-100 dB RSSI threshold
    Preamble=1700)

connections = []


def maxPrint(frame):
    x = {}
    x['cnt'] = frame[1]
    x['flag'] = hex(frame[2])
    x['type'] = hex(frame[3])