示例#1
0
def SensorData():
    uRAD.detection(distances,0,SNR,0,0,movement)

    tof3.start_ranging(3)
    api_dict["back"]    = tof3.get_distance()
    tof3.stop_ranging()

    api_dict["distance"] = distances[0]
    api_dict["snr"] = SNR[0]
    api_dict["movement"] = movement[0]
    return(json.dumps(api_dict))
示例#2
0
def getWeatherData(time):
    
#Transfer the timestamp when function is activated in UNIX time.    
def websiteData():

    #Konfigurasjon av linkt til nettsiden med json fil. 
    cred = credentials.Certificate("/home/pi/Library/FirestoreKey.json")
    app = firebase_admin.initialize_app(cred)

    store = firestore.client()

   
    # Connect the doc_ref to selected Node on the website.
    
    doc_ref = store.collection(u'Unit').document(u"Node1" ).collection(u"Activity")
    
    #Add bird detection coordinates and in real time. 
    doc_ref.add({u"Bird": 1, u"Cord": [10.39621,63.426905],u"TimeStamp": round(time)})
    


#The function write to the next line in a specified CSV file when the Raspberry Pi booted up.
def startTime(filename):
    f = open(filename, mode = "a") 
    sensor_write = csv.writer(f, delimiter = ",", quotechar='"', quoting=csv.QUOTE_MINIMAL)
    write_to_log = sensor_write.writerow(["\n", "Raspberry pi booted up: ", gettime_print(), gettime()])

#Skriver til CSVfilen. 
def writeToFile(filename):    
    #the a is for append
    f = open(filename, mode = "a") 
    sensor_write = csv.writer(f, delimiter = ",", quotechar='"', quoting=csv.QUOTE_MINIMAL)
    write_to_log = sensor_write.writerow(["Bird detected", "#", birdCount, " ", gettime_print(), gettime()])


#Return UNIX time in seconds. 
def gettime():
    return round(time.clock_gettime(0))


#Return date og time and write to screen in the pi.
#Returns date and time to show 
def gettime_print():
    return datetime.now()
    
#Stores the detection times if the Raspberry Pi loses connection to WiFi. 
def backup_data(float time):
    filename = "/home/pi/Library/FugleData_backup"
    f = open(filename, mode = "a") 
    sensor_write = csv.writer(f, delimiter = ",", quotechar='"', quoting=csv.QUOTE_MINIMAL)
    write_to_log = sensor_write.writerow([time])
    
#Reads the content from a file and returns every line in a matrix. 
def readFromFile(file):
    a = []
    with open(file) as f:
            for line in f.readlines():
                a.append(line)
    return a

#Erase the content from a file. 
def delFile(filename): 
        file = open(filename,"r+")
        file.truncate(0)
        file.close()


getTimePiStartedBoot("/home/pi/Library/FugleData")
getWeatherData()

# infinite detection loop
while True:
    # target detecton request
    uRAD.detection(0, 0, 0, 0, 0, movement)
    time_count = time.perf_counter()
    if(time_count > 60):
        getWeatherData()
        time_count = 0
        
    if (movement[0] == True):
        detection_time = gettime()
        print("Bird detected.","#", birdCount," ", gettime_print())
        birdCount += 1
        writeToFile("/home/pi/Library/FugleData")
        try: 
            websiteData(detection_time)
            backup_list = readFromFile("/home/pi/Library/FugleData_backup")
            #Sends the detection times when the Raspberry Pi lost connection to WiFi.
            if(len(backup_list) > 0): 
                for i in range(0,len(backup_list)-1):
                    websiteData(float(backuplist[i]))
                delFile("/home/pi/Library/FugleData_backup")
        except: 
            backup_data(detection_time)
示例#3
0
uRAD.loadConfiguration(uMode, uFrequency, uBW, uSamples, uTargets, uMaxRange,
                       uMTI, uMovement)

# Storage Variables
distances = [0, 0, 0, 0, 0]
SNR = [0, 0, 0, 0, 0]
movement = [0]

api_dict = {}

# Switch on URAD
uRAD.turnON()

while True:
    past_distance = distances
    uRAD.detection(distances, 0, SNR, 0, 0, movement)
    for idx in range(0, 5):
        print(abs(past_distance[idx] - distances[idx]))
    api_dict["distance"] = distances[0]
    api_dict["snr"] = SNR[0]
    api_dict["movement"] = movement[0]


@app.route("/")
def home():
    return render_template("index.html")


@app.before_request
def option_autoreply():
    """ Always reply 200 on OPTIONS request """
示例#4
0
    # Main datacollection loop
    # Capture ndata datapoints
    i = 0
    keep_going = True
    threading.Thread(target=key_capture_thread,
                     args=(),
                     name='key_capture_thread',
                     daemon=True).start()
    while keep_going and (i < ndata or not ndata):
        if len(velocity):
            lastsample = True
        else:
            lastsample = False

        # uRAD.detection(0, velocity, snr, iarr, qarr, movement)
        uRAD.detection(0, 0, 0, iarr, qarr, movement)
        velocity = vel.velocity(iarr, qarr)

        if len(velocity):
            # v or print("{}: velocity: {: 3.2f}, snr: {: 3.2f}"
            #      .format(i, velocity[0], snr[0]))
            if args.duration and lastsample:
                videocapture(duration, 1)
            if args.send:
                # Collect data
                buffadd(activity, velocity)
        else:
            v or print(i)

        # Send data
        # TODO: threading