Пример #1
0
def main():
    def do_connect():
        networkID = passes.wifiID
        networkPass = passes.wifiPass
        # comment the two lines right above
        # uncomment the two lines right below
        # networkID = passes_template.wifiID
        # networkPass = passes_template.wifiPass
        wlan = network.WLAN(network.STA_IF)
        wlan.active(True)
        if not wlan.isconnected():
            print("connecting to network...")
            wlan.connect(networkID, networkPass)

            while not wlan.isconnected():
                pass
                # print("notyet")
                # print(networkID)
                # print(networkPass)
                # wlan.connect(networkID, networkPass)

        print("network config:", wlan.ifconfig())
        return wlan

    do_connect()

    osc = Client("192.168.0.255", 9001)
    # osc.send('/controls/frobnicator', 42, 3.1419, "spamm")
    b = Bundle()
    b.add(create_message("/foo", "test"))
    b.add(create_message("/spamm", 12345))
    while 1:
        osc.send(b)
Пример #2
0
def main():
    osc = Client(OSC_SERVER, OSC_PORT)

    try:
        while True:
            osc.send(OSC_TOPIC, "Filtered", urandom.getrandbits(30))
            sleep_ms(UPDATE_DELAY)
    except Exception as exc:
        print(exc)
Пример #3
0
class ThreadedClient(threading.Thread):
    def __init__(self, host, port=None, start=False, timeout=3.0):
        super(ThreadedClient, self).__init__()
        self.host = host
        self.port = port
        self.timeout = timeout
        self._q = Queue()

        if start:
            self.start()

    def run(self, *args, **kw):
        self.client = Client((self.host, self.port))

        while True:
            msg = self._q.get()
            if msg is None:
                break

            addr, msg = msg
            log.debug("Sending OSC msg %s, %r", addr, msg)
            self.client.send(addr, *msg)

        self.client.close()

    def send(self, addr, *args, **kw):
        self._q.put((addr, args), timeout=kw.get('timeout', self.timeout))

    def close(self, **kw):
        timeout = kw.get('timeout', self.timeout)
        log.debug("Emptying send queue...")

        while True:
            try:
                self._q.get_nowait()
            except QueueEmpty:
                break

        if self.is_alive():
            log.debug("Signalling OSC client thread to exit...")
            self._q.put(None, timeout=timeout)

            log.debug("Joining OSC client thread...")
            self.join(timeout)

            if self.is_alive():
                log.warning("OSC client thread still alive after join().")

    def __enter__(self):
        return self

    def __exit__(self, *args):
        self.close()
Пример #4
0
class ThreadedClient(threading.Thread):
    def __init__(self, host, port=None, start=False, timeout=3.0):
        super(ThreadedClient, self).__init__()
        self.host = host
        self.port = port
        self.timeout = timeout
        self._q = queue.Queue()

        if start:
            self.start()

    def run(self, *args, **kw):
        self.client = Client((self.host, self.port))

        while True:
            msg = self._q.get()
            if msg is None:
                break

            addr, msg = msg
            log.debug("Sending OSC msg %s, %r", addr, msg)
            self.client.send(addr, *msg)

        self.client.close()

    def send(self, addr, *args, **kw):
        self._q.put((addr, args), timeout=kw.get("timeout", self.timeout))

    def close(self, **kw):
        timeout = kw.get("timeout", self.timeout)
        log.debug("Emptying send queue...")

        while True:
            try:
                self._q.get_nowait()
            except queue.Empty:
                break

        if self.is_alive():
            log.debug("Signalling OSC client thread to exit...")
            self._q.put(None, timeout=timeout)

            log.debug("Joining OSC client thread...")
            self.join(timeout)

            if self.is_alive():
                log.warning("OSC client thread still alive after join().")

    def __enter__(self):
        return self

    def __exit__(self, *args):
        self.close()
Пример #5
0
    def run(self, *args, **kw):
        self.client = Client((self.host, self.port))

        while True:
            msg = self._q.get()
            if msg is None:
                break

            addr, msg = msg
            log.debug("Sending OSC msg %s, %r", addr, msg)
            self.client.send(addr, *msg)

        self.client.close()
Пример #6
0
def main():
    if SETUP_DEBUG_PIN:
        debugpin.setup()
    name = get_name()
    print(name)
    protocol = setup_all()

    reconnect_count = 0
    osc_client = None
    nic, destination_address = None, None

    if CONNECT_TO_NET:
        while True:
            try:
                nic, destination_address = setup_wifi()
                break
            except Exception:
                pass

        osc_client = Client(destination_address, OSC_PORT)
        print("sending OSC to", destination_address, OSC_PORT)

    # we have a spurious boot pin trigger,
    # I force debug off once here
    debugpin.DEBUG_MODE = False
    poll = uselect.poll()
    while True:
        print("connecting...")
        wait_while_idling(WIFI_COOLDOWN_PHASE)
        try:
            # this is needed to open the socket
            osc_client.send("/IGNORE", 0)
            poll.register(osc_client.sock, uselect.POLLIN)
            while True:
                machine.idle()
                protocol.update()
                protocol.send_osc(osc_client)
                for sock, kind in poll.ipoll(LOOP_SLEEP_MS):
                    incoming = sock.recv(100)
                    protocol.process_incoming(incoming)
                if debugpin.DEBUG_MODE:
                    print(".", end="")
        except OSError:
            reconnect_count += 1
            if reconnect_count > RESET_COUNT:
                print("resetting hard")
                machine.reset()
            time.sleep(1)
Пример #7
0
def main():
    enc = Encoder(pin_clk=12, pin_dt=14, clicks=4, accel=5, max_val=127)
    osc = Client(OSC_SERVER, OSC_PORT)

    oldval = 0
    try:
        while True:
            val = enc.value
            if oldval != val:
                oldval = val

                osc.send(OSC_TOPIC, ('m', (0, 0xB0, MIDI_CC, val)))

            enc.cur_accel = max(0, enc.cur_accel - enc.accel)
            sleep_ms(UPDATE_DELAY)
    except Exception as exc:
        enc.close()
        print(exc)
Пример #8
0
def main():
    enc = Encoder(pin_clk=PIN_CLK,
                  pin_dt=PIN_DT,
                  clicks=4,
                  accel=5,
                  max_val=127)
    osc = Client(OSC_SERVER, OSC_PORT)
    sw = Pin(PIN_SW, Pin.IN, None)

    oldval = 0
    oldsw = 1
    try:
        while True:
            if enc.value != oldval:
                osc.send(OSC_TOPIC, ("m", (0, 0xB0, MIDI_CC_ENC, enc.value)))
                oldval = enc.value

            enc.cur_accel = max(0, enc.cur_accel - enc.accel)

            if sw() != oldsw:
                osc.send(OSC_TOPIC,
                         ("m", (0, 0xB0, MIDI_CC_SW, 0 if sw() else 127)))
                oldsw = sw()

            sleep_ms(UPDATE_DELAY)
    except Exception as exc:
        enc.close()
        print(exc)
Пример #9
0
def main():
    # enc = Encoder(pin_clk=PIN_CLK, pin_dt=PIN_DT, clicks=4, accel=5, max_val=127)
    osc = Client(OSC_SERVER, OSC_PORT)
    sw = Pin(PIN_SW, Pin.IN, None)
    # mock data "sensor"
    sensor = 512
    oldval = 0
    oldsw = 1
    try:
        while True:
            if sensor != 10:
                # print("first send")
                osc.send(OSC_TOPIC, ("m", (0, 0xB0, MIDI_CC_ENC, sensor)))
                oldval = sensor

            # enc.cur_accel = max(0, enc.cur_accel - enc.accel)

            if sw() != oldsw:
                osc.send(OSC_TOPIC,
                         ("m", (0, 0xB0, MIDI_CC_SW, 0 if sw() else 127)))
                oldsw = sw()

            sleep_ms(UPDATE_DELAY)
    except Exception as exc:
        # enc.close()
        print(exc)
Пример #10
0
    def run(self, *args, **kw):
        self.client = Client((self.host, self.port))

        while True:
            msg = self._q.get()
            if msg is None:
                break

            addr, msg = msg
            log.debug("Sending OSC msg %s, %r", addr, msg)
            self.client.send(addr, *msg)

        self.client.close()
Пример #11
0
def connect_client(host="jack", port=5005, mqtt_client_name=None):
    global mqtt, osc
    print("Querying mDNS", host)
    ip = mdns.queryHost(host, timeout=30000)
    print("Query result:", ip)
    if len(ip) == 0 or 'not found' in ip:
        print("ABORT: Could not resolve host!")
        return False
    if mqtt_client_name is not None:
        mqtt = network.mqtt(mqtt_client_name, "mqtt://" + ip)
        mqtt.start()
    else:  # use OSC
        osc = Client(ip, port)
Пример #12
0
# include pysense libs
from pysense import Pysense
from LIS2HH12 import LIS2HH12
from SI7006A20 import SI7006A20
from LTR329ALS01 import LTR329ALS01
from MPL3115A2 import MPL3115A2, ALTITUDE, PRESSURE
# include osc libs
from uosc.client import Bundle, Client, create_message

# read config
with open('config.json') as json_data_file:
    CONFIG = json.load(json_data_file)

# setup osc
osc = Client(CONFIG["osc"]["server"], CONFIG["osc"]["port"])

py = Pysense()
# Send sensor data forever
while True:
    # Send pressure in Pa
    mpp = MPL3115A2(py, mode=PRESSURE)
    pressureOscData = str(mpp.pressure())
    osc.send(CONFIG["osc"]["sensors"]["pressure"], pressureOscData)
    print("Pressure: " + pressureOscData)

    # Send 3-axis acceleration
    li = LIS2HH12(py)
    accelerationOscData = li.acceleration()

    osc.send(CONFIG["osc"]["sensors"]["accelerationX"], accelerationOscData[0])
Пример #13
0
    led.on()
    sleep(0.1)
    led.off()
    sleep(0.1)
    
sta_if = network.WLAN(network.STA_IF)

sta_if.active(True) # Dont spawn own WiFi
sta_if.connect('DS4_TROPEN', 'groen333')

while not sta_if.isconnected():
  await_connection()
  sleep(1)
  print("Awaiting wifi connection.")

ap_if = network.WLAN(network.AP_IF)
ap_if.active(False)
print("Connected to DS4_TROPEN (wifi AP now disabled):")
print(sta_if.ifconfig())
  
local_addr = sta_if.ifconfig()[0]
print("My IP:", local_addr)

msg = "Hallo Jarno"
osc = Client(local_addr, 9001)
osc.send('/controls/frobnicator', 42, 3.1419, "spamm")
b = Bundle()
b.add(create_message("/foo", msg))
b.add(create_message("/spamm", 12345))
osc.send(b)
Пример #14
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import time

from uosc.client import Client


def run_loadtest(c):
    nreq = 0
    s = time.time()
    while True:
        nreq += 1
        c.send("/foo", 42, 23)
        e = time.time()
        if e - s > 5.0:
            print("{} req/s".format(nreq / 5.0))
            nreq = 0
            s = time.time()


if __name__ == "__main__":
    c = Client(9001)
    try:
        run_loadtest(c)
    except KeyboardInterrupt:
        pass
Пример #15
0
'''
Beautiful it ain't. But I made it in an afternoon so pbbbbththtttthh.

Hit the button, Max.
'''

from machine import Pin
from uosc.client import Client
import time
import network
print("main.py loaded")

button1 = Pin(34, Pin.IN)
button2 = Pin(35, Pin.IN)

console = Client('192.168.1.162', 53000)
#ESP32-GATEWAY board rev C and above require the clock_mode parameter in network setup
nic = network.LAN(mdc=Pin(23),
                  mdio=Pin(18),
                  phy_type=network.PHY_LAN8720,
                  phy_addr=0,
                  clock_mode=network.ETH_CLOCK_GPIO17_OUT)


def networkConnect():
    if not nic.isconnected():
        nic.active(True)
        nic.ifconfig(
            ('192.168.1.254', '255.255.255.0', '192.168.1.1', '192.168.1.1'))
    print(nic.ifconfig())
Пример #16
0
def main():
    # set timing variables:
    timePeriod = 20  # time in milliseconds between each data sending
    startTiming = 0
    stopTiming = 0

    # set variables for uosc client
    microsDelay = 20 * 1000  #  time delay in microseconds
    bonsaiAddress = "192.168.137.255"
    commPort = 9001
    digitalSend = "/digitalInput"
    digitalReceive = "/digitalOutput"

    # create osc client object
    osc = Client(bonsaiAddress, commPort)
    # set Digital pins

    # Digital output
    p0 = Pin(32, Pin.OUT)  # currently beehive D0 is IO32
    p1 = Pin(33, Pin.OUT)  # currently beehive D1 is IO33
    p2 = Pin(25, Pin.OUT)  # currently beehive D2 is IO25
    p3 = Pin(26, Pin.OUT)  # currently beehive D3 is IO26

    # index of pins set as output
    pinOutList = [p0, p1, p2, p3]
    pinOutIndex = [0, 1, 2, 3]
    # pinOutNum = [0,1,2,3]

    # digital input
    # p4 = Pin(27, Pin.IN) # currently beehive D4 is IO27
    p5 = Pin(14, Pin.IN)  # currently beehive D5 is IO14
    # p6 = Pin(12, Pin.IN) # currently beehive D6 is IO12
    # p7 = Pin(13, Pin.IN) # currently beehive D7 is IO13

    # index of pins set as input
    pinInList = [p5]  # [p4,p5,p6,p7]
    pinInIndex = [5]  # [4,5,6,7]

    # Analog input

    # although attenuation allows 3.6V to be the max range, 3.3V should be the MAX send to the board!!!
    # adc0 = machine.ADC(34) # currently beehive D7 is IO13
    # adc0.atten(machine.ADC.ATTN_11DB)    # set 11dB input attenuation (voltage range roughly 0.0v - 3.6v)
    # adc1 = machine.ADC(34) # currently beehive D7 is IO13
    # adc1.atten(machine.ADC.ATTN_11DB)    # set 11dB input attenuation (voltage range roughly 0.0v - 3.6v)
    # adc2 = machine.ADC(34) # currently beehive D7 is IO13
    # adc2.atten(machine.ADC.ATTN_11DB)    # set 11dB input attenuation (voltage range roughly 0.0v - 3.6v)
    # adc3 = machine.ADC(34) # currently beehive D7 is IO13
    # adc3.atten(machine.ADC.ATTN_11DB)    # set 11dB input attenuation (voltage range roughly 0.0v - 3.6v)

    # index of pins set as analog
    # pinsAnalogInList = [adc0,adc1,adc2,adc3]

    # analog output (actually PWM):
    # dac0 = 1
    # dac1 = 2
    # dac2 = 3
    # dac4 = 4

    # create bundle
    b = Bundle()
    # infinite loop

    while 1:

        # receive message from OSC
        dummie = 0
        # if there is a specific message break the scanning loop
        if dummie != 0:
            break

        # temp variable to store digital input values
        temp = 0

        startTiming = time.ticks_us()  # get microsecond counter
        # loop to scan input pins

        # tic1 = time.ticks_us()
        for i in range(len(pinInList)):
            # print(i)
            # print(pinInList[i].value())
            if pinInList[i].value() == 1:
                temp = temp + (2 ** pinInIndex[i])
            # print(temp)
        # toc1 = time.ticks_us()
        # print("getting all dig in ports took: "+str(toc1-tic1)+ " microseconds" )
        # print(toc1-tic1)
        # temp = bytes(temp)
        temp = uarray.array("B", [10, 32, 10, 20, 10, 10])
        msg = create_message(digitalSend, ("b", temp))
        b.add(msg)
        tic2 = time.ticks_us()
        osc.send(b)
        osc.close()
        del temp
        toc2 = time.ticks_us()
        print("sending took: " + str(toc2 - tic2) + " microseconds")
        x = 0
        while (
            stopTiming - startTiming < timePeriod * 1000
        ):  # convert milliseconds in microseconds
            # read digital port
            stopTiming = time.ticks_us()
        # time.sleep(0.001)

    # analog input pins
    # for i in range(len(pinsAnalogInList)):
    #    print(i)
    #    print(pinsAnalogInList[i].adc.read_u16())
    # do not forget to actually send the adc read info.

    # send message out with pins state

    # listen for message setting pins
    return
Пример #17
0
from uosc.client import Client

limitOpen = Pin(12, Pin.IN)
limitClose = Pin(14, Pin.IN)


drive = UART(1,9600)
drive.init(9600, bits=8, parity=None, stop=1)  # 9600 baud, 8 data bits, 1 stop bit, no parity

moveDistance = 72744                           # distance in steps to close / open doors

spi = 3031                                     # steps per inch of the motor/sprocket/belt

CONSOLE_IP = "192.168.1.114"                   # Make this the same as the IP address of the lighting console

console = Client(CONSOLE_IP, 8000)             # creates an OSC client that will send to the lighting console at CONSOLE_IP





nic = network.WLAN(network.STA_IF)
if not nic.isconnected():
    nic.active(True)
    nic.config(dhcp_hostname='NetIO Gateway')
    nic.connect('Stagehouse', 'Stage75!$Pp?')
    while not nic.isconnected():
        pass
print(nic.ifconfig())