Data from python script to website The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsRemove a directory level from a website URLStart/stop program from websiteHow to start a GUI program with PHP from websiteSame website, multiple serversApache website access“Unable to connect” to local website running Apache 2 / PHPLocking Website - Weird BehaviourApache and FPM link severed by script timeout
What information about me do stores get via my credit card?
Did the new image of black hole confirm the general theory of relativity?
Match Roman Numerals
Are my PIs rude or am I just being too sensitive?
Program that generates brainfuck code that outputs given text
Why is superheterodyning better than direct conversion?
What are these Gizmos at Izaña Atmospheric Research Center in Spain?
Is above average number of years spent on PhD considered a red flag in future academia or industry positions?
Python - Fishing Simulator
First use of “packing” as in carrying a gun
Is this wall load bearing? Blueprints and photos attached
What is this lever in Argentinian toilets?
Pandas DataFrames: Create new rows with calculations across existing rows
How did the audience guess the pentatonic scale in Bobby McFerrin's presentation?
Why can't devices on different VLANs, but on the same subnet, communicate?
Do warforged have souls?
ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?
Would an alien lifeform be able to achieve space travel if lacking in vision?
How long does the line of fire that you can create as an action using the Investiture of Flame spell last?
Can the prologue be the backstory of your main character?
Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?
How to colour the US map with Yellow, Green, Red and Blue to minimize the number of states with the colour of Green
how can a perfect fourth interval be considered either consonant or dissonant?
Is there a trick to getting spices to fix to nuts?
Data from python script to website
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election ResultsRemove a directory level from a website URLStart/stop program from websiteHow to start a GUI program with PHP from websiteSame website, multiple serversApache website access“Unable to connect” to local website running Apache 2 / PHPLocking Website - Weird BehaviourApache and FPM link severed by script timeout
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
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()
php apache-httpd javascript
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
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()
php apache-httpd javascript
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
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()
php apache-httpd javascript
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()
php apache-httpd javascript
php apache-httpd javascript
edited May 13 '16 at 14:52
Jeff Schaller♦
45k1164147
45k1164147
asked Apr 14 '16 at 18:59
AhsinAhsin
63
63
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
First of all you'll need to create an endpoint in your website.
The simpliest way is to create a file called robot_update.php with the following content.
<?php
$input_data = file_get_contents('php://input');
$decoded_data = json_decode($input_data);
//Do something with $decoded_data, update image or write it to the database.
?>
Next,
Send your data via http from python like so
import json
import urllib2
def update_robot(angle, distance):
data =
'angle' : angle,
'distance' : distance
req = urllib2.Request('http://yourwebsite.com/robot_update.php')
req.add_header('Content-Type', 'application/json')
res = urllib2.urlopen(req, json.dumps(data))
res.read()
Call this function in place where your angle and distance is calculated.
This will work just fine but remember to add proper restrictions to your robot_update.php.
This is all new to me, im sorry. The python script continuously produces a new angle (from 0-180) using a for loop, and within each loop it gives a distance of an object. Can you explain this a bit more, how it would work with my script. i have never seen this before. Will this continuously send each new piece of data produced? in your code you wrote "data-, but my data is continuously produced, its not set. i added my python code to the question, i would just like a small explanation as to how this works.
– Ahsin
Apr 16 '16 at 16:26
Take my python code and create function that takes two parameters (angle and distance). Then call it when your angle and distance is ready. It can be send many times. I'll update my answer.
– Inclooder
Apr 16 '16 at 20:03
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f276533%2fdata-from-python-script-to-website%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
First of all you'll need to create an endpoint in your website.
The simpliest way is to create a file called robot_update.php with the following content.
<?php
$input_data = file_get_contents('php://input');
$decoded_data = json_decode($input_data);
//Do something with $decoded_data, update image or write it to the database.
?>
Next,
Send your data via http from python like so
import json
import urllib2
def update_robot(angle, distance):
data =
'angle' : angle,
'distance' : distance
req = urllib2.Request('http://yourwebsite.com/robot_update.php')
req.add_header('Content-Type', 'application/json')
res = urllib2.urlopen(req, json.dumps(data))
res.read()
Call this function in place where your angle and distance is calculated.
This will work just fine but remember to add proper restrictions to your robot_update.php.
This is all new to me, im sorry. The python script continuously produces a new angle (from 0-180) using a for loop, and within each loop it gives a distance of an object. Can you explain this a bit more, how it would work with my script. i have never seen this before. Will this continuously send each new piece of data produced? in your code you wrote "data-, but my data is continuously produced, its not set. i added my python code to the question, i would just like a small explanation as to how this works.
– Ahsin
Apr 16 '16 at 16:26
Take my python code and create function that takes two parameters (angle and distance). Then call it when your angle and distance is ready. It can be send many times. I'll update my answer.
– Inclooder
Apr 16 '16 at 20:03
add a comment |
First of all you'll need to create an endpoint in your website.
The simpliest way is to create a file called robot_update.php with the following content.
<?php
$input_data = file_get_contents('php://input');
$decoded_data = json_decode($input_data);
//Do something with $decoded_data, update image or write it to the database.
?>
Next,
Send your data via http from python like so
import json
import urllib2
def update_robot(angle, distance):
data =
'angle' : angle,
'distance' : distance
req = urllib2.Request('http://yourwebsite.com/robot_update.php')
req.add_header('Content-Type', 'application/json')
res = urllib2.urlopen(req, json.dumps(data))
res.read()
Call this function in place where your angle and distance is calculated.
This will work just fine but remember to add proper restrictions to your robot_update.php.
This is all new to me, im sorry. The python script continuously produces a new angle (from 0-180) using a for loop, and within each loop it gives a distance of an object. Can you explain this a bit more, how it would work with my script. i have never seen this before. Will this continuously send each new piece of data produced? in your code you wrote "data-, but my data is continuously produced, its not set. i added my python code to the question, i would just like a small explanation as to how this works.
– Ahsin
Apr 16 '16 at 16:26
Take my python code and create function that takes two parameters (angle and distance). Then call it when your angle and distance is ready. It can be send many times. I'll update my answer.
– Inclooder
Apr 16 '16 at 20:03
add a comment |
First of all you'll need to create an endpoint in your website.
The simpliest way is to create a file called robot_update.php with the following content.
<?php
$input_data = file_get_contents('php://input');
$decoded_data = json_decode($input_data);
//Do something with $decoded_data, update image or write it to the database.
?>
Next,
Send your data via http from python like so
import json
import urllib2
def update_robot(angle, distance):
data =
'angle' : angle,
'distance' : distance
req = urllib2.Request('http://yourwebsite.com/robot_update.php')
req.add_header('Content-Type', 'application/json')
res = urllib2.urlopen(req, json.dumps(data))
res.read()
Call this function in place where your angle and distance is calculated.
This will work just fine but remember to add proper restrictions to your robot_update.php.
First of all you'll need to create an endpoint in your website.
The simpliest way is to create a file called robot_update.php with the following content.
<?php
$input_data = file_get_contents('php://input');
$decoded_data = json_decode($input_data);
//Do something with $decoded_data, update image or write it to the database.
?>
Next,
Send your data via http from python like so
import json
import urllib2
def update_robot(angle, distance):
data =
'angle' : angle,
'distance' : distance
req = urllib2.Request('http://yourwebsite.com/robot_update.php')
req.add_header('Content-Type', 'application/json')
res = urllib2.urlopen(req, json.dumps(data))
res.read()
Call this function in place where your angle and distance is calculated.
This will work just fine but remember to add proper restrictions to your robot_update.php.
edited Apr 16 '16 at 20:08
answered Apr 15 '16 at 9:48
InclooderInclooder
30816
30816
This is all new to me, im sorry. The python script continuously produces a new angle (from 0-180) using a for loop, and within each loop it gives a distance of an object. Can you explain this a bit more, how it would work with my script. i have never seen this before. Will this continuously send each new piece of data produced? in your code you wrote "data-, but my data is continuously produced, its not set. i added my python code to the question, i would just like a small explanation as to how this works.
– Ahsin
Apr 16 '16 at 16:26
Take my python code and create function that takes two parameters (angle and distance). Then call it when your angle and distance is ready. It can be send many times. I'll update my answer.
– Inclooder
Apr 16 '16 at 20:03
add a comment |
This is all new to me, im sorry. The python script continuously produces a new angle (from 0-180) using a for loop, and within each loop it gives a distance of an object. Can you explain this a bit more, how it would work with my script. i have never seen this before. Will this continuously send each new piece of data produced? in your code you wrote "data-, but my data is continuously produced, its not set. i added my python code to the question, i would just like a small explanation as to how this works.
– Ahsin
Apr 16 '16 at 16:26
Take my python code and create function that takes two parameters (angle and distance). Then call it when your angle and distance is ready. It can be send many times. I'll update my answer.
– Inclooder
Apr 16 '16 at 20:03
This is all new to me, im sorry. The python script continuously produces a new angle (from 0-180) using a for loop, and within each loop it gives a distance of an object. Can you explain this a bit more, how it would work with my script. i have never seen this before. Will this continuously send each new piece of data produced? in your code you wrote "data-, but my data is continuously produced, its not set. i added my python code to the question, i would just like a small explanation as to how this works.
– Ahsin
Apr 16 '16 at 16:26
This is all new to me, im sorry. The python script continuously produces a new angle (from 0-180) using a for loop, and within each loop it gives a distance of an object. Can you explain this a bit more, how it would work with my script. i have never seen this before. Will this continuously send each new piece of data produced? in your code you wrote "data-, but my data is continuously produced, its not set. i added my python code to the question, i would just like a small explanation as to how this works.
– Ahsin
Apr 16 '16 at 16:26
Take my python code and create function that takes two parameters (angle and distance). Then call it when your angle and distance is ready. It can be send many times. I'll update my answer.
– Inclooder
Apr 16 '16 at 20:03
Take my python code and create function that takes two parameters (angle and distance). Then call it when your angle and distance is ready. It can be send many times. I'll update my answer.
– Inclooder
Apr 16 '16 at 20:03
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f276533%2fdata-from-python-script-to-website%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
-apache-httpd, javascript, php