30 de octubre de 2021

How to measure Temperature and Humidity from two DHT22 sensors conected to Raspberry-Pi and Python3

For this project I used 2 DHT22 sensors modules that include the resistor.

Sensor has 3 wires to connect to GPio: Data, GND and VCC (+5V or 3.3V).

Can be use 5V or 3.3V to provide power to sensor.

With 3.3V sometimes DHT22 sensor did no respond or lost the connection (?), in my case using 5V solve the problem.

Script are coded in Python3, let's install previously the libraries. 

 

   1) The Python script:

#!/usr/bin/python3
####################################################
# (C)by MisNotasLinux 2021
# DHT22_01: data wire to gpio 23

# DHT22_02: data wire to gpio 24
# Conect VCC of
DHTs to 5V or 3.3V rpi gpio pin.
# Conect GND of DHTs to GND rpi gpio pin.
####################################################

import Adafruit_DHT
import time
import datetime

DHT_SENSOR = Adafruit_DHT.DHT22
DHT_01 = 23   # data rpi gpio pin for dht sensor 01
DHT_02 = 24   #
data rpi gpio pin for dht sensor 02

t = 10    # time for repeat measurement

while True:
    print(datetime.datetime.now())
    print("----------------------------------------------")

    h01, t01 = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_01)

    if h01 is not None and t01 is not None:
        print("Temp_01={0:0.1f}*C  Humidity_01={1:0.1f}%".format(t01, h01))
    else:
        print("Failed to retrieve data from humidity sensor 01")

    h02, t02 = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_02)

    if h02 is not None and t02 is not None:
        print("Temp_02={0:0.1f}*C  Humidity_02={1:0.1f}%".format(t02, h02))
    else:
        print("Failed to retrieve data from humidity sensor 02")

    print("Sleeping " + str(t) + " sec ...")
    print("----------------------------------------------")

 

   2) References:

https://github.com/adafruit/Adafruit_Python_DHT

19 de octubre de 2021

Cambiar el Sistema Operativo por defecto al arranque en Linux Mint 20


En Linux Mint 20 instalado con multi SO boot con Windows no aparece /etc/default/grub (????)

http://misnotaslinux.blogspot.com/2020/06/linux-mint-193-tricia-y-window10-con.html

De modo que no puedo aplicar la solución indicada en:

http://misnotaslinux.blogspot.com/2010/10/menulst-de-grub2.html

tampoco me permite cambiar el sistema operativo por edefecto usando BootReapair (???)

http://misnotaslinux.blogspot.com/2012/06/arreglar-el-mbr-con-boot-repair.html

 -

Finalmente he podido cambiar el sistema operativo que arraca por defecto al iniciar el ordenador con grub2 del siguiente modo:

# grub-set-default 0
# update-grub 

Siendo "0" el primer sistema operativo que aparece en el menu de arranque de grub2.

Ref.: https://askubuntu.com/questions/148662/how-to-get-grub2-to-remember-last-choice


17 de octubre de 2021

How to install Grafana in Rpi

https://grafana.com/


Protocol:

1)  Detect my RPi CPU:

    $ cat /proc/cpuinfo
        processor    : 0
        model name    : ARMv6-compatible processor rev 7 (v6l)
        BogoMIPS    : 697.95
38.40
        ..

         So my RPi B+ ARMv6 cpu.

2) Download Grafana for ARMv6

from https://grafana.com/grafana/download?platform=arm

Choose the version corresponding with the cpu, copy and execute commans in your RPi console.

Ubuntu and Debian(ARMv6)

    $ sudo apt-get install -y adduser libfontconfig1
    $ wget https://dl.grafana.com/oss/release/grafana_7.3.6_armhf.deb
    $ sudo dpkg -i grafana_7.3.6_armhf.deb

     ...

    ### NOT starting on installation, please execute the following         statements to configure grafana to start automatically using         systemd

     sudo /bin/systemctl daemon-reload
     sudo /bin/systemctl enable grafana-server

    ### You can start grafana-server by executing
     sudo /bin/systemctl start grafana-server

Execute the indicated command if you want start Grafana at boot.  


3) Start Grafana server:

    $ sudo service grafana-server start
 

4) Web Access to Grafana:

Using web browser in address [Grafana host IP]:3000

 

5) First login to Grafana:

Default user: admin
Default password: admin

Change your password and enter into Grafana:



7) Create new source of data from MariaDB

If you have your database in different host, allow remote access in database server: http://misnotaslinux.blogspot.com/2021/10/allow-access-to-mysqlmariadb-from.html

Add new data source:


Select MySQL:

 

Fulfill database access data:

 

... Save&Test

 

8) Make a Grafana panel

 

 Start to design graph, tables, etc.

 

Links:

https://andreea-sonda31.medium.com/monitor-raspberry-pi-resources-and-parameters-with-grafana-board-part-1-ab0567303e8

https://websiteforstudents.com/allow-remote-access-to-mariadb-database-server-on-ubuntu-18-04/

How to Backup and Restore MariaDB/MySQL databses


This is a clear tutorial about:

https://phoenixnap.com/kb/how-to-backup-restore-a-mysql-database




En resumen:

Backup:

sudo mysqldump -u [user] -p [database_name] > [filename].sql

 

Restore:

mysql -u root -e "CREATE DATABASE database_name"

mysql -u [user] -p [database_name] < [filename].sql

16 de octubre de 2021

Allow access to MySQL/MariaDB from remote hosts

Edit mariadb.conf:

# nano /etc/mysql/mariadb.conf.d/50-server.cnf

    change:    bind-address = 127.0.0.1

    for:           bind-address = 0.0.0.0

# service mariadb restart


This allow access from all universe IPs, it can dangerous, is better limit access to localnet.

For example:

                bind-address = 192.168.1.0  

 

Grant access from remote host:

    with all privileges:

            GRANT ALL ON database_name.* TO 'database_user@localhost' IDENTIFIED BY                     'database_user_password';

    Only read data (select): 
            GRANT SELECT ON *.* TO 'user'@'localhost' IDENTIFIED BY 'password';
    and
    FLUSH PRIVILEGES;