Wednesday, November 25, 2015

Make Raspberry Pi Serial port available over Ethernet


Make Raspberry Pi Serial port available over Ethernet

To do this on raspberry-pi first install socat.

Then run following commands.

  1. On the raspberry-pi  run following command to redirect tcp data on port 54321 to serial port ttyAMA0

sudo socat tcp-l:54321,reuseaddr,fork file:/dev/ttyAMA0, nonblock, raw, waitlock=/var/run/ttyAMA0.lock

  1. On other connecting(client) linux machine run following command to create a virtual serial port and direct it to tcp port of the raspberry-pi 54321 port.

sudo socat pty,link=/dev/ttyAMA0,waitslave tcp:10.42.0.3:54321

  1. Now when you write to virtual serial port on the linux pc it get to the actual serial port of raspberry-pi over ethernet connection. However this seems to be a blocking the port.
  2. Checked on pi4j read/write on same port and read hangs. So as a solution to this create another virtual serial port on raspberry pi and map it to actual serial port. Then read/write to it. It fixed the problem.

sudo socat PTY,link=/dev/ttyAMA0 PTY,link=/dev/ttyAMA1

Srinath Gamage has attached the following document:
Make Serial port available over Ethernet
Google Docs: Create and edit documents online.Logo for Google Docs

Share Article : Make Raspberry Pi Serial port available over Ethernet
Share/Save/Bookmark

Monday, November 23, 2015

Serial Communication Test on Raspberry-pi


Serial Communication Test on Raspberry-pi

  1. First we have to disable OS from using serial port

1.png

2.png

3.png

4.png

  1. Just for the testing; Connect TxRx pin 8 and 10 on pin header with a jumper(cable).

8-10.png

  1. Then write to Serial port with following python code.

#!/usr/bin/env python

import time

import serial

ser = serial.Serial(

            port='/dev/ttyAMA0',

            baudrate = 9600,

            parity=serial.PARITY_NONE,

            stopbits=serial.STOPBITS_ONE,

            bytesize=serial.EIGHTBITS,

            timeout=1

)

counter=0

while 1:

            print counter

            ser.write('Write counter: %d \n'%(counter))

            time.sleep(1)

            counter += 1

write.png

  1. Use following code to read it

#!/usr/bin/env python

import time

import serial

ser = serial.Serial(

                   port='/dev/ttyAMA0',

                   baudrate = 9600,

                   parity=serial.PARITY_NONE,

                   stopbits=serial.STOPBITS_ONE,

                   bytesize=serial.EIGHTBITS,

                   timeout=1

               )

counter=0

while 1:

  x=ser.readline()

  print x

read.png

Srinath Gamage has attached the following document:
Serial Communication Test on Raspberry-pi
Google Docs: Create and edit documents online.Logo for Google Docs

Share Article : Serial Communication Test on Raspberry-pi
Share/Save/Bookmark

Wednesday, November 11, 2015

Add current RSA keys for password less login


cat .ssh/id_rsa.pub | ssh remoteLoginUser@172.1.1.1  'cat >> .ssh/authorized_keys'

Share Article : Add current RSA keys for password less login
Share/Save/Bookmark