Home » Non classé » Page 3

Category: Non classé

Envoyer des commandes SSH avec paramiko

Un script pour envoyer des commandes SSH avec paramiko.

Ce script permet de contrôler en SSH le robot MRPiZ à partir d’un PC.

#!/usr/bin/env python

import sys, paramiko
import time


hostname = '192.168.42.1' # IP du robot MRPiZ
password = 'raspberry'
username = 'pi'
port = 22

command = 'echo "#MF,30!" > /dev/ttyAMA0'

##################################################################################""

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.load_system_host_keys()
ssh.connect(hostname, port=port, username=username, password=password)


ssh.exec_command(command)

MRPiZ obstacle avoidance

Exemple de gestion des obstacles avec le robot MRPiZ et 5 capteurs de distance ToF:


#!/usr/bin/python

# Mace Robotics (www.macerobotics.com)
 # Author : Mace Robotics
 # Exemple : alarm
 # Date : 30/12/2015
 # Version : 0.1

from mrpiZ_lib import *
 import time, sys
 import random

#main program
 print "Exemple : Obstacle avoidance"

limit = 20
 speed = 45
 speedSlow = 30

try:
 while 1:
 p1 = proxSensor(1)
 p2 = proxSensor(2)
 p3 = proxSensor(3)
 p4 = proxSensor(4)
 p5 = proxSensor(5)
 #-----------------
 if((p1 < limit)or(p2 < limit)) and (p4 > limit):
 turnRight(speed)
 time.sleep(0.5)
 r = random.randint(0,2)
 if (r == 0):
 back(speedSlow)
 elif ((p4 < limit)or(p5 < limit)) and (p2 > limit):
 turnLeft(speed)
 time.sleep(0.5)
 r = random.randint(0,2)
 if (r == 1):
 back(speedSlow)
 elif (p3 < limit):
 r = random.randint(0,3)
 if (r == 0):
 back(speedSlow)
 time.sleep(0.6)
 elif (r == 1):
 back(speedSlow)
 time.sleep(0.9)
 turnRight(35)
 time.sleep(0.5)
 elif (r == 2):
 back(speedSlow)
 time.sleep(0.7)
 turnLeft(35)
 time.sleep(0.5)
 elif (r == 3):
 back(speedSlow)
 elif (p2 < limit) and (p4 < limit):
 turnLeft(35)
 time.sleep(1)
 else:
 forward(speed)
 except:
 print "Fin programme"
 stop()
 print "stop"
 exit()

Envoyer un SMS avec la carte Esus

Envoyer un SMS avec la carte Esus en utilisant le système de notification de Free mobile.

photo_esus_smsV2

Vous avez besoin de votre identifiant Free mobile et de la clé d’identification au service :

Free_sms_V2

Ceci est disponible sur votre espace abonné de Free mobile.

Le programme

Vous devez modifier ces constantes :

  • VOTRE_SSID : le nom du réseau sans Wifi auquel votre carte Esus sera connecter.
  • VOTRE_PASS : le mot de passe de votre réseau Wifi.
  • IDENTIFIANT_FREE : votre identifiant Free mobile.
  • CLE_ID : votre clé d’identification au service.
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

WiFiClientSecure client;
  
const char* ssid = "VOTRE_SSID";
const char* password ="VOTRE_PASS";

const char* host = "smsapi.free-mobile.fr";
const int https_Port = 443;

String url, message_SMS;

void setup()
{
  Serial.begin(9600);
  
  Serial.println();
  
  Serial.print("connexion à ");
  
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  
  Serial.println("Connexion Wifi");
  Serial.println("Adresse IP:");
  Serial.println(WiFi.localIP());

  Serial.print("connection a ");
  Serial.println(host);
  
  if (!client.connect(host, https_Port))
  {
    Serial.println("Erreur de connexion Wifi");
  }

  url = "/sendmsg?user=IDENTIFIANT_FREE&pass=CLE_ID&msg=";
  message_SMS = "Test envoi SMS par la carte Esus!";

  url = url + message_SMS;
  
  Serial.print("URL: ");
  Serial.println(url);

  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "User-Agent: BuildFailureDetectorESP8266\r\n" +
               "Connection: close\r\n\r\n");


}

void loop() 
{
  // rien
}

Fin du tuto !