Issues with Data Streaming via Moku:Go Datalogger

Hi there, I am trying to implement the data streaming feature with my Moku:Go, but am running into some issues in getting connected and whatnot. Here’s my specs:

Moku model: Moku:Go
Operating system: macOS
Software version: 3.0.0
Firmware version: 580

Here’s what I’ve tried, first via the command line:

% mokucli stream --ip-address=[fe80:0000:0000:0000:7269:79ff:feb9:3732%22] --target=- --stream-id=logsink0
zsh: no matches found: --ip-address=[fe80:0000:0000:0000:7269:79ff:feb9:3732%22]

where my IPv6 address is pulled from:

I believe the brackets should be there, and I don’t understand why it can’t connect to it. If I do the same basic idea using the Python API, I have:

from moku.instruments import Datalogger
i = Datalogger(
    '[fe80:0000:0000:0000:7269:79ff:feb9:3732%22]',
    force_connect=True,
    session_trust_env=False,
)
i.start_streaming(duration=10)
data = i.get_stream_data()
# Print out the data
print(data['time'], data['ch1'], data['ch2'])
i.relinquish_ownership()

Where I have to include the session_trust_env=False kwarg to bypass my workplace proxies (see my previous issue here:

Doing this, I get a different error:

---------------------------------------------------------------------------
ConnectionRefusedError                    Traceback (most recent call last)
/opt/anaconda3/envs/py310/lib/python3.10/site-packages/moku/instruments/_stream.py in _connect(self)
     71                 client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
---> 72                 client.connect(("localhost", self.port))
     73                 self._socket_rdr = client.makefile('r')

ConnectionRefusedError: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
/var/folders/5p/tldcvwc96mq_36y25zzh9snw0016_2/T/ipykernel_19991/579061853.py in <module>
      6 )
      7 i.start_streaming(duration=10)
----> 8 data = i.get_stream_data()
      9 # Print out the data
     10 print(data['time'], data['ch1'], data['ch2'])

/opt/anaconda3/envs/py310/lib/python3.10/site-packages/moku/instruments/_stream.py in get_stream_data(self)
    130             raise Exception
    131         if not self._running:
--> 132             self._begin_streaming()
    133         data = self._socket_rdr.readline()
    134         if data:

/opt/anaconda3/envs/py310/lib/python3.10/site-packages/moku/instruments/_stream.py in _begin_streaming(self)
     91         _start_event.wait()
     92         self._running = True
---> 93         self._connect()
     94 
     95     def stream_to_file(self, name=None):

/opt/anaconda3/envs/py310/lib/python3.10/site-packages/moku/instruments/_stream.py in _connect(self)
     75             except socket.error:
     76                 if i == 5:
---> 77                     raise Exception(f"Cannot connect to port {self.port}")
     78                 time.sleep(0.5)
     79 

Exception: Cannot connect to port 57442

So, I’m wondering if there’s any clear issues in what I’m doing. As far as I can tell, I’m following the documentation as well as can be, and this may be an issue simply with proxies from my workplace. I tried using the mokucli program to run a proxy, doing the following, but it gives me the same “no matches found” error:

% mokucli proxy [fe80:0000:0000:0000:7269:79ff:feb9:3732%22]  
zsh: no matches found: [fe80:0000:0000:0000:7269:79ff:feb9:3732%22]

Removing the brackets, it appears to run a proxy:

% mokucli proxy fe80:0000:0000:0000:7269:79ff:feb9:3732%22
Running a proxy from fe80:0000:0000:0000:7269:79ff:feb9:3732%22 to localhost:8090

Here I try to connect to localhost:8090 via both mokucli and the Python API, both giving the following errors:

CLI:

% mokucli stream --ip-address=localhost:8090 --stream-id=logsink0 --target=-
Invalid IP address

Python API:

from moku.instruments import Datalogger
i = Datalogger(
    'localhost:8090',
    force_connect=True,
    session_trust_env=False,
)
i.start_streaming(duration=10)
data = i.get_stream_data()
# Print out the data
print(data['time'], data['ch1'], data['ch2'])
i.relinquish_ownership()

---------------------------------------------------------------------------
ConnectionRefusedError                    Traceback (most recent call last)
/opt/anaconda3/envs/py310/lib/python3.10/site-packages/moku/instruments/_stream.py in _connect(self)
     71                 client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
---> 72                 client.connect(("localhost", self.port))
     73                 self._socket_rdr = client.makefile('r')

ConnectionRefusedError: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
/var/folders/5p/tldcvwc96mq_36y25zzh9snw0016_2/T/ipykernel_19991/336347656.py in <module>
      6 )
      7 i.start_streaming(duration=10)
----> 8 data = i.get_stream_data()
      9 # Print out the data
     10 print(data['time'], data['ch1'], data['ch2'])

/opt/anaconda3/envs/py310/lib/python3.10/site-packages/moku/instruments/_stream.py in get_stream_data(self)
    130             raise Exception
    131         if not self._running:
--> 132             self._begin_streaming()
    133         data = self._socket_rdr.readline()
    134         if data:

/opt/anaconda3/envs/py310/lib/python3.10/site-packages/moku/instruments/_stream.py in _begin_streaming(self)
     91         _start_event.wait()
     92         self._running = True
---> 93         self._connect()
     94 
     95     def stream_to_file(self, name=None):

/opt/anaconda3/envs/py310/lib/python3.10/site-packages/moku/instruments/_stream.py in _connect(self)
     75             except socket.error:
     76                 if i == 5:
---> 77                     raise Exception(f"Cannot connect to port {self.port}")
     78                 time.sleep(0.5)
     79 

Exception: Cannot connect to port 57734

So, I’m a bit at a loss on what to try next, or if there’s any clear reasons why it’s not working. I do plan to try just running it with my non-work computer to see if that’s the issue, so I’ll report back on that front. Any help/insight would be much appreciated, thanks!

I’ve tried running the same commands on a non-work computer, but I run into the same issues.

I wonder if this is a problem with connecting via IPv6?

You are correct that this is an issue with running the MokuCLI stream over IPv6. More specifically, it is an issue setting up a proxy via USB to stream the data through.

For now, is it possible to use the stream via WiFi? This feature does work for IPv4, although it sounds like you are in a pretty secure environment, so maybe this is not an option?

Hi Sam - okay thanks! Connecting the Moku to our WiFi network is not allowed, unfortunately. I was able to get the streaming working if I use the Moku as an Access Point via IPv4, but that is a bit inconvenient as then we lose internet connectivity on the machine controlling the Moku.

Is there an effort/timeline to have streaming working via IPv6? The USB-C connection works the best for our group and environment, so that would be an excellent feature.

This is an issue that we are working towards fixing but I do not have a timeline at this moment. It is high on our priority list as it would open up more applications and usability for many users! I will be sure to follow up here when I have more information.

1 Like

Can you please share how you use Moku as an access point via IPv4? I think I have exact same issue but for the Matlab API, described in the comments of the original post from someone else here: Python issues with IPv6 address of Moku:Go - #6 by azeytunyan

I also use Moku on a work PC and I am able to connect to Moku via WiFi. But WiFi connection should be slower than USB (or ethernet), so definitely would be nice to have USB connection working.

Do you mean how to use a proxy with MokuCLI over WiFi? There is an example of how to set it up on our API documentation site here.

Moku can already be used as an access point via IPv4, this is typically how users connect using an iPad or computer. If you need to turn this option on, right-click the device icon in the app and enable the “Access Point” section.

@slw : we have released “mokucli 2.1.0” which resolves this ‘streaming over IPv6 / USB’ issue.

You can download mokucli v2.1.0 from our website here : Utilities - Liquid Instruments

1 Like

Excellent, thank you! I’ll try it out soon.

Did mokucli 2.1.0 resolve the issue for you?

Yep! I’ve finally been able to mess around with the streaming, and the IPv6 streaming seems to work well in a Jupyter Notebook. Will be testing various cases to see what I can do with it.

Did you set up a proxy for IPv6 connection? If yes, can you please post how?

I did not - I’ve been able to use the first block of code I have in my post without any changes after updating to mokucli v2.1.0. I haven’t tested directly using the command line tool itself.

Update:
I was able to connect to and use the Moku:Go data streaming through the Matlab API using USB connection. Here is the code to do so by setting a proxy.

!powershell “netsh interface portproxy set v4tov6 listenport=8090 connectaddress=[IPADDRESS] connectport=http”
m = MokuDatalogger(‘localhost:8090’, true);