2

I have a python script running on my raspberry pi that outputs data from sensors connected to the pi's GPIO input. I need a simple way to have this live data on a server accessible from anywhere. I've looked at django framework but it seems like overkill for what I need to do.

1
  • very very quick and dirty way: use ngrok on raspberry itself to host files quickly over internet Commented May 25, 2017 at 16:29

3 Answers 3

1

You mean something like this?

You can create a static webpage with some JS like so:

<html>
<head>
    <title>My Pi</title>
    <script
      src="https://code.jquery.com/jquery-3.2.1.min.js"
      integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
      crossorigin="anonymous"></script>
</head>
<body>
    <div id="sensor1"></div>
    <a href="javascript:getSensor1()">Get data from sensor 1</a>
    <script type="text/javascript">
        function getSensor1() {
            $.ajax({
                type: "POST",
                url: "cgi-bin/cputemp.py",
                dataType: "html",
                success: function(msg) {
                    document.getElementById('sensor1').innerHTML = msg;
                },
            });
        }
    </script>
</body>

And something like this in a cgi-bin/cputemp.py directory relative to your html page.

#!/usr/bin/python
import cgi;
import cgitb;
import time
cgitb.enable()
import commands
import sys
import string
print "Content-type: text/html\n\n";
mytemp1 = commands.getoutput('/opt/vc/bin/vcgencmd measure_temp | cut -d "=" -f2 | cut -f1')
output = "Pi CPU Temp is: " + mytemp1
print output
Sign up to request clarification or add additional context in comments.

1 Comment

Shouldn't getSensor1() be cputemp2()?
0

You can run a script every x minutes with cron, the script will have to output the values instead of run in loops, and the cron task will be something like:

curl -X POST -d '$(python /path/to/script.py)' http://example.com/receive.php

Comments

0

You can use Flask instead of Django.

And if you don't want to create server you can use third party Application Like ThingSpeak where you can just post data and you can view your data from anywhere.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.