Two instances of BusyBox on separate Serial lines (ttySn) - console

I am working on an arm board which has two serial ports, accessible through /dev/ttyS0 and /dev/ttyS1.
Busybox runs on /dev/ttyS0.
I am able to write data on /dev/ttyS1 using 'echo' command like so
#echo "microMolvi" > /dev/ttyS1
I was wondering if there is a way to run another instance of busybox(shell) on /dev/ttyS1, so that I may be able to work with two virtual terminals simultaneously.

After some research I found out that the first shell, that runs on ttyS0, was configured to behave so in the /etc/inittab file.
This line in /etc/inittab was responsible for invocation of the default shell at ttyS0:
ttyS0::respawn:/sbin/getty -L ttyS0 38400 vt100 # GENERIC_SERIAL
So, based on my gut feeling, I put a getty on the second serial port by adding the following line in /etc/inittab
ttyS1::respawn:/sbin/getty -L ttyS1 38400 vt100 # GENERIC_SERIAL
It worked like a charm.
Hope this helps someone someday.

Related

Sending AT command through bash script

I'm testing some satellital modem with a USB-to-serial (RS232) converter. I have already tested the "connection", and it works. I'm using minicom and am able to capture data sent from one terminal (running one bash script that echoes random numbers) to another.
To make this modem send things, I must send it AT commands to it. What is the best way to do it? Should I just echo the AT command from my bash script? Or is there any better way?
#!/bin/bash
while true;
do
number=$RANDOM
echo $number >/dev/ttyUSB0
sleep 4
done
Thank you for your time!
Since you're talking with a modem, the general way to talk with the modem is to use ModemManager, an application that handles the communication with the modem for you.
If you are unable to use ModemManager or you must use bash for some reason, note that commands must end with a \r\n to be used by the modem. The best way that I have found to do that is to use /bin/echo as follows:
/bin/echo -n -e "AT\r\n" > /dev/ttyUSB0
This ensures that echo will convert the escape characters to the carriage return and newline appropriately.
I got a working answer from for this from here:
https://unix.stackexchange.com/questions/97242/how-to-send-at-commands-to-a-modem-in-linux
First using socat.
echo "AT" | socat - /dev/ttyUSB2,crnl
worked great.
Then I used atinout
echo AT | atinout - /dev/ttyACM0 -
Ultimately I chose socat, because atinout isn't in any repository.

Control remote pi GPIO with domoticz

There are 2 pi in this setup:
- PI-domo: running domoticz
- PI-pump: controlling a pump with one GPIO
Those pi are far away, but can communicate through network. PI-domo has some passwordless ssh login setup to pi-pump, and contains three scripts:
- pump_on.sh: sends value to gpio with ssh to turn pump on and returns 1
`ssh pi#pi-pump -n "echo 0 > /sys/class/gpio/gpio18/value" && echo 1`
pump_off.sh: sends value to gpio with ssh to turn pump off and returns 0
ssh pi#pi-pump -n "echo 1 > /sys/class/gpio/gpio18/value" && echo 0
pump_status.sh: returns 1 if pump is on, 0 if pump is off.
All three scripts work as expected when launched in bash, but I can not find how to call them with domoticz. I created a virtual switch and set those as script:///.....[on off].sh but domoticz doesn't seem to be running any of them. nor could I find a place to read the status...
Any idea or link to a RECENT (working) tutorial would be welcome!
Found the issue: stupid me.
It turns out domoticz process was running as root and root didn't have the key setup for passwordless ssh.
I know that this is a old thread and it is answered already, but I have stumbled on the same issue and found that online answers lacked detail. So, here it goes:
On PI-domo run
sudo su to become root
Generate a new key using ssh-keygen -t rsa -b 4096 -C "nameofyourkey"
Copy your key to PI-pump by using ssh-copy-id -i /root/.ssh/yourkey.pub pi#pi-pump
ssh to pi-pump to test that ssh agent for root is working, and if all is well exit and go back to become a pi user.
Note 1: Although logging in as root of PI-domo, it is critical that pump_off and pump_status.sh contain pi#pi-pump and not root#pi-pump or this approach will fail.
Note 2: Domoticz log indicates that the above process has some error by outputting Error: Error executing script command (/home/pi/domoticz/scripts/pump_off.sh). returned: 65280. Note the 65280 error in particular

Socat: run script in bidirectional tunnel

I am running a tunnel like this:
socat TCP-LISTEN:9090,fork TCP:192.168.1.3:9090
I would like to run a script to execute code with the strings passing through the tunnel.
The script does not change the strings, only processes strings independently but allows passage without changing between both ends.
Is this possible?
You should be able to even alter the communication using this approach:
Prepare a helper script helper.sh which gets executed for each connection:
#!/bin/bash
./inFilter.sh | socat - TCP:192.168.1.3:9090 | ./outFilter.sh
And start listening by using:
socat TCP-LISTEN:9090,fork EXEC:"./helper.sh"
The scripts inFilter.sh and outFilter.sh are processing the client and the server parts of the communication.
Example inFilter.sh:
#!/bin/bash
while read -r l ; do echo "IN(${l})" ; done
Example outFilter.sh:
#!/bin/bash
while read -r l ; do echo "OUT(${l})" ; done
This method should work for line-based text communication (as almost everything is line-buffered).
To make it work for binary protocols wrapping all processes with stdbuf -i0 -o0 might help (see .e.g here) and getting rid of shell is probably a good idea in this case.
Good luck!

printing gatttool notification data in file

I am running sensortag 2650 to read notification from sensor to my computer.I am using gatttool (bluez) to do this.My output gets displayed on the console, while the sensor is on the run. BTW I am using ubuntu 14.0.4.
Now the issue is I am not able to make the output data get written in a file instead of displaying on the console. I tried the normal re-direct >>/> operator but that doesnt work.
I am using the following link, just that I am using Linux on my system instead of Raspberry Pi.
https://github.com/codeplanner/TI-CC2650-1
Any clue would be highly appreciated.
Thanks,
Shankhadeep
Do the following:
sudo gatttool -b XX:XX:XX:XX:XX:XX >> output.txt
Then the terminal won´t show anything. BUT! type connect and press enter.
Now the bluetoothmodule is paired with your device!
Normaly, everytime when you get a notification, this will be write in the output.txt.
I tested it with my bluetooth module HM-10 and a Raspberry Pi and it works!
I know its 6 years too late but:
what worked for me was sudo gatttool -b XX:XX:XX:XX:XX:XX -I >> output.txt
putty_capture
This is not ideal for me because im only interested in the received raw data not the ascii console dump, but it is what OP asked for...
Another option would be to use hcidump with some filters

Setup an ssh jump when the second connection uses gsissh

I can run the following command to accomplish what I am trying to do, however I would like to setup entries in my ~/.ssh/config to handle a transparent jump:
ssh -tt login.domain.org gsissh -tt -p 2222 remote.behind.wall.domain.org
Note that the second hop MUST be made with gsissh, some info can be found here: http://toolkit.globus.org/toolkit/docs/5.0/5.0.4/security/openssh/pi/
AFAIK this precludes the standard use of netcat or the -W flag in the ProxyCommand option in the .ssh/config. I think this is because ssh will try to use ssh instead of gsissh on the intermediate machine.
If I put something like this in my .ssh/config it will hop through to the target machine, but when I exit I will land in a shell on the intermediate machine and it borks my ControlMaster setup—the next time I try to ssh to the final destination I end up on the intermediate machine
Host dest
HostName login.domain.org
PermitLocalCommand yes
LocalCommand gsissh -p 2222 remote.behind.wall.domain.org
Also, it seems that trickery using -L or -R is disabled for security reasons.
I would love some help if anybody has any tips.
Thanks

Resources