Operare Raspberry Pi Python Script / PHP Sito Web da C # o Java [chiuso]


Attualmente sto tentando di usare il mio Raspberry Pi come apriporta per garage. Ho usato il codice da YouTube e funziona, ma sto cercando di collegarlo con un'app nativa per Windows Phone e Android.

Voglio eseguire lo script Python tramite un clic del pulsante su un'app nativa su un dispositivo Windows Phone / Android.

Attualmente, ho un sito web con PHP ospitato dal Raspberry Pi che esegue uno script Python:

<html>
<head>
<meta charset="UTF-8" />
<title>Garage Operator</title>
</head>


<?php
if (isset($_POST['OPEN']))
{
exec("sudo python /home/pi/door.py");
}

?>


<form method="post">
<button name="OPEN"> Door</button><br>



</form>
</html>

Ecco lo script Python:

#!/usr/bin/python

# Import required Python libraries
import RPi.GPIO as GPIO
import time

# Use BCM GPIO references instead of physical pin numbers
GPIO.setmode(GPIO.BCM)

# init list with pin numbers

pinList = [2]

# loop through pins and set mode and state to 'low'

for i in pinList: 
    GPIO.setup(i, GPIO.OUT) 
    GPIO.output(i, GPIO.HIGH)

def trigger() :
        for i in pinList:
          GPIO.output(i, GPIO.LOW)
          time.sleep(0.5) 
          GPIO.output(i, GPIO.HIGH)
          GPIO.cleanup()


try: 
    trigger()


except KeyboardInterrupt:
  print "  Quit" 
  # Reset GPIO settings
  GPIO.cleanup()

Il mio primo l'idea era di fare un "clic virtuale" tramite c # o codice Java che utilizza il sito web PHP. Come potrei fare questo? Inoltre, ci sono alternative migliori / più efficienti?

Author: ForeverLearning, 2013-12-06

1 answers

Il tuo PI è connesso a una rete?
1. se sì: puoi facilmente aprire il codice php tramite il PI usando il suo IP
2. Se no, ottenere un dongle wireles per il PI, creare un hotspot con esso in modo da poter connettersi ad esso tramite un telefono

Se vuoi sviluppare un'app nativa per esso (Android o Windows), ti suggerisco di provare a rendere PHP un'API REST.

Ad Es.

http://192.2.2.2/open  
http://192.2.2.2/close

Buona fortuna con il tuo progetto

 1
Author: Acute X, 2013-12-06 04:37:41