xseignard / cordovarduino

Cordova/Phonegap plugin for USB host serial communication from an Android device.
MIT License
166 stars 110 forks source link

Android looses connection to arduino after few minutes #91

Closed Jaytt closed 6 years ago

Jaytt commented 6 years ago

I'm try to make a constant connection with android 4.0 but after a few minutes it disconnect and i can't get it back to work. I've tried 2 different android tablets, an arduino uno ch340q and an origianal arduino mega, but the none can hold the connection. I also would like to know how to get vendor-id product-id, it would be useful for me.

xseignard commented 6 years ago

Hello please provide some code!

xseignard commented 6 years ago

As stated on the readme, you can find your vid/pid with the lsusb command on Linux or Android

Jaytt commented 6 years ago

`serial.requestPermission( // if user grants permission function(successMessage) { // open serial port serial.open( {baudRate: 9600}, // if port is succesfuly opened function(successMessage) { open = true; // register the read callback serial.registerReadCallback( function success(data){ Recieved(data); }, // error attaching the callback errorCallback ); }, // error opening the port errorCallback ); }, // user does not grant permission errorCallback );

    function Recieved(data){
        // decode the received message
        var view = new Uint8Array(data);
        if(view.length != 0) {
            for(var i=0; i < view.length; i++) {
             // if we received a \n, the message is complete, display it
                if(view[i] == 13) {

                    str = str.replace(/(\r\n|\n|\r)/gm,"");

                    if(str.length > 7){
                        cardUD = str;
                        readNew = true;
                    }else if(str.length > 2 && str !=Test){ //==============================================
                        consumption = parseInt(str);
                    }
                    if(str != "0" && str !=Test){

                        time = 0.0; // if not idle reset timer 
                    }
                    Test = str;
                    AnyText++;
                    str = '';

                }else{// if not, concatenate with the begening of the message

                    var temp_str = String.fromCharCode(view[i]);
                    var str_esc = escape(temp_str);
                    str += unescape(str_esc);
                }
            }
       }

    }`
Jaytt commented 6 years ago

nothing special on my code it's basicly the exemple you guys made with a bit of string processing

Jaytt commented 6 years ago

i found my problem, it's an interference with reles, after using a phototransistor everything worked just fine