0

I need some help with setting up a Button to control my lighting in one room. I have implemented WebSocket client in Android Studio. I have a Button that I want to send/write the value false for this KNX group address "1/0/4". Is there anyway to do this?

I use a LogicMachine LogicMachine as a webserver with built in Websockets libraries in LUA.

public class MainActivity extends AppCompatActivity {

Button btn;

private WebSocketClient webSocketClient;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btn = (Button)findViewById(R.id.BT);


    connectWS();

}


private void connectWS() {

    URI uri;
    try {
        uri = new URI("wss://admin:admin@192.168.10.11/apps/localbus.lp");

    } catch (URISyntaxException e) {
        e.printStackTrace();
        return;
    }

    webSocketClient = new WebSocketClient(uri) {


        @Override
        public void onOpen(ServerHandshake handshakedata) {
            Log.i("Websocket", "Opened");
            webSocketClient.send("Hello from " + Build.MANUFACTURER + " " + Build.MODEL);
        }

        @Override
        public void onMessage(String s) {
            final String message = s;
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    TextView textView = (TextView) findViewById(R.id.TW);
                    textView.setText(textView.getText() + "\n" + message);
                }
            });
        }


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

        }

        @Override
        public void onError(Exception e) {
            Log.i("Websocket", "Error " + e.getMessage());
        }

    };

    webSocketClient.connect();

}

public void sendMessage(View view) {
    EditText editText = (EditText) findViewById(R.id.ET);
    webSocketClient.send(editText.getText().toString());
    editText.setText("");


}
Klaus Gütter
  • 11,151
  • 6
  • 31
  • 36
Alex
  • 27
  • 8
  • To which service are you talking - I mean what is this "wss://admin:admin@192.168.10.11/apps/localbus.lp" endpoint? – Klaus Gütter May 11 '21 at 04:39
  • That is a websocket server. It's a logicmachine, that serve as a web interface with my KNX installation. – Alex May 11 '21 at 05:57
  • OK, but *which* server? There must be an API description for this service, or? – Klaus Gütter May 11 '21 at 06:01
  • I don't know a lot about this LogicMachine but all I know is that you script in LUA in it and there are built in websocket libraries. I'm sorry for not giving you more info. – Alex May 11 '21 at 06:05
  • You did not mention "LogicMachine" (is this https://forum.logicmachine.net/index.php?) in your question. Would be good if you [edit] the question and add this information. – Klaus Gütter May 11 '21 at 06:09
  • Ok, I have edited the question now. But say I have a websocket connection with the server (I have tested the url in a websocket connection tester and it works.) How can I make my button in Android Studio to send a boolean value to my server? – Alex May 11 '21 at 06:16
  • Also, I have made a html to test if I can turn off and on lights, and that worked. – Alex May 11 '21 at 06:17

0 Answers0