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("");
}