Run python program on start-up

Problem:
You need to run a python program or report once raspberry pi start-up.

Solution:
You can do this editing you rc-local file, you add the next entry and pay especial attention on bash method to ensure that you run the program with the specific software version.


sudo bash -c '/usr/bin/python3 /home/pi/progra.py > /home/pi/log.txt 2>&1' &
Light  Explanation:
sudo allow you to run the program with admin privilege, 
bash allow to specify the software version pf pyhton
> create a file with the result of the program execution


Remember that the rc.local fine need to end with a exit 0 in the final line

pink colored images on Raspberry PI Noir V2 camera

Problem:
You detect that the Pi Noir V2 camera take pictures in a pink color mask for day pictures.

Solution:
It's fixed after execute the next command:
sudo vcdbg set awb_mode 0 

Source:
https://github.com/raspberrypi/firmware/issues/1167


wifi headless setup

Problem:
you need to setup the wifi connection and you don't have a display to do it trough graphic interface.

Solution:
You can plug the microSD card into a computer,a new Disk Unit will be available, there you can create a new file (wpa_supplicant.conf) for the wifi configuration file with the details example as you can see later in this same post.
If you have access to the command line ( you have a display ), you can do it using the command line tool once you are connected using ssh, just open the file wpa_supplicant.conf using the following commands:
# manual edition of the filesudo nano
  sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
# launch the config setup tool
 sudo raspi-config


Just edit the file with the correct SSID and password in the file that have to lloks like:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<Insert 2 letter ISO 3166-1 country code here>
network={
 ssid="<Name of your wireless LAN>"
 psk="<Password for your wireless LAN>"
}

Source:
https://www.raspberrypi.org/documentation/configuration/wireless/headless.md

Hardware:
For old raspberry PI, you will need an wifi USB key like this:
TP-Link TL-WN725N Adaptador WiFi USB inalámbrico Nano, Compatible con Raspberry Pi, N 150 Mbps, Botón WPS, AP soft Windows10/8.1/8/7/XP, Mac OS X 10.7-10.11, Linux, negro

list file content into text file with pyrhon

problem:
You need to add into a text file the name of all files in a folder, usually you can use the following command sudo ls *.jpg > stills.txt but you get an error:
"unable to execute /bin/ls: Argument list too long"
this is because the sentence is too long because linux can not hold all content in memory if the folder have an huge amount of data.

solution:
You can use python as a workarund, use the following code to create a text file fith the name of all files in a folder or directory.

import os
from os import listdir
from os.path import isfile, join
#folder that hold the files, in my case 70.000,00
dirName = '/media/USB128/SHARED/RingBell/pictures/'
#crete and array
fileNames=[f for f in listdir(dirName) if isfile(join(dirName, f))]
#empty the file is it was previouly filled
open('file.txt', 'w').close()
#loop and write line by ñine each filename
for file in os.listdir(dirName):
f = open("./stills.txt", "a+")
f.write("/media/USB128/SHARED/RingBell/pictures/"+file+"\n")
f.flush() 
f.seek(0)
f.close()

Change Time Zone on Raspberry Pi

Problem:
Beside you select the time zone correctly ( most of it ) trough command raspi-config, you detect that the system don't use the correct time, in some countries there is a gap in the time zone calculator of it can be possible to use diferents time zones in the same country.

Solution:
it's as simple as launch the next command and follow the instructions:
sudo dpkg-reconfigure tzdata

Source:

Remote access trought SSH

Problem:
You need to access to your local server from outside of local network using SSH from the command line.

Solution:
You need to map a port in your firewall to allow the firewall pass the remote access connectin from ou public IP access to your local server, for that search port forwarding configuration and map there you raspberry local IP, now you can create an external connection  to your raspberry if you user your public IP and the selected port.

Use the following steps to jump between any raspberry system:

1.- simple remote access connection using the same user.

sudo ssh hostname/ipaddress

2.- change the user

sudo ssh user@hostname

3.- close the session

sudo exit