Update information received from Arduin

Asked

Viewed 46 times

0

I have made an application that interacts with a robotic head with Arduino and I would like to know how to automatically receive all the data from the robot without having to trigger the sending of some command

It would work similar to a log, always keeping updated the app of the information received from the robot

This is the thread I have to configure the receipt of information

 class ThreadServidor extends Thread{
        @Override
        public void run(){
            try{
                if(socket != null){
                    /*serverSocket.close();*/
                    // Depois que alguém conectou, pega a InputStream para ler as mensagens
                    in = socket.getInputStream();
                    // Fica em loop, para receber as mensagens
                    while(true) {
                        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                        String line = reader.readLine();
                        updateViewMensagem(line);
                    }
                }
            } catch(IOException e){
                e.printStackTrace();
            }
        }
    }

And this is the method that shows on the screen the information received

private void updateViewMensagem(String s) {
        if((!s.isEmpty()) && s != null){
            if(qtdLinhas == 10){
                list = "";
                qtdLinhas = 1;
            }
            if(ordem == 7){
                list += s;
                ordem = 1;
                qtdLinhas++;
            }else{
                list += s + " - ";
                ordem++;
            }
            getActivity().runOnUiThread(new Runnable(){
                @Override
                public void run(){
                    if(list != null){
                        logInfo.setText(list);
                    }
                }
            });
        }
    }

Note:I don’t know how to put the code among the necessary markups here in the forum(yet.....)

Thank you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.