Data from python script to website The 2019 Stack Overflow Developer Survey Results Are In ...

Accepted by European university, rejected by all American ones I applied to? Possible reasons?

Button changing its text & action. Good or terrible?

Circular reasoning in L'Hopital's rule

One-dimensional Japanese puzzle

Match Roman Numerals

Identify 80s or 90s comics with ripped creatures (not dwarves)

Is 'stolen' appropriate word?

Example of compact Riemannian manifold with only one geodesic.

Using dividends to reduce short term capital gains?

Working through the single responsibility principle (SRP) in Python when calls are expensive

Deal with toxic manager when you can't quit

Why not take a picture of a closer black hole?

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?

The following signatures were invalid: EXPKEYSIG 1397BC53640DB551

What can I do if neighbor is blocking my solar panels intentionally?

60's-70's movie: home appliances revolting against the owners

My body leaves; my core can stay

What was the last x86 CPU that did not have the x87 floating-point unit built in?

What is the padding with red substance inside of steak packaging?

For what reasons would an animal species NOT cross a *horizontal* land bridge?

How to type a long/em dash `—`

Can the DM override racial traits?

How do spell lists change if the party levels up without taking a long rest?

Why don't hard Brexiteers insist on a hard border to prevent illegal immigration after Brexit?



Data from python script to website



The 2019 Stack Overflow Developer Survey Results Are In
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
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 6 hours ago


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 6 hours ago


    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 6 hours ago


      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 6 hours ago


      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







          Popular posts from this blog

          Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

          Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

          Ciclooctatetraenă Vezi și | Bibliografie | Meniu de navigare637866text4148569-500570979m