Python issues with IPv6 address of Moku:Go

Hi All,
I am trying to connect to Moku:Go using python/spyder installation. My device is connected using a USB-C cable to the computer. I try to communicate with the Moku:go but get an invalid ip address. Please see below: any help is deeply appreciated.

Code:
(c) 2021 Liquid Instruments Pty. Ltd.

import numpy as np
from moku.instruments import WaveformGenerator
The ip address has been copied from the Moku interface
fe80:0000:0000:0000:7269:79ff:feb9:0f16%50
ip = '[fe80:0000:0000:0000:7269:79ff:feb9:0f16%50]'
i = WaveformGenerator(ip, force_connect=True)

Error
InvalidURL: Failed to parse: http://[fe80:0000:0000:0000:7269:79ff:feb9:0f16P]/api/moku/claim_ownership

Hello Avinash, the way to fix this issue is to remove the percent and the numbers after it, so your ip line should just be:

ip = '[fe80:0000:0000:0000:7269:79ff:feb9:0f16]'

This is because once you connect to your Moku:Go via USBC for the first time, this port is already known so you do not need to specify it and many version of python (and LabVIEW for that matter) have some strange typecasing for when the % is used and treats it as modulus. Please let me know if you encounter any other problems!

Hi Sam, Your suggestion fixed the problem. Thanks!

Hello Sam,

I was trying to implement your solution in Matlab, but I’m getting an error message. Is there any Matlab-specific trick in the code line that would fix the issue? Here is my code line to connect to the Moku:Go.

m = MokuOscilloscope(‘[fe80:0000:0000:0000:7269:79ff:feb9:12be]’, true);

The error message starts with the following:

Error using urlread2
Java exception occurred:
java.net.SocketException: Protocol family
unavailable

I am not quite sure about MATLAB, but I do know it is much more strict when it comes to dealing with IPv6. Have you already connected to this Moku via the desktop app and have you already tried including the port identifier as part of the IP address? The error you are getting looks more like a MATLAB error and not a Moku error. SocketException is usually related to issues with the program only accepting IPv4 and not IPv6.

Are you trying to use your Moku over USB, WiFi, or Ethernet? Sometimes, when you first make a connection to the Moku, the app will display an IPv6 address temporarily before correctly showing the IPv4 address. If you are not using USB to connect, then you may need to wait a few seconds for the app to acquire the correct address first.

Thank you for the reply! I should have provided more information in the previous post.

  • I am able to use the Moku:Go using the Moku Windows app over both WiFi and USB (there is no Ethernet capability on this unit).
  • I am only able to use the Moku:Go using Matlab over WiFi only.
  • For Wifi connection, I use the Matlab code line below, and it works with no problem:

m = MokuOscilloscope(‘192.168.73.1’, true);

  • For USB connection, I use the Matlab code lines below, both resulting in a long list of errors:

m = MokuOscilloscope(‘[fe80:0000:0000:0000:7269:79ff:feb9:12be%20]’, true);
or
m = MokuOscilloscope(‘[fe80:0000:0000:0000:7269:79ff:feb9:12be]’, true);

It looks like the issue is with the “urlread2” file, which is a part of the moku-MATLAB add-on.

Error using urlread2
Java exception occurred:
java.net.SocketException: Protocol family unavailable

at
java.net.TwoStacksPlainSocketImpl.socketConnect(Native
Method)

at
java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)

at
java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)

at
java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)

at
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)

at
java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)

at java.net.Socket.connect(Socket.java:589)

at java.net.Socket.connect(Socket.java:538)

at
sun.net.NetworkClient.doConnect(NetworkClient.java:180)

at
sun.net.www.http.HttpClient.openServer(HttpClient.java:463)

at
sun.net.www.http.HttpClient.openServer(HttpClient.java:558)

at
sun.net.www.http.HttpClient.(HttpClient.java:242)

at
sun.net.www.http.HttpClient.New(HttpClient.java:339)

at
sun.net.www.http.HttpClient.New(HttpClient.java:357)

at
sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1220)

at
sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156)

at
sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)

at
sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:984)

at
sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1334)

at
sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1309)

Error in Requests/http_post (line 122)
[output, extras] = urlread2(obj.create_url(obj.IP, action),…

Error in Moku/claim_ownership (line 214)
response = obj.session.http_post(‘moku/claim_ownership’, params);

Error in Moku (line 175)
obj.claim_ownership(‘force_connect’, force_connect, ‘ignore_busy’, ignore_busy, …

Error in MokuOscilloscope (line 84)
obj@Moku(IpAddr, force_connect, ignore_busy, persist_state, read_timeout, mimInited);

Error in MokuGo_oscilloscope (line 12)
m = MokuOscilloscope(‘[fe80:0000:0000:0000:7269:79ff:feb9:12be]’, true);

I see, thank you for providing the extra info. This issue is usually fixed using a proxy over USB which you can set up by downloading Moku CLI here. You can then set up the proxy very easily by following these steps.

Sam, thank you for the recommendation and sorry for “dumb” follow-up questions! Do you think it is possible to set up a proxy over USB without installing the Moku CLI?

It is not possible to set up a proxy with Moku:Go without using the CLI since this is how the proxy is connected directly to the Moku:Go. Is there are specific reason why you would prefer not to use the Moku CLI utility?

We purchased a new Moku:Go with ethernet connection capability, and I was hoping this would resolve the issue, but unfortunately no. Matlab API can only work via wi-fi connection, when the device IP address has the simple ‘192.168.73.1’ format. For USB-C and ethernet, the IP address format is ‘fe80::7269:79ff:feb9:47e0’ and Matlab just won’t work with this.
I just downloaded and installed the latest MokuCLI 2.1, but not sure how to use it. When I double-click on the mokucli.exe file to open the application it flashes some black window and then does nothing.

MATLAB API can accept IPv6 (we have some troubleshooting on this here). Also, that IPv6 address looks incorrect. The reason is because you can see there is a set of two colons next to eachother implying there is an empty address, also there is no port identifier (typically shown as a % followed by two numbers (e.g. fe00:xxxx:xxxx:xxxx%12)

MokuCLI needs to be called from a command terminal. You can open this by pressing Win+R and typing cmd into the prompt. I am not sure how to do this on Mac.

Thank you! I’ll double- or triple-check my steps on trying to set up a proxy. I spent a couple of hours yesterday, pretty sure I tried many different combinations (with and without % followed by two numbers, with and without the port number, after finding it using the ‘netstat -a’ command, etc.). One of the issues that I thought might be relevant is that the MokuCLI won’t see the connected Moku device. Please see the screenshot below showing that the Moku:Go is connected, but the command ‘mokucli list’ returns an empty list.

I believe the combination of identifiers you should try is with/without brackets and single quotes like below:

mokucli.exe proxy – port 27181 [fe00:0000:0000:xxxx:xxxx%21]
mokucli.exe proxy – port 27181 ‘[fe00:0000:0000:xxxx:xxxx%21]’
mokucli.exe proxy – port 27181 ‘fe00:0000:0000:xxxx:xxxx%21’

The syntax for IPv6 is interpreted differently between Windows and Mac, but one of the above combinations should work.

Sometimes, there is an issue where the port will be busy (the error message will say this) and to fix this you need to remove the port identifier (%21 in this case).

Let me know how you go.

My guess is there is some error in the ‘Requests.m’ file of Moku Matlab API, line 122. When I am connecting Moku:Go through wi-fi, the following code line works perfectly.

m = MokuOscilloscope(‘192.168.73.1’, true);

But the following code line returns a Java exception error “Error using urlread2”, even though the IP address is copy-pasted from the Moku software.

m = MokuOscilloscope(‘[fe80::1208:2cff:fe76:bae8]’,true);

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);