def main():
    bash.command('sudo systemctl start readSensor')
    while True:
        command, address = udp.receive(PI_DATA_UDP_PORT)
        if command == 'h':
            udp.send(PI_CONTROL_IP_DATA, PI_CONTROL_UDP_PORT_DATA, '15.2')
        elif command == 't':
            time, hum, tem = database.read_data_from_db()
            udp.send(PI_CONTROL_IP_DATA, PI_CONTROL_UDP_PORT_DATA, '22.4')
        elif command == 'i':
            tcp.send(PI_CONTROL_IP_DATA, PI_CONTROL_TCP_PORT_DATA, '~\proj\image.jpg')
Exemplo n.º 2
0
def main():
    bash.command('sudo systemctl start readSensor')
    while True:
        command, address = udp.receive(PI_DATA_UDP_PORT)
        if command == 'h':
            time, hum, tem = database.read_data_from_db()
            udp.send(PI_CONTROL_IP_DATA, PI_CONTROL_UDP_PORT_DATA, str(hum))
        elif command == 't':
            time, hum, tem = database.read_data_from_db()
            udp.send(PI_CONTROL_IP_DATA, PI_CONTROL_UDP_PORT_DATA, str(tem))
        elif command == 'i':
            path = takePhoto()
            tcp.send(PI_CONTROL_IP_DATA, PI_CONTROL_TCP_PORT_DATA, path)
Exemplo n.º 3
0
def main():
    while True:
        udp.send(PI_DATA_IP, PI_DATA_UDP_PORT, 'h')
        hum, addr = udp.receive(PI_CONTROL_UDP_PORT_DATA)
        hum = float(hum)
        udp.send(PI_DATA_IP, PI_DATA_UDP_PORT, 't')
        tem, addr = udp.receive(PI_CONTROL_UDP_PORT_DATA)
        tem = float(tem)
        delay = tem ** 2 - tem * 10 - hum * 2
        bash.command('sudo systemctl start motor')
        time.sleep(delay)
        bash.command('sudo systemctl stop motor')
        time.sleep(86400 - delay - 1)
Exemplo n.º 4
0
def main():
    while True:
        command, address = udp.receive(PI_CONTROL_UDP_PORT_AND)
        if command == 'h': # humidity or temperature requested
            udp.send(address[0], ANDROID_UDP_PORT, '15.1')
        elif command == 't': # humidity or temperature requested
            udp.send(address[0], ANDROID_UDP_PORT, '22.3')
        elif command == 'i': # image requestedm, 
            tcp.send(address[0], ANDROID_TCP_PORT, '~\proj\image.jpg')
        elif command == 'r': # start motor requested
            print('sudo systemctl start motor')
        elif command == 's': # stop motor requested
            print('sudo systemctl stop motor')
        elif command == 'a': # turn auto irrigation mode on
            print('sudo systemctl start autoIrrigation')
        elif command == 'u': # turn auto irrigation mode off
            print('sudo systemctl stop autoIrrigation')
Exemplo n.º 5
0
def main():
    while True:
        command, address = udp.receive(PI_CONTROL_UDP_PORT_AND)
        if command == 'h' or command == 't': # humidity or temperature requested
            udp.send(PI_DATA_IP, PI_DATA_UDP_PORT, command)
            val, addr = udp.receive(PI_CONTROL_UDP_PORT_DATA)
            udp.send(address[0], ANDROID_UDP_PORT, val)
        elif command == 'i': # image requested, 
            udp.send(PI_DATA_IP, PI_DATA_UDP_PORT, command)
            #tcp.forward(PI_CONTROL_TCP_PORT_DATA, address[0], ANDROID_TCP_PORT)
            # Due to implementation difficulties, replaces by cloudnary library
            filename = tcp.receive(PI_CONTROL_TCP_PORT_DATA)
            url = basic.upload_files(filename) # upload received photo to cloudnary
            udp.send(address[0], ANDROID_UDP_PORT, url) # send url to android
        elif command == 'r': # start motor requested
            bash.command('sudo systemctl start motor')
        elif command == 's': # stop motor requested
            bash.command('sudo systemctl stop motor')
        elif command == 'a': # turn auto irrigation mode on
            bash.command('sudo systemctl start autoIrrigation')
        elif command == 'u': # turn auto irrigation mode off
            bash.command('sudo systemctl stop autoIrrigation')
Exemplo n.º 6
0
def main():
    # test humidity access 
    udp.send('localhost', PI_CONTROL_UDP_PORT_AND, 'h')
    val = udp.receive(ANDROID_UDP_PORT)
    assert int(val) >= 0 and int(val) <= 100, 'Invalid humidity value!' + val

    # test temperature access 
    udp.send('localhost', PI_CONTROL_UDP_PORT_AND, 't')
    val = udp.receive(ANDROID_UDP_PORT)
    assert int(val) >= -50 and int(val) <= 50, 'Invalid temperature value!' + val

    # test image access 
    udp.send('localhost', PI_CONTROL_UDP_PORT_AND, 'i')
    val = tcp.receive(ANDROID_TCP_PORT)
    assert val != None, 'Did not receive a picture!'
    assert os.path.isfile(val), 'File not exist!'
Exemplo n.º 7
0
    notes = prepareChord(chord)
    instruments = ['oboe', 'violin', 'viola', 'cello']
    time = abs(window(4.)) + 2.
    note, notes = oneOf(notes)

    while len(instruments) > 0 and len(notes) > 0:
        bundles = []
        note, notes = oneOf(notes)
        possible_instruments = intersect(instruments, check(note))
        instrument = one(possible_instruments)
        instruments.remove(instrument)
        voiceTime = window(time) * .2 + time
        note_used = note[0]
        if one([0, 1]) is 0: 
            note_used = round(note_used)
        bundles.append(reartic(note_used, voiceTime, instrument))
        oscore = o.message('/score', bundles)
        file_prefix = prefix()
        oprefix = o.message('/prefix', file_prefix)
        otime = o.message('/time', time + 3.)
        result = o.bundle(messages = [oscore, otime, oprefix])
        f = open('./scores/' + file_prefix + '_score.txt', 'w')
        f.write(str(result))
        f.close()
        send(result)
        print(result)
        print('-' * 100)
        sleep(time * 2 + 3.)

print("Finished...")
Exemplo n.º 8
0
    def refresh(self):
        if self.combo.count()==0:
            self.combo.addItems(self.threadacquisition.channelNames)
            self.freqs = np.fft.fftfreq(self.fft_size, self.threadacquisition.samplingInterval)
        channel = self.combo.currentIndex()
        
        if self.comboBand.count()==0:
            self.comboBand.addItems(self.band_name)
        id_band = self.comboBand.currentIndex()
  
  
        #Time representation
        s_time = self.threadacquisition.buffer[-self.scope_size:, channel]
        self.ax_time.clear()
        self.ax_time.set_title('Signal over samples')
        self.ax_time.set_ylabel('Amplitude')
        self.ax_time.set_xlabel('Samples')
        self.ax_time.plot(s_time, color = 'r')
        self.ax_time.set_xlim(0,self.scope_size)
##         self.ax_time.set_ylim(,1024)
        
        self.canvas_time.draw()
    
        #Power spectrum
        s_fft = self.threadacquisition.buffer[-self.fft_size:, channel]
        f = abs(np.fft.fft(s_fft))
        self.ax_fft.clear()
        self.ax_fft.plot(self.freqs[1:self.fft_size//2], f[1:self.fft_size//2], color = 'g')
        self.ax_fft.set_title('Corresponding power spectrum')
        self.ax_fft.set_ylabel('Power')
        self.ax_fft.set_xlabel('Frequency (Hz)')
##         self.ax_fft.set_xlim(0,self.scope_size)
##         self.ax_fft.set_ylim(,1024)
        
        self.canvas_fft.draw()
        
        
        #Power in frequency band
        #Delta
        ind = (self.freqs>1.) & (self.freqs<=4.)
        self.idelta = np.sum([f[ind]])
        #Theta
        ind = (self.freqs>4.) & (self.freqs<=8.)
        self.itheta = np.sum([f[ind]])
        #Alpha
        ind = (self.freqs>8.) & (self.freqs<=12.)
        self.ialpha = np.sum([f[ind]])
        #Beta
        ind = (self.freqs>12.) & (self.freqs<=24.)
        self.ibeta = np.sum([f[ind]])
        #Gamma
        ind = (self.freqs>24.) & (self.freqs<=45.)
        self.igamma = np.sum([f[ind]])
        
        b = np.array([[self.idelta, self.itheta, self.ialpha, self.ibeta, self.igamma]])
        self.band = np.concatenate( [self.band, b.T], axis = 1)
        self.band = self.band[-self.scope_size:] 
        
        color_band = ['r','b','g','y','m']
        self.ax_powband.clear()

        for i in range (0,len(self.band)):
            self.ax_powband.plot(self.band[i,-20:], color = color_band[i])
        self.ax_powband.set_title('Pow in Delta(red)-Theta(blue)-Alpha(green)-Beta(yellow)-Gamma(magenta)')
        self.ax_powband.set_ylabel('Power')
        self.ax_powband.set_xlabel('Windows')
        
        self.canvas_powband.draw()
        
        #Selected band
        self.ax_select_powband.clear()
        self.ax_select_powband.plot(self.band[id_band,-20:], color = color_band[id_band])
        self.canvas_select_powband.draw()
        
        udp.send(self.port, str(int(b[0,id_band])))
Exemplo n.º 9
0
#!/usr/bin/python

import udp
import argparse

parser = argparse.ArgumentParser(description='Listen to UDP-packets')

group = parser.add_mutually_exclusive_group(required=False)
group.add_argument('-b', "--broadcast", action='store_true', help="Send to broadcast")
group.add_argument("-a", "--address", default='', help="Address to send to. If not specified, try to figure local IP")
parser.add_argument("-p", "--port", default=5000, type=int, help="Port to send to. Default 5000")

parser.add_argument('-v', "--verbose", action='store_true')

parser.add_argument("message")
args = parser.parse_args()

if args.broadcast:
	ip = udp.get_broadcast_address()
elif args.address == '':
	ip = udp.get_ip_address()
else:
	ip = args.address

port = args.port  # where do you want to send a msg?
udp.setup(ip, port)
udp.send(args.message, args.verbose)
Exemplo n.º 10
0
#!/usr/bin/python3

import sys

sys.path.insert(1, '../src')

import udp
udp.PACKET_SIZE = 16

sock = udp.open('', 8081)
pack = bytes('chrissx is cool.', 'utf-8')
print(udp.send(sock, pack, '127.0.0.1', 8081))
udp.close(sock)