Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data not received in other end device. #220

Closed
PriyankaRose opened this issue Apr 16, 2016 · 2 comments
Closed

Data not received in other end device. #220

PriyankaRose opened this issue Apr 16, 2016 · 2 comments

Comments

@PriyankaRose
Copy link

hi Don,

Greetings.
I have tired your BluetoothSerial Chat plugin to transfer set of data from one device to another (android-android and ios-ios).
while testing for android-android, it lists the devices and both are even connected. From device-1 if i send data, it says success. but it is not received in the device-2!

for your reference, i am attaching the screens took while testing in both android devices
Device-1
screenshot_2016-04-16-12-35-00
screenshot_2016-04-16-12-35-34
screenshot_2016-04-16-12-35-40
screenshot_2016-04-16-12-35-48
screenshot_2016-04-16-12-35-56

Device-2
screenshot_2016-04-16-12-35-19-483
screenshot_2016-04-16-12-35-27-799

and here is my index.js file
`var app = {
initialize: function() {
this.bindEvents();
this.showMainPage();
},
bindEvents: function() {

    var TOUCH_START = 'touchstart';
    if (window.navigator.msPointerEnabled) { // windows phone
        TOUCH_START = 'MSPointerDown';
    }
    document.addEventListener('deviceready', this.onDeviceReady, false);
    refreshButton.addEventListener(TOUCH_START, this.refreshDeviceList, false);
    sendButton.addEventListener(TOUCH_START, this.sendData, false);
    disconnectButton.addEventListener(TOUCH_START, this.disconnect, false);
    deviceList.addEventListener('touchstart', this.connect, false);
},
onDeviceReady: function() {
    app.refreshDeviceList();
},
refreshDeviceList: function() {
    bluetoothSerial.list(app.onDeviceList, app.onError);
    app.onData();
},
onDeviceList: function(devices) {
    var option;

    // remove existing devices
    deviceList.innerHTML = "";
    app.setStatus("");

    devices.forEach(function(device) {

        var listItem = document.createElement('li'),
            html = '<b>' + device.name + '</b><br/>' + device.id;

        listItem.innerHTML = html;

        if (cordova.platformId === 'windowsphone') {
          // This is a temporary hack until I get the list tap working
          var button = document.createElement('button');
          button.innerHTML = "Connect";
          button.addEventListener('click', app.connect, false);
          button.dataset = {};
          button.dataset.deviceId = device.id;
          listItem.appendChild(button);
        } else {
          listItem.dataset.deviceId = device.id;
        }
        deviceList.appendChild(listItem);
    });

    if (devices.length === 0) {

        option = document.createElement('option');
        option.innerHTML = "No Bluetooth Devices";
        deviceList.appendChild(option);

        if (cordova.platformId === "ios") { // BLE
            app.setStatus("No Bluetooth Peripherals Discovered.");
        } else { // Android or Windows Phone
            app.setStatus("Please Pair a Bluetooth Device.");
        }

    } else {
        app.setStatus("Found " + devices.length + " device" + (devices.length === 1 ? "." : "s."));
    }

},
connect: function(e) { alert('1');
    var onConnect = function() {
            // subscribe for incoming data
            bluetoothSerial.subscribe('\n', app.onData, app.onError);

            resultDiv.innerHTML = "";
            app.setStatus("Connected");
            app.showDetailPage();
        };

    var deviceId = e.target.dataset.deviceId;
    if (!deviceId) { // try the parent
        deviceId = e.target.parentNode.dataset.deviceId;
    }

    bluetoothSerial.connect(deviceId, onConnect, app.onError);
},
onData: function(data) { // data received from Arduino
    alert("data="+data);
    resultDiv.innerHTML = resultDiv.innerHTML + "Received: " + data + "<br/>";
    resultDiv.scrollTop = resultDiv.scrollHeight;
},
sendData: function(event) { // send data to Arduino
//connect();

    var success = function() {
        alert("success");
        resultDiv.innerHTML = resultDiv.innerHTML + "Sent: " + messageInput.value + "<br/>";
        resultDiv.scrollTop = resultDiv.scrollHeight;
    };

    var failure = function() {
        alert("Failed writing data to Bluetooth peripheral");
    };

    var data = messageInput.value;
    bluetoothSerial.write(data, success, failure);
},
disconnect: function(event) {
    bluetoothSerial.disconnect(app.showMainPage, app.onError);
},
showMainPage: function() {
    mainPage.style.display = "";
    detailPage.style.display = "none";
},
showDetailPage: function() {
    mainPage.style.display = "none";
    detailPage.style.display = "";
},
setStatus: function(message) {
    alert("message="+message);

    window.clearTimeout(app.statusTimeout);
    statusDiv.innerHTML = message;
    statusDiv.className = 'fadein';

    // automatically clear the status with a timer
    app.statusTimeout = setTimeout(function () {
        statusDiv.className = 'fadeout';
    }, 5000);
},
onError: function(reason) {
    alert("ERROR: " + reason); // real apps should use notification.alert
}

};`

my problem is, data not received in the device-2.

Thanks in advance. :)

@PriyankaRose
Copy link
Author

PriyankaRose commented Apr 19, 2016

the devices tested are
device-1 : Moto G3
device-2 : iphone 6s

and i have tested with other devices too.
Data Read not working though the Data sent success message comes.

Could you provide any suggestion.!!

@don
Copy link
Owner

don commented Apr 20, 2016

@PriyankaRose Currently can't connect Android to Android. You can pair two Android devices, but unless one of them opens provides Serial Port Profile, you're not going to be able to connect. This plugin doesn't currently support incoming connections. Some of the other github issues may point to forks from other users that fix this. #50 (comment) It's technically possible, I just haven't implemented it and no one has submitted a pull request.

Android to iOS is not possible with this plugin. Android uses Bluetooth Classic and iOS uses Bluetooth Low Energy.

You could do iOS to iOS (or Android) is the other device implements one of the UART-like BLE SPP services. #75 (comment) You'd need to implement the BLE service with native code. I don't think there's a Corodva plugin for that yet.

@don don closed this as completed Apr 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants