Update information received from arduino

0

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

A log-like job, always keeping the app up-to-date on the robot.

This is the thread I have to set up receiving 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 information received on the screen

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 do not know how to put the code between the necessary markings here in the forum (still .....)

Thank you.

    
asked by anonymous 06.06.2017 / 01:07

0 answers