Python, use proxy for Selenium test automation


You need to make a test script using Selenium with python in a raspberry pi and you don't know how to use it.


Copy and paste the following code in your py file:

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

from fp.fp import FreeProxy

import os

#proxy connection 


 v_proxy = FreeProxy(timeout=0.3, anonym=False, rand=True).get()


  print(' Using Proxy: ', v_proxy)

except Exception as e:

 print(' Error:', e)

#load data

chrome_options = webdriver.ChromeOptions()

chrome_options.add_argument('--proxy-server=%s' % v_proxy)


driver = webdriver.Chrome(options=chrome_options)


Mostrar información del sistema en el inicio de sesión SSH

Es muy útil iniciar sesión para verificar nada más entrar en nuestra Raspberry Pi el estado del sistema, por lo que no sería bueno tener algunos parámetros importantes del sistema, tales como la carga, el tiempo de actividad, la memoria RAM disponible, etc...

Veamos una solución basada en un script de Shell que nos da la información actual del sistema justo después de inicar sesión SSH a través del Mensaje del día, también conocido como MOTD.

Veamos un ejemplo:

Es posible añadir un texto ASCII con generadores ASCII como este: aquí .

Como crear nuestro propio MOTD ?

Primero vamos a crear nuestro propio mensaje dinámico.

Para ello crearemos un archivo con este nombre “dynmotd” en  la siguiente ruta “/ usr / local / bin” y lo editamos con un editor para añadir la información que queremos

sudo nano /usr/local/bin/dynmotd

Raspberry Pi 4 connect it to a computer via USB


In the Raspberry Pi 4, the USB Type-C power jack can also be used for data transfer. This can be used for various useful project purposes and ideas, for example, how to connect to a computer trough USB port as an OTG device. ( USB OTG introduces the concept of a device performing both master and slave roles – whenever two USB devices are connected and one of them is a USB OTG device  source )


1. Turn on a dwc2 driver writing the next line in /boot/config.txt


2. Use the options for using the Raspberry Pi as a USB device connected to a computer

You will be able to create a small FAT32 file system in a file on an SD card that will appear on the computer as a read / write drive

sudo dd if=/dev/folder of=/piusb.bin bs=512 count=2880
sudo mkdosfs /piMyUSB.bin
sudo modprobe g_mass_storage file=/piMyUSB.bin stall=0

For example, using the next Makerfun USB dongle expansion board for your Raspberry Pi Zero, you will be able to attachc your raspberry pi zero to your computer

Download images from amazon from database table image list

You need to download a huge list of images from amazon and the list is in a data base table.

You can create an easy script using request to access to the image url and shutil to copy one by one each image.

import mysql.connector
import shutil
import requests
conn = mysql.connector.connect(
cursor = conn.cursor()
cursor.execute('SELECT * FROM z_images ORDER')
rows = cursor.fetchall()
for row in rows:
  resp = requests.get(row[4], stream=True)
  path = row[4]
  firstpos = path.rfind("/")+1
  v_filename = path[firstpos:lastpos] 
  local_file = "/home/img/"+v_filename
  with open(local_file, 'wb') as out_file:
    shutil.copyfileobj(resp.raw, out_file)

Rapberry pi lens comparation

With the release of the new Raspberry Pi High Quality Camera, you have the option to use different CS-mount senses with your Raspberry Pi. The High Quality Camera is a 12,3 M sensor with a 7.9 diagonal image size, enough for hobby projects and learn about digital photography.

Take a look in the official product page:

The camera have a CS-mount ring adapter and a C-mount, I remember the first time that I got the camera, and when playing with the 9 min and 16 min lenses I got frustrated because I don't remember that you have to use the ring adapter for the 16 min.

Check the official documentation to see how to mount the adapter ring for different lenses.

Camera Specification

Sensor:    12,3 megapixels

Output    RAW, COMP8

Back Focus:    12.5 mm - 22.4 mm

Lens Standard:    CS mount, C-mount ( C-CS adapter included )

Tripod mount:    1/4"


A lens is a device that have a different amount of lenses inside, divergent  and convergent, and with the most cases you can modify the shutter and the focus, there are 3 main topic that you have to adapt to take in consideration before you capture a photograph:
  • Luminosity,  
  • F number, 
  • Focal distance, 

In this picture, you can see the vision angle of different lens focal distance. You can see the relation between a focal distance of the lens and the vision angle raised by the following type of lenses; the numbers of the bellow diagram represent the following lens type:

1.- Fish Eye, an extreme wide-angle lens with a strongly convex front element.
2.- Wide angle lens
a lens that reproduces perspective that generally looks "wider" than a normal lens.
3.- Normal Lense,  a lens with a focal length about equal to the diagonal size of the film or sensor format, or that reproduces perspective that generally looks "normal" to a human observer.
4.- Telean optically compressed version of the long-focus lens. 
5.- Super Tele,

16mm C-Mount Lense

This lens provides a higher quality image than the 6 mm lens but it offer a narrow angle of view which is more suited to viewing distant objects.
This lense comes with a Back focus ring to adjust with a litter screw, you have to screwed it fully once mounted in the camera, this ring is to ensure that the focus will be hard fixed while you adjust the aperture or focus manually.

  • Resolution: 10 mpx
  • Picture Format: 1"
  • Focus Distance:  17.53mm
  • Aperture:  F1.4-16
  • Mount: C Type
  • Dimensions: 39x50 mm
  • Mode: Manual
  • Minimum Macro Dist:  17.53mm
  • Weigh: 133.7 gr. 

  • Angle View:
    1" > 4.6°× 33.6°
    2/3" > 30.0°× 23.2°
    1/1.8" >  24.7°× 18.6°
    1/2" >  21.8°× 16.4°

6mm CS Mount

This lens is the low cost Wide Range version of a raspberry pi lens for the new high quality camera, it's suitable for basic photography and it offer also the possibility to do macro photography because it can focus objects at very short distance.

  • Resolution: 3 mpx
  • Picture Format: 1/2"
  • Focus Distance:  7.53mm
  • Aperture:  F1.2
  • Mount: CS Type
  • Minimum Macro Dist:  7.53mm
  • Dimensions: 30x34 mm
  • Mode: Manual
  • Weigh: 53 gr. 
  • Angle View: 63º

What we can do with this lenses ?

If you check the previous diagram, you will see that we have 2 lens for our Raspberry, 16 mm and 6 mm, if you try to category by the lens type both have to be places as a type 1, Fish Eye type but there are more factors that we have to consider.

As you can see, the 6 mm lens is a basic one for normal photograph pictures. The 16 mm is a very good one but more expensive but it's not a real Tele lense like a large one that have a focus near to 135 mm.

Even that, if you would like to learn about photography bot are very good for it, and if you try to adjust them dynamically using a python program you will have a loot of options to play with Aperture, ISO, exposure, etc... for example to take long expose pictures.

Check this offer from Waveshare where they have other lenses avairables. 

Waveshare Quality Industrial Telephoto Lens with 16mm Focal Length, Multi Field Angle and C-Mount Compatible with Raspberry Pi Camera…

  • 16mm C-Mount Telephoto Lens For Raspberry Pi High Quality Camera
  • 16mm Focal Length High Definition Telephoto Lens, Capturing Every Tiny Details
  • Fitting The Lens To Raspberry Pi High Quality Camera (C-CS Adapter Required)
  • To use with Raspberry Pi Zero, you need to buy an additional Raspberry Pi Zero v1.3 Camera Cable

Scrap Twitter member list using Tweepy in Raspberrypi

You need to populate date in a website and the source of this information is stored in a Twitter list, you need to read information of members in this list.

You can do that scraping the information using Tweepy library, this library help to read information from twitter in a legal way.

First, you will need to create a Twitter app and register the corresponding tokens, etc...
Create you twitter application here: 

This is a sample code to download the name of members in a specific list.

#Twitter bot to read information of members in a list
v_access_token = "**********"
v_access_token_secret = "**********"
v_consumer_key = "**********"
v_consumer_secret = "**********"

import tweepy

auth = tweepy.OAuthHandler(v_consumer_key, v_consumer_secret)
auth.set_access_token(v_access_token, v_access_token_secret)

api = tweepy.API(auth)

public_tweets = api.home_timeline()

slug = 'Twiter-List-Name'
owner = 'Twiter-Name'
list_id = 1153378345425632898

members = []

for page in tweepy.Cursor(api.list_members, list_id=list_id).items():

Tips for using SSH effectively on Raspberry Pi

SSH is a common secure type of remote connection to access to servers or other computers in the same or different network, it's important to remember this few tips for using SSH effectively; you will need it to connect to your Raspberry PI if you don't use a display.
Let's see a few of them:

  • The two-factor authentication for SSH.
  • Use safe agent-forwarding.
  • Exit out of SSH session.
  • leave the terminal open on disconnecting.
  • share a remote connection with friend mates.

Let's start with the first point, you will see that there are different ways to add a second factor for SSH authentication and ensure in this way your connection.

1.- Use hardware tokens (USB Key).

Around February 2020, support for Universal Second Factor tokens was added to OpenSSH connection. This is a great new feature, but there are thinks that we have to consider before to use it.

Around February 2020, support for Universal Second Factor tokens was added to OpenSSH connection. This is a great new feature, but there are thinks that we have to consider before to use it.

Since this update adds new key types to support tokens, it can only be used if you update both the client and server. The current version of the client can be checked with the command ssh -V, for the remote server it depend of the OS, check your OS information to know who to check it.

Two new types of keys were added - ecdsa - skand ed25519 - sk . To create key files, insert your token into your computer and run the command$ ssh -keygen -t ecdsa-sk -f This command will create the public and private keys associated with your token. The private key on the device is used to decrypt the private key file stored on disk.

Also, as a second factor, you can set a password for key files. OpenSSH supports another variant of key generation, a'resident' key. In this case, key files are stored on a token. This way, you will always have your keys with you. 

To transfer a key file to a new machine, insert the key media and execute the command ssh-add -k. You will need to activate your token.

More information:

2.- Safe use of agent forwarding (UNTIL HERE, DRAFT)

SSH key forwarding gives remote host access to your local SSH agent. When your SSH client uses key forwarding, there are 2 channels in the connection:

- Your interactive session.
- The key forwarding channel.

The local SSH agent creates an IPC socket that connects to the remote host through this channel. This is dangerous because a root user on the remote host has access to your local SSH agent and can potentially use it to access network resources on
your behalf. With the standard SSH agent that comes with OpenSSH, you will never know what happened. But if you use a U2F key, you will be able to stop any attempts to use your SSH agent.

Even with this limitation, periodic use of key forwarding is perfectly acceptable.

Do not use this method for all of your connections. Use it only if you are sure you need it in specific situations.

3.- Exit out of SSH session

SSH sessions often hang due to network interruptions, loss of control of a program being executed, or one of the terminal escape sequences that block keyboard input.

Here are some ways to get out of a frozen session:

Automatic logout in case of network failure.

In your SSH configuration files [.ssh/config] you need to add the next command:

ServerAliveInterval 5
ServerAliveCountMax 1

ssh will test the connection by sending echo requests to the remote host every ServerAliveIntervalseconds. If more than ServerAliveCountMaxsuch requests go unanswered, SSH will close the connection.

In this situation you will have sure about the current situation in your server to avoid that any ssh connection remains open without your control.

Terminate the session.
SSH uses a character ~ as the default escape sequence. The command closes the current connection and returns to the terminal.
(remember that you can enter escape sequences only on a new line).

The command  ~? displays a list of commands that can be used in the current session. If you have a keyboard with multiple languages, you may have to press the button ~ twice to send this character.

Leave the terminal open on disconnecting

There are two options for how to save the session when you switch between networks or want to disconnect for a while:

Use Mosh or External Terminal.

If you really need a connection that doesn't drop even if you switch between networks, use Mosh - the mobile shell. Mosh is a secure shell that uses SSH to initialize a session and then switch to its own encrypted channel. This channel is very stable. It can handle a variety of situations, including internet disconnects, changing your laptop's IP address, high network latency, and more.

To use Mosh, you need to install it on both your server and client and open ports for incoming UDP traffic on your remote host. Then just dial mosh user@server connect.

Mosh works at the level of terminal screens and keystrokes, and this gives it many advantages over SSH, which transfers a binary stream of standard I/O between the client and server. If we need to synchronize only the terminal screen and keystrokes, then the interrupted connection can then be restored much faster. SSH would have to buffer and forward whatever happened, while Mosh would only need to store the keystrokes and synchronize the last state of the terminal window with the client.

More information: 

Use tmux.

If you want to connect and disconnect as you please and keep the same session on the remote host, use the tmux terminal. If your SSH connection drops, just connect again and type tmux attach to return to your session tmux. It has some great additional features in tabs and panels, the same as in the macOS terminal and the ability to share the terminal with friends.

Some people improve tmux with Byobu, a package that adds many handy functions and keyboard shortcuts. Byobu ships with Ubuntu and is easy to install on macOS via the Homebrew package manager.

Read more,reattach%20to%20a%20running%20process.

Share a remote connection with friends:

When solving a complex problem in servers in different task, It would be useful to share the SSH session with someone else who is in a different location.

tmux is the best terminal sharing tool for that. So, you need to do the following:

Make sure it is tmux installed on your server.

You both need to connect to the server via SSH using the same account.
One of you must run tmux for the tmux session to be created .
Another has to execute the command tmux attach.


It's done ! You have shared the terminal.