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;








1















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()









share|improve this question
















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.





















    1















    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()









    share|improve this question
















    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.

















      1












      1








      1








      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()









      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      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.






















          1 Answer
          1






          active

          oldest

          votes


















          0














          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.






          share|improve this answer

























          • 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











          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
          );



          );













          draft saved

          draft discarded


















          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









          0














          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.






          share|improve this answer

























          • 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















          0














          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.






          share|improve this answer

























          • 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













          0












          0








          0







          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.






          share|improve this answer















          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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          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

















          • 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

















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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

          Popular posts from this blog

          Creating 100m^2 grid automatically using QGIS?Creating grid constrained within polygon in QGIS?Createing polygon layer from point data using QGIS?Creating vector grid using QGIS?Creating grid polygons from coordinates using R or PythonCreating grid from spatio temporal point data?Creating fields in attributes table using other layers using QGISCreate .shp vector grid in QGISQGIS Creating 4km point grid within polygonsCreate a vector grid over a raster layerVector Grid Creates just one grid

          Can I redirect output to a log file and background a process at the same time?2019 Community Moderator ElectionUnable to write to file in shell script when running command in backgroundredirect and log script outputhow to properly log the output of a console program that frequently updates “parts” of the screen, resulting in a messy log file?How can I redirect the output of a child process?grep script - output lines at the same time into echoHow to run process in background and get its pid to create log file nameHow to redirect output to a log from expect commandHow to clear a redirect log file content in shell?Log background jobs started in all the manually started shells?Why do `jobs` and `dirs` run in command subsitution, process substitution, pipeline, and background jobs output the same as in original shell?How to redirect output to file to STDOUT?

          Can I sign legal documents with a smiley face?Do Legal Documents Require Signing In Standard Pen Colors?Is it possible to legally prohibit someone from linking to specific pages on your website?Do scans of signed documents have the same legal power as the original document?What can I do if I signed an excessively restrictive contract?Can other party sneak in new contract terms via termination notice?How to prove that someone forged my signature on a contract that I was not aware of?In Australia, Is it legal to sign a document as somebody else?making a contract that includes video licenceLease dispute, over email and text messageIf you must include all of the natural language prose in a legal document, or if it can be abstracted outE-signing: legal ramifications of “identifying” a person