def connect(unused_addr, addressOrName, sample_rate=250, max_packets_to_skip=20, latency=10000, timeout=3, attempts=5, tcp=False): #tcp MUST be true! Doesn't work un UDP mode!
        # print("args:", unused_addr, timeout, attempts )
        try:
            socket.inet_aton(addressOrName)
            ip = addressOrName
            name = None
        except socket.error:
            ip = None
            name = addressOrName

        # print("tcp:", tcp)

        global obci_wifi
        try:
            # print("starting OpenBCIWifi")
            # print("sample_rate: ", sample_rate)
            # print("max_packets_to_skip: ", max_packets_to_skip)
            # print("latency: ", latency)
            # print("timeout: ", timeout)
            # print("attempts: ", attempts)
            send_message("starting OpenBCIWifi")
            send_message("sample_rate: ", sample_rate)
            send_message("max_packets_to_skip: ", max_packets_to_skip)
            send_message("latency: ", latency)
            send_message("timeout: ", timeout)
            send_message("attempts: ", attempts)
            obci_wifi = bci.OpenBCIWiFi(ip_address=ip, shield_name=name, sample_rate=sample_rate, log=True, timeout=timeout, max_packets_to_skip=max_packets_to_skip, latency=latency, high_speed=True, ssdp_attempts=attempts, num_channels=8, shield_found_cb=None, useTCP=tcp)
            # num_channels is ignored
            if obci_wifi.local_wifi_server is None:
                connected = False
                obci_wifi = None # prevent main loop
            else:
                connected = True
        except Exception as e:
            print("Connection failed. Error:", e)
            connected = False

        osc_sender_main.send_message(args.address + "/connected", connected) # status
    logging.basicConfig(filename="test.log",
                        format='%(asctime)s - %(levelname)s : %(message)s',
                        level=logging.DEBUG)
    logging.info('---------LOG START-------------')
    # If you don't know your IP Address, you can use shield name option
    # If you know IP, such as with wifi direct 192.168.4.1, then use ip_address='192.168.4.1'
    shield_name = 'OpenBCI-79AB'
    sample_rate = 500
    ip_address = '192.168.4.1'

    shield_wifi = bci.OpenBCIWiFi(ip_address=ip_address,
                                  shield_name=shield_name,
                                  sample_rate=sample_rate,
                                  timeout=15,
                                  max_packets_to_skip=10,
                                  latency=5000,
                                  high_speed=True,
                                  ssdp_attempts=20,
                                  auto_connect=False,
                                  micro_volts=True)

    print("WiFi Shield Instantiated")
    time.sleep(1)
    shield_wifi.connect()
    print("WiFi Shield Connected with board")
    time.sleep(1)
    print("WiFi Shield streaming started...")
    shield_wifi.start_streaming(handle_streamed_data)
    shield_wifi.loop()

    # Note: do this when you're finished streaming:
Beispiel #3
0
from __future__ import print_function
import sys

sys.path.append('..')  # help python find cyton.py relative to scripts folder
from openbci import wifi as bci
import logging


def printData(sample):
    print(sample.sample_number)
    print(sample.channel_data)


if __name__ == '__main__':
    logging.basicConfig(filename="test.log",
                        format='%(asctime)s - %(levelname)s : %(message)s',
                        level=logging.DEBUG)
    logging.info('---------LOG START-------------')
    # If you don't know your IP Address, you can use shield name option
    # If you know IP, such as with wifi direct 192.168.4.1, then use ip_address='192.168.4.1'
    shield_name = 'OpenBCI-E218'
    shield = bci.OpenBCIWiFi(shield_name=shield_name,
                             log=True,
                             high_speed=True)
    print("WiFi Shield Instantiated")
    shield.start_streaming(printData)

    shield.loop()
 def discover_shields(unused_addr, timeout=3, attempts=5):
     # print("args:", unused_addr, timeout, attempts )
     obci_wifi = bci.OpenBCIWiFi(log=True, timeout=timeout, ssdp_attempts=attempts, shield_found_cb=lambda ip_address, name, description : send_main('/found', ip_address, name))
Beispiel #5
0
                                   aux_channels=3,
                                   imp_channels=0)

    # osc.plugin_object.ip='localhost'
    # osc.plugin_object.port=57120
    # osc.plugin_object.address="/obci0"

    # print("osc.plugin_object.port", osc.plugin_object.port)


    def list_found_shields(ip_address, name, description):
        print("In stream_data... Found WiFi Shield %s with IP Address %s" %
              (name, ip_address))

    # osc = StreamerOSC(ip='localhost', port = 57120, address="/obci0")
    # osc.activate();

    shield = bci.OpenBCIWiFi(shield_name=None,
                             log=True,
                             high_speed=False,
                             shield_found_cb=list_found_shields)
    # shield = bci.OpenBCIWiFi(shield_name=shield_name, log=True, high_speed=False)
    # shield = bci.OpenBCIWiFi(ip_address='10.45.0.113', log=True, high_speed=False)
    # print("shield.local_wifi_server:", shield.local_wifi_server)
    if shield.local_wifi_server is not None:
        print("WiFi Shield Instantiated")
        # shield.start_streaming(printData)
        shield.start_streaming(sendData)

        shield.loop()
Beispiel #6
0
import SignalProcessor as SP
import thread


def printData(sample):
    print(sample.sample_number)
    print(sample.channel_data)


class State:
    def __init__(self):
        self.sp = SP.SignalProcessor()
        self.bicep = []

    def update(self, sample):
        if len(sample.channel_data) > 3:
            self.bicep.append(sample.channel_data[1])
        # Make sure the window size here is the same as in SignalProcessor.py
        if len(self.bicep) >= 200:
            thread.start_new_thread(self.sp.processEMG, (self.bicep, ))
            self.bicep = []


if __name__ == '__main__':
    state = State()
    shield = bci.OpenBCIWiFi(ip_address='192.166.0.2',
                             log=True,
                             high_speed=True)
    shield.set_sample_rate(1600)
    shield.start_streaming(state.update)
    shield.loop()