tl;dr;
I have been attempting to use Node.js on termux to speak to a serial converter on a usb port (Tablet->OTG->USB->Arduino). Have had a few issues with Node/Serial. This is partly issue/potential planning for a pull (haven't done one before)
full version,
When trying to open the /dev/tty as per the node-serialport example
https://github.com/EmergingTechnologyAdvisors/node-serialport
var SerialPort = require('serialport');
var port = new SerialPort('/dev/tty-usbserial1', {
baudRate: 57600
});
I tried ttySAC01 and a few others that were present in /dev but am getting
Error: Error: Permission denied, cannot open /dev/ttySAC0
at Error (native)
first line gives this
WARNING: linker: /data/data/com.termux/files/home/node-ardx/node_modules/serialport/build/Release/serialport.node has text relocations. This is wasting memory and prevents security hardening. Please fix.
I made a fork of termux-app and added this line to the AndroidManifest.xml
but as yet haven't had luck.
I know it's possible on android (non-rooted) through java (See https://github.com/mik3y/usb-serial-for-android) and i found a C/JNI one too. I looked at another option which creates a 'symlink' type tty device (pseudo tty) but this fails due to permissions also. I've seen the minicom package - but not sure how it is used to connect to serial (i skimmed through the code but can't see where it hooks into serial)
Is this a matter of adding more permissions to termux? or would it involve more involve coding to make a pretend /dev device? I figured it would be more usable to have it available through termux than building up a java app specifically for it. Another use case is Node-RED.
(I have also been attempting to build an updated termux-package for node 7.xx but ran into trouble with V8 dependencies on mkpeephole...)
Is there any news about it ?
I also need to use the serial port of my tablet for NodeJS. I would be so frustated to not be able to... :/
I'm also desperately looking for a way to access serial devices.
By default Android's kernel doesn't have serial drivers though. So the serial devices definitely don't show up under /dev, no matter if you're root or not.
It is however possible to access these devices using the Android USB host capability and its corresponding API. For this, the USB-serial driver code must be implemented in Termux's userspace.
There is a pretty good open source library that provides an interface to serial devices, even without root. It would be pretty neat if someone could connect the API with a device node like /dev/ttyUSB0.
there is already label for enhancement, does anyone work on it ?
that would be actually cool !
I'm also waiting for this, in the mean time, if you're not tied to usb ports, etherport works ok with wifi and ethernet shields (EthernetFirmata and WiFiFirmata).
You just need to add the etherport package.
https://github.com/rwaldron/etherport

let EtherPort = require('etherport');
let five = require('johnny-five');
let boardsConfig = [
{ id: 'NodeMCU', port: new EtherPort(3030), timeout: 30000 }, //WiFiFirmata
{ id: 'EtherShield', port: new EtherPort(3031), timeout: 30000 } //EthernetFirmata
];
let boards = new five.Boards(boardsConfig);
boards.on('ready', function() {
let potentiometer = new five.Sensor({
pin: 'A0',
freq: 250,
board: this.byId('NodeMCU')
});
let red = new five.Led({
pin: 5,
board: this.byId('EtherShield')
}),
yellow = new five.Led({
pin: 6,
board: this.byId('EtherShield')
}),
green = new five.Led({
pin: 7,
board: this.byId('EtherShield')
}),
leds = new five.Leds([red, yellow, green]);
leds.off();
potentiometer.on('change', function() {
leds.off();
if (this.value < 300) {
green.on();
}
if (this.value >= 300 && this.value <= 600) {
yellow.on();
}
if (this.value >= 601 && this.value <= 900) {
red.on();
}
if (this.value > 900) {
leds.strobe(500);
}
});
boards.repl.inject({
pot: potentiometer,
red,
yellow,
green,
leds
});
});
+1, was expecting to run my Arduino project served from my phone.
USB support is now implemented as part of Termux:API (https://wiki.termux.com/wiki/Termux-usb). However its usage is possible only of program backed by libusb.
Direct device access through /dev is not allowed by Android and therefore is not possible without root.
I found a workaround using a TCP bridge between a native Android app and Termux:
https://github.com/danpeig/Johnny-Five-Android-Termux
Most helpful comment
I found a workaround using a TCP bridge between a native Android app and Termux:
https://github.com/danpeig/Johnny-Five-Android-Termux