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:[email protected]/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("");


}
7
  • To which service are you talking - I mean what is this "wss://admin:[email protected]/apps/localbus.lp" endpoint? Commented May 11, 2021 at 4:39
  • That is a websocket server. It's a logicmachine, that serve as a web interface with my KNX installation. Commented May 11, 2021 at 5:57
  • OK, but which server? There must be an API description for this service, or? Commented May 11, 2021 at 6: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. Commented May 11, 2021 at 6:05
  • You did not mention "LogicMachine" (is this forum.logicmachine.net/index.php?) in your question. Would be good if you edit the question and add this information. Commented May 11, 2021 at 6:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.