node-serialport equivalent of remserial - node.js

remserial is a program aimed at acting as a communication bridge between a TCP/IP network port and a linux serial port.
Is there a way to use the serialport node package (or another) to achieve the same behavior as this command?
./remserial -r 10.42.0.70 -p 5001 -l /dev/remserial1 /dev/ptmx

Related

virtual serial port from remote physical serial port

I have a local client host (linux), which runs an application (like minicom) that connects to a serial port.
However, the physical serial port (/dev/ttyUSB0) is present on a remote server host (linux), to which I have ssh access.
For various reasons, I do not want to run the application on the server host through ssh.
Therefore, I am connecting this physical serial port to a local virtual serial port (/dev/ttyNET0) using socat:
sudo socat "pty,link=/dev/ttyNET0,group-late=dialout,perm-late=666,sane,rawer" \
"exec:'ssh -tt ${remote-host} socat "stdio,sane,rawer" "file:/dev/ttyUSB0,sane,rawer,b115200"',pty,sane,rawer"
I am then able to connect to this serial port on my local machine as follows:
sudo minicom -D "/dev/ttyNET0"
Note that there were two calls of socat in the previous command: one on the client side, and one on the server side.
I am wondering if the equivalent of this command can be constructed with a single call of socat. I tried this:
sudo socat "pty,link=/dev/ttyNET0,group-late=dialout,perm-late=666,sane,rawer" \
"file:'ssh://${remote-host}:/dev/ttyUSB0',sane,rawer,b115200"
But it did not work. I have read through the manpage of socat, but I might be missing something.

iperf between 2 interfaces on same host

I am looking for a way how I can run iperf benchmark between 2 interfaces on the same host as shown on the schema:
Both of the machines (pc and router) are linux.
I'm need a way to run some functional tests on my "router" machine using my only 1 PC with 2 ethernet ports.
I tried already few different ways to solve it but still no luck:
1) Adding static routes for destination hosts with metric
2) Binding iperf to specific ip address
3) Disabling local loopback interface
Basicly what I'm looking for is to run traffic 192.168.1.10<-->1.1.1.10 thru the router device (with ip forwarding enabled).
Don't forget to bind the server as well:
For the server run iperf -s -B 1.1.10 in terminal
and on another terminal instance for the client run iperf -c 1.1.10 -B 192.168.1.10
This will normally work if your OS doesn't use the loop-back interface by default.

Cannot access app engine application from LAN

I added the --address=0.0.0.0 to GAE arguments in eclipse.
From the same machine I can access the server with:
http://192.168.1.7:8888/createUser.html
http://localhost:8888/createUser.html
http://0.0.0.0:8888/createUser.html
http://127.0.0.1:8888/createUser.html
However if I try to access it from an Android device on the same LAN through http://192.168.1.7:8888/createUser.html I get an "Oops!".
The Android device can ping 192.168.1.7 and vice versa.
I'm using Linux and I don't have any firewall. What's the solution?
Thank you.
EDIT: I also tried to access the page from another PC in the same LAN but didn't work. I also tested the port using telnet: it works from the machine but doesn't work from other devices in the same LAN.
The solution is to open the port 8888 using this command:
sudo /sbin/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 8888 -j ACCEPT

how to connect 2 applications through a pseudo serial port with socat

I am developing an embedded application. It will be running on a full-fledged embedded linux, but will be controlled through commands arriving from the serial port from a windows host.
during the debug phase, this windows host is running in a virtual machine and the embedded application is run locally. As such I would like for these 2 to communicate normally as if a normal usb (to serial) cable was connected between them.
How do I go about it? I have heard of the notion of pseudo ports (/dev/ptyXX) but haven't found any C tutorial to go about it.
I basically expect something like a device node (or 2), so I can assign one node to virtualbox "serial port" settings and assign the other node to my linux applicatio that is currently running on the linux host.
Thank you for your help
EDIT: it looks like socat might be the tool for the job , but I can't quite grab the way it works. I am trying the command:
socat -d -d PTY:link=/home/nass/acm0,raw,echo=0 UNIX-CONNECT:/home/nass/dm0
2013/07/18 17:53:56 socat[13271] N PTY is /dev/pts/10
2013/07/18 17:53:56 socat[13271] N opening connection to AF=1 "/home/nass/dm0"
2013/07/18 17:53:56 socat[13271] E connect(5, AF=1 "/home/nass/dm0", 16): Connection refused
2013/07/18 17:53:56 socat[13271] N exit(1)
Why is the connection refused?
If /home/nass/dm0 is missing, the virtual machine will fail to startup (both in host pipe and host device cases)
I pre-created the node /home/nass/dm0 as a file with touch /home/nass/dm0. how should I setup virtualbox? host device? host pipe?
should dm0 even exist before powering up the virtual machine? if yes, should it be a file created with touch /home/nass/dm0? If it should be a socket, how do I pre-create it?
I realize this is an old question, but I was recently working with socat and virtual serial ports and this cropped up in a google search.
If you want socat to create the unix socket, then use UNIX-LISTEN instead of UNIX-CONNECT:
socat pty,link=/home/nass/acm0,raw,echo=0 unix-listen:/home/nass/dm0
Running the above produces a pty device with a symlink at $HOME/acm0:
$ ls -l ~/acm0
lrwxrwxrwx 1 lars lars 10 Jan 12 23:12 /home/lars/acm0 -> /dev/pts/8
And a Unix socket at $HOME/dm0:
$ ls -l ~/dm0
srwxr-xr-x 1 lars lars 0 Jan 12 23:12 /home/lars/dm0
If you connect to the unix socket and send data, it will be sent out the pty device (and vice-versa). This works, but it may not be what you want. If your Linux application expects to interact with a serial port, then instead of a unix socket you would want a second pty device:
socat pty,link=$HOME/vmside,raw,echo=0 pty,link=$HOME/hostside,raw,echo=0
This creates a pair of connected pty devices (one named vmside and one named hostside). You would connect the vmside pty to your virtual machine, and then you would connect your application (or other serial communication program, like picocom or cu or screen) to hostside.

How to run node.js as non-root user?

I'm running a node.js server, that will serve requests on port 80 amongst others. Clearly this requires the application running as root (on Linux).
Looking at this post (http://syskall.com/dont-run-node-dot-js-as-root) as an example it's clear that there are simple ways to allow node to be run as a non-root user, but I'm wondering if anyone has views on the advantages/disadvantages of the different methods suggested:
code: use setuid() to drop down from root to non-priviledged user after listening on port 80 is established.
using a proxy server of some sort to redirect requests to a port >1024 (and so not need node to run as root)
using IP tables to forward to another port (ditto node would not run as root)
Thanks
Option 1 requires you launch the node server as root. Not ideal.
Option 2 adds overhead to every handled request and adds another failure point to your stack.
Option 3 Is the simplest and most efficient method.
To implement Option 3, add the following to your system init scripts. (/etc/rc.d/rc.local on RedHat based systems like AWS).
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
That will redirect requests from port 80 to port 3000.
(I haven't got enough reputation to add a comment the the one of Matt Browne, so I write this as an answer. Feel free to edit.)
There is a simpler method to load iptables rules automatically after a reboot than the one described in the link of Matt Browne: One can install iptables-persistent from the repositories using apt-get:
apt-get install iptables-persistent
Rules still need to be saved manually like this:
IPv4:
iptables-save > /etc/iptables/rules.v4
IPv6:
iptables-save > /etc/iptables/rules.v6
(Source: http://www.thomas-krenn.com/de/wiki/Iptables_Firewall_Regeln_dauerhaft_speichern (german))
I love the simplicity of this workaround:
sudo setcap 'cap_net_bind_service=+ep' `which node`
It also works for programs other than nodejs btw.
Basically as 2nd parameter you type the path to the program executable (like /usr/bin/nodejs on Ubuntu), in the above case which node should provide it dynamically, thus making this work independently from Linux distro.
Beware though that when you upgrade nodejs or the executable gets overwritten for some other reason you would have to execute that same command again.
Sources:
How to: Allow Node to bind to port 80 without sudo,
Is there a way for non-root processes to bind to "privileged" ports on Linux?

Resources