This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Apple Client
#1
would anyone be able to share their knowledge of connecting an app to the rpi as a client? I would like to build an app that displays Engine data but am unable to connect to the rpi server. I am using the signal k script for apple since javascript into the Android base code is not clear to me. The code provided by signal K for apple client was used and cocoa pods were installed correctly shown on the following link.

https://github.com/SignalK/signalk-apple-client

host used is: "10-1-1-40.local"
port used is: 3000

why would the error code: "Request timed out" keep appearing? Running 10.10.10.1:3000 into my browser opens up signalk. Also, is there better instruction for running a client to retrieve data in an Android app then is provided by SignalK website?

cheers
Reply
#2
The error message sounds like you are trying to reach some other server than what you think.

The server’s api is just http and WebSocket, can’t you just google these and the programming language you are using? Java, Kotlin, Swift, ObjC? To get data by http or stream via ws should be very easy in any language. The advantage of a dedicated client library comes with more complicated stuff, for example access requests and authorization in general.


Sent from my iPhone using Tapatalk
Reply
#3
For future reference, this code has got me a response from the raspberry pi. It still needs refinement:


build.gradle:
implementation "org.java-websocket:Java-WebSocket:1.3.0"

Manifest:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />



Main Activity:

private WebSocketClient mWebSocketClient;

static String TAG = "***WEBSOCKET TEST***";
private static final String SERVER = "ws://10.10.10.1:3000/signalk/v1/stream";
private static final int TIMEOUT = 5000;


private void connectWebsocket() {
   URI uri;
   try {
       uri = new URI(SERVER);
       Log.d(TAG, "URI COMPLETE");
   } catch (URISyntaxException e) {
       Log.d(TAG, "URI SYNTAX EXCEPTION: " + e);
       return;
   }

   mWebSocketClient = new WebSocketClient(uri) {
       @Override
       public void onOpen(ServerHandshake serverHandshake) {
           Log.d(TAG, "SERVER HANDSHAKE");
           mWebSocketClient.send("Hello from " + Build.MANUFACTURER + " " + Build.MODEL);
       }

       @Override
       public void onWebsocketHandshakeSentAsClient(WebSocket conn, ClientHandshake request) throws InvalidDataException {
           super.onWebsocketHandshakeSentAsClient(conn, request);
           Log.d(TAG, "HANDSHAKE SENT AS CLIENT");
       }

       @Override
       public void onWebsocketHandshakeReceivedAsClient(WebSocket conn, ClientHandshake request, ServerHandshake response) throws InvalidDataException {
           super.onWebsocketHandshakeReceivedAsClient(conn, request, response);
           Log.d(TAG, "HANDSHAKE RECEIVED AS CLIENT");
       }


       @Override
       public void onMessage(String s) {
           final String message = s;
           Log.d(TAG, "ON MESSAGE: " + s);
           runOnUiThread(new Runnable() {
               @Override
               public void run() {
                   //TextView textView = (TextView)findViewById(R.id.messages);
                   //textView.setText(textView.getText() + "\n" + message);
               }
           });
       }

       @Override
       public void onMessage(ByteBuffer bytes) {
           super.onMessage(bytes);
           Log.d(TAG, "ON MESSAGE");
       }

       @Override
       public void onClose(int i, String s, boolean b) {
           Log.d(TAG, "Closed " + s);
       }

       @Override
       public void onError(Exception e) {
           Log.d(TAG, "ERROM MESSAGE: " + e.getMessage());
       }
   };
   mWebSocketClient.connect();
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)