This involves a raspberry pi and apache2 so I thought the question would be good to go here..
have never used web sockets and things like that before so I'm pretty lost and hoping for some guidance...
I have a python script that gives me two pieces of data...the angle of a servo motor and the distance of an object from the ultrasonic sensor.
I need this data to be sent to my website which has a radar imsge. As the angle changes the sweep on the radar image should change, and where there is an obstacle it should show on my radar.
My question is how can I get this data to the website in a continuous way? I have apache2 running on my website. Right now I'm already using Ajax requests to make motors run on my raspberry pi (it's like an RC car).
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
TRIG = 22
ECHO =18
GPIO.setup(TRIG, GPIO.OUT)
GPIO.output(TRIG,0)
GPIO.setup(ECHO, GPIO.IN)
GPIO.setup(33, GPIO.OUT)
pwm=GPIO.PWM(33,100)
pwm.start(5)
time.sleep(0.1)
class rotateRead():
def To180andBackRead():
angle=0
for angle in range(0, 180, 1):
GPIO.setmode(GPIO.BOARD)
duty=float(angle)/10+2.5
pwm.ChangeDutyCycle(duty)
print angle
time.sleep(0.1)
GPIO.output(TRIG,1)
time.sleep(0.00001)
GPIO.output(TRIG,0)
while GPIO.input(ECHO) ==0:
pass
start =time.time()
while GPIO.input(ECHO) ==1:
pass
stop=time.time()
print (stop-start) *17000
angle=180
for angle in range(180, 0, -1):
GPIO.setmode(GPIO.BOARD)
duty=float(angle)/10+2.5
pwm.ChangeDutyCycle(duty)
print angle
time.sleep(0.1)
GPIO.output(TRIG,1)
time.sleep(0.00001)
GPIO.output(TRIG,0)
while GPIO.input(ECHO) ==0:
pass
start =time.time()
while GPIO.input(ECHO) ==1:
pass
stop=time.time()
print (stop-start) *17000
for x in range(0,1,1):
To180andBackRead()
GPIO.cleanup()
Asked by Ahsin
(21 rep)
Apr 14, 2016, 06:59 PM
Last activity: Jan 22, 2025, 01:07 AM
Last activity: Jan 22, 2025, 01:07 AM