• This topic has 4 replies, 2 voices, and was last updated 7 years ago by amby.
Viewing 4 reply threads
  • Author
    Posts
    • #7929
      lecagnois
      Participant

      Voici un petit bout de code pour envoyer un mail avec prise de photo de la caméra.
      le script pourra être modifier (par exemple) , pour mettre votre robot en mode surveillance de votre maison et envoyé des photos des instrus …… ou avec détection de présence etc ….

      Pour commencer nous allons ajouter les bibliothèques pour l’envoi de mail .

      Si vous utilisez le pack de Anthony et Gael
      il faudra modifier le fichier :
      …/InmoovScript/system/Import_Librairie.py

      Editer le fichier avec NotePAD++ et

      ajouter cela en fin du fichier

      ########## suplement pour mail
      import smtplib
      from email import *
      from email.mime.multipart import *
      from email.mime.text import *
      from email import encoders
      from email.mime.base import *

      Ensuite ajouter ce code dans votre fichier xxxxx.py
      que vous avez mis dans le répertoire :

      …/InmoovScript/inmoovCustom/

      def photoa(destinataire):
      	try:
      		talk(destinataire)
      		print destinataire
      		# creation d un dictionnaire des amis ici que 2 amis
      		dico = {"toto":"toto@wanadoo.fr" , "tata":"tata@gmail.com"}
      		# message si pas trouver
      		if (dico.get(destinataire) == None):
      			print("Amis inconnu dans l annuaire")
      			talk("personne inconnu au bataillon")
      		else:
      			print (dico.get(destinataire))
      			talk(" fais parti de tes amis , regarde moi dans les yeux")
      			i01.opencv.addFilter("pdown","PyramidDown")
      			i01.opencv.setDisplayFilter("pdown")
      			i01.opencv.setCameraIndex(0)
      			i01.opencv.capture()
      			sleep(2)
      			talk("attention le petit oiseau va sortir")
      			sleep(5)
      
                              #ajouter le fichier click.mp3 dans ../system/sound
      			AudioPlayer.playFile(RuningFolder+'/system/sounds/click.mp3')
      			photoFileName = i01.opencv.recordSingleFrame()
      			i01.opencv.removeFilters()
      			sleep(1)
      			i01.opencv.stopCapture()
      			sleep(1)
      			talk("merci la photo est enregistrer , envoi de la photo a " + destinataire)
      			sleep(2)
      
      			#ici adresse de experditeur
      			fromaddr = "toto@wanadoo.fr"
      			toaddr = (dico.get(destinataire))
      			msg = MIMEMultipart()
      			msg['From'] = fromaddr
      			msg['To'] = toaddr
      			msg['Subject'] = "formation python"
      			body = "envoie d un mail avec python test avec piece jointe"
      			msg.attach(MIMEText(body, 'plain'))
      			filename = photoFileName
      
                              #ici le chemin d'acces ou se trouve la photo enregistré par la cam
      			attachement = open("d:/MRL9/inmoov-master/" + photoFileName,"rb")
                              #encodage du mail      
      			part = MIMEBase('application', 'octet-stream')
      			part.set_payload((attachement).read())
      			encoders.encode_base64(part)
      			part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
      			msg.attach(part)
      			# valeur du serveur smtp enlever la securise si serveur gmail
      			server = smtplib.SMTP('smtp.gmail.com', 587)
      			server.starttls()
      			server.login(fromaddr, "VOTRE MOT DE PASSE DE MESSAGERIE")
      			text = msg.as_string()
      			server.sendmail(fromaddr, toaddr, text)
      			server.quit()
      			talk("mel transmis a ," + destinataire)
      
      	except IOError:
      		talk("le serveur est hors service , mail non transmis")
      		
      

      Le fichier click.mp3 doit être ajouté dans le répertoire : ../system/sound

      pour finir voici le fichier AIML à mettre dans le répertoire
      …../InmoovScript/inmoovVocal/bots/fr/aiml/

      	<category>
            <pattern>ENVOYER UNE PHOTO À *</pattern>
            <template>
      		<think><set name="destinataire"><star/></set></think>
      			<oob>
      				<mrl>
      				   <service>python</service>
      				   <method>exec</method>
      				   <param>photoa("<get name="destinataire"/>")</param>
      				 </mrl>
      			</oob>
      			
         	</template>
          </category>
      • This topic was modified 7 years ago by lecagnois.
      Attachments:
      You must be logged in to view attached files.
    • #7933
      lecagnois
      Participant

      Si vous êtes client ORANGE
      Voici le serveur smtp
      smtp-msa.orange.fr port 587

      Il faudra donc modifier les 2 lignes (starttls securité non obligatoire) :
      server = smtplib.SMTP(‘smtp-msa.orange.fr’, 587)
      #server.starttls()

    • #7935
      amby
      Participant

      hey salut lecagnois
      bien sympas ce petit scrip
      je vais l utiliser pour mon robot maintenant qu il a 2 jambes
      merci amby

    • #7938
      lecagnois
      Participant

      Ton InMoov a des jambes ? tu a des photos !

    • #7985
      amby
      Participant

      oui 2 jambes motorisées
      je fais le coffrage pour le moment bientot des photos et videos oui

Viewing 4 reply threads
  • You must be logged in to reply to this topic.