Use RaspberryPi for simple Telepresence Sistem


with a raspberry pi(or other devBoards) will be possible send command trough a db,
is an alternative in case need to cacth data from a sensor or send more
command to the motors or for to take remote control of other things like:
electrovalve,relay ecc....
for this work i used the pymysql library with python3
for install the library with pip need to digit in linux terminal:
pip3 install pymysql
below you can see the python code for insert or catch data from a db

Python code for take control of 4 motors from walkeremote website


from pynput.mouse import Button, Controller
import pymysql.cursors
import RPi.GPIO as GPIO
import time
import subprocess              #for remote reboot
from threading import Timer
from RpiMotorLib import RpiMotorLib



GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
nord=[21,20,16,12]
sud=[12,16,20,21]

mymotor=RpiMotorLib.BYJMotor('MyMotorOne','28BYJ')  #Stepper Motor
GPIO.setup(21,GPIO.OUT)
GPIO.setup(20,GPIO.OUT)   #GPIO Pins connected to driver L298n
GPIO.setup(16,GPIO.OUT)
GPIO.setup(12,GPIO.OUT)
GPIO.setup(4,GPIO.OUT)
GPIO.setup(22,GPIO.OUT)   #GPIO Pins connected to driver L298n
GPIO.setup(23,GPIO.OUT)
GPIO.setup(24,GPIO.OUT)
GPIO.setup(5,GPIO.OUT)
GPIO.output(4,GPIO.HIGH)
#stepper

#date of access to your db     #your db credentials
db=pymysql.connect(host="",port=3306,user="",password="",db="",charset="utf8mb4")   
cursor=db.cursor()
sql="SELECT comandi FROM pilotino" #table and row
cur=cursor.execute(sql)
result=cursor.fetchone()



GoHeadTime="SELECT gohead from MotionTime"
time1=cursor.execute(GoHeadTime)
result1=cursor.fetchone()

GoBottomTime="SELECT gobottom from MotionTime"
time2=cursor.execute(GoBottomTime)
result2=cursor.fetchone()

GoRight="SELECT goright from MotionTime"
time3=cursor.execute(GoRight)
result3=cursor.fetchone()

GoLeft="SELECT goleft from MotionTime"
time4=cursor.execute(GoLeft)
result4=cursor.fetchone()

Gorallent="SELECT goralle from MotionTime"
time5=cursor.execute(Gorallent)
result4=cursor.fetchone()

for a in result1:
           print(a)
           
for b in result2:
          print(b)
         
for d in result3:
          print(d)
          
for c in result4:
          print(c)

for e in result5:
          print(e)
         
def check():
    if(cur > 0):
         for x in result:
             if(x=="h"):                        #your command selected 
                    print("left")              #from walkeremote.com
                    GPIO.output(22,GPIO.HIGH)  #right
                    GPIO.output(23,GPIO.LOW)
                    GPIO.output(24,GPIO.HIGH)
                    GPIO.output(5,GPIO.LOW)
                    time.sleep(float(c))                #your time selected     
                    GPIO.output(22,GPIO.LOW) #from walkeremote.com
                    GPIO.output(23,GPIO.LOW)
                    GPIO.output(24,GPIO.LOW)
                    GPIO.output(5,GPIO.LOW)
                    via()
                    #Timer(5, via).start()
                    
             if(x=='nord'):
                  print('nord')
                  mymotor.motor_run(sud, .1/50,30,False,False,'half', .100)
                  
                  via()
             
             
             
             if(x=='sud'):
                  print('sud')
                  mymotor.motor_run(nord, .1/50,30,False,False,'half', .100)
                  via()
                              
                    
             if(x=="g"):
                    print("right")
                    GPIO.output(22,GPIO.LOW)  #left
                    GPIO.output(23,GPIO.HIGH)
                    GPIO.output(24,GPIO.LOW)
                    GPIO.output(5,GPIO.HIGH)
                    time.sleep(float(d))
                    GPIO.output(22,GPIO.LOW)
                    GPIO.output(23,GPIO.LOW)
                    GPIO.output(24,GPIO.LOW)
                    GPIO.output(5,GPIO.LOW)
                    via()
              
              
             ifx=="s"):
                    print("stop")
                    GPIO.output(22,GPIO.LOW)   #stop
                    GPIO.output(23,GPIO.LOW)
                    GPIO.output(24,GPIO.LOW)
                    GPIO.output(5,GPIO.LOW)
                    via()
                    #Timer(0.50, via).start() 
              
              
              
             if(x=="b"):
                    print("bottom")
                    GPIO.output(22,GPIO.LOW)  #bottom
                    GPIO.output(23,GPIO.HIGH)
                    GPIO.output(24,GPIO.HIGH)
                    GPIO.output(5,GPIO.LOW)
                    time.sleep(float(b))
                    GPIO.output(22,GPIO.LOW)
                    GPIO.output(23,GPIO.LOW)
                    GPIO.output(24,GPIO.LOW)
                    GPIO.output(5,GPIO.LOW)
                    via()
              
             if(x=="ra"):
                    print("GoRallent")
                    GPIO.output(22,GPIO.HIGH)  #gorallent
                    GPIO.output(23,GPIO.LOW)
                    GPIO.output(24,GPIO.LOW)
                    GPIO.output(5,GPIO.HIGH)
                    time.sleep(float(a))
                    GPIO.output(23,GPIO.LOW)
                    GPIO.output(24,GPIO.LOW)
                    GPIO.output(5,GPIO.LOW)
                    via()
                   
                   
                    
                    
             if(x=="y"):
                    print("go")
                    GPIO.output(22,GPIO.HIGH) #avanti
                    GPIO.output(23,GPIO.LOW)
                    GPIO.output(24,GPIO.LOW)
                    GPIO.output(5,GPIO.HIGH)
                    time.sleep(float(e))
                    GPIO.output(22,GPIO.LOW)
                    GPIO.output(23,GPIO.LOW)
                    GPIO.output(24,GPIO.LOW)
                    GPIO.output(5,GPIO.LOW)
                    via()
                    
                    #Timer(10, via).start()
                    
                    
                                          
                                        
                    
    if(cur==0): 
          print("no command inserted") 
          quit()
     
    via(    
           
def via():
    canc="delete from pilotino"
    cursor.execute(canc)
    db.commit()
    quit()    


#For reboot the remote linux machine
#Insert the word reboot in first form and send.
#Or insert the word answer for to move the cursor
#Over the answer button of remote notebook videocalled

if(a=='reboot'):
          subprocess.Popen(['sudo','reboot','-h','now']) 
    

if(a=='answer'):
          mouse.Controller()
          mouse.position=(x,y)              #add in xy the coordinate
          mouse.press(Button.left)          #of your answer button for 
          mouse.release(Button.left)        #to answer from remote
          time.sleep(10)                                  


check() 

php page to send data control to db


script Python,php,sh in action in the video below


and this is for send data sensor to DB


from gpiozero import CPUTemperature
from datetime import datetime    
from threading import Timer
import pymysql.cursors
import Adafruit_DHT
cpu=CPUTemperature()
internal=(cpu.temperature)
sensor=Adafruit_DHT.DHT11
pin=17
humidity,temperature = Adafruit_DHT.read_retry(sensor,pin)

db=pymysql.connect(host="",port=,user="",password="",db="",charset="")

cursor=db.cursor()
data1=datetime.now()

    #time.sleep(0.1)
#sql= "insert into users (datetime,temp,hum) values (%s,%s,%s)"
#cursor.execute(sql,(data1,temperature,humidity))
#sql="SELECT * FROM users"
        
def tira():
    canc="delete from users"
    cursor.execute(canc)
    db.commit()
    quit()
    #Timer(5.0, rimbalzo).start()

def rimbalzo():
    humidity,temperature = Adafruit_DHT.read_retry(sensor,pin)
    data1=datetime.now()
    sql= "insert into users (datetime,temp,hum,password) values (%s,%s,%s,%s)"
    cursor.execute(sql,(data1,temperature,humidity,internal))
    db.commit()
    Timer(10.0, tira).start()
    
rimbalzo()



#db.commit()
#cursor.execute(sql)
#result=cursor.fetchall()

#for r in result:
      #print(r)




in this last every 15 second the R.Pi send
the data of CPU temperature humidity and time
to Db , the sensor is an DTH11 and later 10 second
when go out from function "rimbalzo" go to function "tira"
cancel all data from db and rewrite the data upgraded
an exemple of this code in action is in this
page


HOW TO USE AN OLD NOTEBOOK WITH AN ACTIONOISENOISEBOARD(WHIT DB)



If you have some old notebook that you want
to use like a telepresence sistem,
first of all is necessary to install a light os
like for example the raspbian desktop available
here(raspberryPiDesktop)
download iso and create a pen drive bootable
to install to the old notebook.

So now choose a web videocall service
like for example Google duo,jitsy,skype ecc...
set the autostart web page and bash file:
for this operation create a bash file with sh extension name
like this:



#!/bin/bash
sleep 10
@chromium-browser --kiosk --disable-session-crashed-bubble --disable-infobars --disable-restore-session-state https://YourVidecallLink

add the permission to file
with sudo chmod 777 yourfile.sh
now set the autostart of your bash file created
in terminal digit the address of directory were is the autostart file:

cd ../../etc/xdg/lxsession/LXDE-pi
sudo nano autostart

later the last string add this string for to call the bash created in startup file:

@lxterminal -e /home/pi/yourscript.sh
and below also other bash file you prefer
to start later for python script ecc...


press
ctrl+x
y
enter
With This Command In Terminal: sudo alsactl store
the volume out of headphone still the same for other
future reboot of raspi,is fundamental to set a correct Volume
is recommended set to 25%.For Set VOlume digit "alsamixer"
in terminal and digit up or down arrowKey of keyboard.
If operate from terminal(without a keyboard) can set the volume with this string:
"amixer -q -M sset Headphone 50%" (instead of 50% can change with 25% recommended)
Don't forget to digit before to reboot: sudo alsactl store
for keep the setting in next reboot
reboot the sistem and wait about 10-15 sec.

now can see the chromium browser opened in kiosk mode with your videocall link.
for answer from remote to a videocall in the script below
i used the pynput.mouse library,
in the end of the script instead of x y
need add the parameters of mouse cursor
for stay over the answer button and click it
in this webpage
can catch it and replace them with number.
When you will write in the form of Temp the word
answer, the cursor will go over the answer button
for open the videocall from remote
or if you will write reboot the remote sistem
will reboot.

In the python script below i used
the pygame library ,for to play
tha audio frequencyes
to trigger the Actionoiseboard
pinout,
Instead of Raspberry GPIO.
The Actionoiseboard is
connected with audio
jack to the old notebook.



from pynput.mouse import Button, Controller        
import pymysql.cursors              #need to install the library             
import time                         #pip3 install pynput
from threading import Timer         #pip3 install time
import pygame                       #pip3 install pygame
import subprocess                   #pip3 install pymysql
pygame.mixer.init()

#date of access to your db
db=pymysql.connect(host="",user="",port=,password="",db="",charset="") 
cursor=db.cursor()
sql="select comandi from pilotino"     
cur=cursor.execute(sql)
result=cursor.fetchone()

com="SELECT gohead from MotionTime"
time1=cursor.execute(com)
result1=cursor.fetchone()


for a in result1:
           print(a)


   
def check():
    if(cur > 0):
         for x in result:
             if(x=="h"):
                    print("left")
                    pygame.mixer.music.load('audioCommand/left.mp3')   
                    pygame.mixer.music.play()        #audioCommand available in 
                                                      #actionoise.com webPage
                    time.sleep(1)                      #to homepage download section
                    via()                                            
                    
             if(x=="nord"):
                    print("NordFrame")
                    pygame.mixer.music.load('audioCommand/nord.mp3')
                    pygame.mixer.music.play()
                    time.sleep(1)
                    via()      
               
               
             if(x=="g"):
                    print("right")
                    pygame.mixer.music.load('audioCommand/right.mp3')
                    pygame.mixer.music.play()
                    time.sleep(1)
                    via()
                    
                    
             if(x=="sud"):
                     print("sud")
                     pygame.mixer.music.load('audioCommand/sud.mp3')
                     pygame.mixer.music.play()
                     time.sleep(1)
                     via()
              
              
             if(x=="s"):
                    pygame.mixer.music.load('audioCommand/sttop.mp3')
                    pygame.mixer.music.play()
                    time.sleep(1)
                    print("stop")
                    via()              
              
              
             if(x=="b"):
                    print("bottom")
                    pygame.mixer.music.load('audioCommand/bottom.mp3')
                    pygame.mixer.music.play()
                    time.sleep(1)
                    via()
              
             if(x=="y"):
                    print("goNostop")
                    pygame.mixer.music.load('audioCommand/longstraight.mp3')
                    pygame.mixer.music.play()
                    time.sleep(1)
                    via()     
                    
                    
                    
             if(x=="ra"):
                    print("go")
                    pygame.mixer.music.load('audioCommand/slowstraight.mp3')
                    pygame.mixer.music.play()
                    time.sleep(1)
                    via()
              
                    
             if(x=="Aremote"):
                     print("A-relay command sent")
                     pygame.mixer.music.load('audioCommand/Aremote.mp3')   
                     pygame.mixer.music.play()
                     time.sleep(1)
                     via()
  
                
              if(x=="Bremote"):
                     print("B-relay command sent")
                     pygame.mixer.music.load('audioCommand/Bremote.mp3')   
                     pygame.mixer.music.play()
                     time.sleep(1)
                     via()    

               if(x=="Cremote"):
                     print("C-relay command sent")
                     pygame.mixer.music.load('audioCommand/Cremote.mp3')   
                     pygame.mixer.music.play()
                     time.sleep(1)
                     via()

               if(x=="Dremote"):
                     print("D-relay command sent")
                     pygame.mixer.music.load('audioCommand/Dremote.mp3')   
                     pygame.mixer.music.play()
                     time.sleep(1)
                     via()

             
                if(x=="Eremote"):
                     print("E-relay command sent")
                     pygame.mixer.music.load('audioCommand/Eremote.mp3')   
                     pygame.mixer.music.play()
                     time.sleep(1)
                     via()
                                         
                                        
                    
    if(cur==0): 
          print("no command inserted") 
          quit()
          
     
    via

      
def via():
    canc="delete from pilotino"
    cursor.execute(canc)
    db.commit()
    quit() 


#reboot from your remote p.station
#in walkeremote.com webpage

if(a=='reboot'):        
         subprocess.Popen([ 'sudo','reboot','-h','now'  ])    


if(a=='answer'):
           mouse=Controller()
           mouse.position=(x,y)                    #xy coordinates of    
           mouse.press(Button.left)                #cursor over the answer
           mouse.release(Button.left)              #button
           time.sleep(10)     #remember to change the command in 10 secs


check() 
   


In the short video
there is installed in an old
notebook the Raspbian OS
in permanentrly usb pendrive,
and for universal
use with all old and new notebook




Is necessary to create
also a bash script for
to execute every second
the python script above,
This one every second
will check if there are
data in DB
and if the condition is true
will execute the audio
frequencies for Actionoiseboard
Pinout
and to cancell later with
the function via()

This is the bash file
Can use the same for other script:


#!/bin/bash
while true;
do
python3 YourPyScript.py;done



For create the raspbian
pendrive for notebook
all necessary is in this
Linkwhere
i used Debian buster with raspberry
pi desktop compatible with
pc nd mac.
About command Page i used the
same php page above.
With this method
you can reuse old computer
and also you can have the audio
channel free for your videcall.