B4J Question WebSocketClient and UniPi API

besoft

Active Member
Licensed User
Longtime User
Hello,
I'm trying to connect to UniPi via the Evok UniPI API.

Code used:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private ws As WebSocketClient
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.Show
 
   ws.Initialize("ws")
   'accept all trust manager
   Dim ssl As JavaObject
   ssl.InitializeNewInstance("org.eclipse.jetty.util.ssl.SslContextFactory", Array(True))
   Dim jo As JavaObject = ws
   Dim wsc As JavaObject
   wsc.InitializeNewInstance("org.eclipse.jetty.websocket.client.WebSocketClient", Array(ssl))
   jo.SetField("wsc", wsc)
 
   ws.Connect("wss://192.168.8.103:8080/json/relay/3")
   Wait For ws_Connected
   Log("connected")
 
End Sub

I get an error or do not connect to the API. If I enter the address in chrome, I get the answer.
What am I doing wrong?

 
Last edited:

woniol

Active Member
Licensed User
Longtime User

Hi,
maybe you should try with this:
B4X:
ws.Connect("wss://192.168.8.103:8080/json/relay/3")
... single wss://

amd make sure that port 8080 is set for ssl connection
 
Upvote 0

besoft

Active Member
Licensed User
Longtime User
Thanks for the reply,
B4X:
ws.Connect("wss://192.168.8.103:8080/json/relay/3")
this is a mistake that has already been corrected, I forgot to change when posting.
The case does not work anyway. I am still researching.
 
Upvote 0

besoft

Active Member
Licensed User
Longtime User
Where is the updated error message?

 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
1) Quoting from the docs (https://evok-7.api-docs.io/1.06/q9xtwryq3ipgyhbbd/websocket):
To recieve the event messages register your client at the URL ws://your.unipi.ip.address/ws, (the Websocket Handshake/Upgrade endpoint). Once the connection is established you can send the commands specified above to your device.
Should your connection not be
B4X:
ws.Connect("ws://192.168.8.103:8080/ws")
?
Of course I have no experience with the API and I may be quoting the wrong portion of the API docs.

Or

2) The log shows
so your connection string may need to be
B4X:
ws.Connect("ws://192.168.8.103:8080/json/relay/3")
 
Upvote 0

besoft

Active Member
Licensed User
Longtime User
Please help,
How to use it in B4J ?

B4X:
# Values to be written
value_double=17.89

# URLs of the data points
url_double="http://192.168.1.100:8008/api/tasks/rest_api_task/CNR_IN:ycn"

# Credentials
user="admin"
password="mypasswd"

echo -e "\nWriting data type double ... "
curl -d "{\"v\":$value_double}" -u "$user:$password" -H "Content-Type: application/json" -X POST $url_double

EDIT

I did not ask questions very well, I know how to do this with jShell, I'm interested in how to correctly use HttpJob to use all the parameters.
 
Last edited:
Upvote 0

besoft

Active Member
Licensed User
Longtime User
Thanks for the reply,

In fact, it's still about UniPi Api, the first question is the ua Evok API, this question relates to the Rexygen API. In my opinion, things are very interconnected, so I posted in this section.

Anyway, I'll copy it to a new one.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…