Communicate with Android bluetooth device via NodeJS and Termux
You can communicate through the serial port using this tool. I have never use this tool but providing this only as a reference, since android is built on a linux kernel this might work. Please note that the examples are same as documentation.
https://github.com/eelcocramer/node-bluetooth-serial-port
Basic client usage
var btSerial = new (require('bluetooth-serial-port')).BluetoothSerialPort();btSerial.on('found', function(address, name) { btSerial.findSerialPortChannel(address, function(channel) { btSerial.connect(address, channel, function() { console.log('connected'); btSerial.write(new Buffer('my data', 'utf-8'), function(err, bytesWritten) { if (err) console.log(err); }); btSerial.on('data', function(buffer) { console.log(buffer.toString('utf-8')); }); }, function () { console.log('cannot connect'); }); // close the connection when you're ready btSerial.close(); }, function() { console.log('found nothing'); });});btSerial.inquire();
Basic server usage (only on Linux)
var server = new(require('bluetooth-serial-port')).BluetoothSerialPortServer();var CHANNEL = 10; // My service channel. Defaults to 1 if omitted.var UUID = '38e851bc-7144-44b4-9cd8-80549c6f2912'; // My own service UUID. Defaults to '1101' if omittedserver.listen(function (clientAddress) { console.log('Client: ' + clientAddress + ' connected!'); server.on('data', function(buffer) { console.log('Received data from client: ' + buffer); // ... console.log('Sending data to the client'); server.write(new Buffer('...'), function (err, bytesWritten) { if (err) { console.log('Error!'); } else { console.log('Send ' + bytesWritten + ' to the client!'); } }); });}, function(error){ console.error("Something wrong happened!:" + error);}, {uuid: UUID, channel: CHANNEL} );