Python Forum
sending data from my raspberry pi to my website
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sending data from my raspberry pi to my website
#1
my question here

I am an embedded systems engineer with just basic understanding of python.
I need to send temperature readings that have been stored in my raspberry pi as an xls file, to my website. after that on the server side, the other team is resposible to parse that data using PHP or whatever.
my responsibility is to make a python script that will send this data to the server.
I know that I have to use urllib in some way, most of the tutorials talk about grabbing and parsing data from a website, but none show how to send data.
if someone could help me with what I am supposed to do, that would be a great help

my code here
Reply
#2
(Sep-05-2017, 04:15 PM)mohitsangavikar Wrote: I need to send temperature readings that have been stored in my raspberry pi as an xls file
xls is a really bad choice when it comes to web commutation.
If the server is not specialty setup to handle xls,then have to upload file as binary and server side has to deal with the whole file.
JSON is the preferred format when it come sending stuff to and from a server.
(Sep-05-2017, 04:15 PM)mohitsangavikar Wrote: I know that I have to use urllib in some way, most of the tutorials talk about grabbing and parsing data from a website, but none show how to send data.
No Requests is the one to use,not urllib.
Here a demo with Flask as server,and i will be sending data from outside into the server with Requests.
app.py:
from flask import Flask, request, jsonify

app = Flask(__name__)
@app.route('/pi', methods=['POST'])
def pi():
    pi_data = request.json
    print(f'Vaule on server {pi_data}') #--> Value on server {'temp': 100, 'temp_1': 150}
    return jsonify(pi_data)

if __name__ == '__main__':
    app.run(debug=True)
Start server with python app.py will be running on http://127.0.0.1:5000/.

pi_data.py:
import requests

data_from_pi = {'temp_1': 100, 'temp_2': 150}
response = requests.post('http://127.0.0.1:5000/pi', json=data_from_pi)
if response.ok:
    print(response.json()) #--> {'temp_1': 100, 'temp_2': 150}
Reply
#3
While I agree that JSON is the way to go for more complicated data, for just sending a couple of values you might also consider using GET statements for simplicity.

For example:

import urllib

url = "http://yourserver.com/webpage.php?temperature=55"
urllib.urlopen(url)
And webpage.php would look something like:

<?php

$temperature = $_GET["temperature"];
print $temperature;

?>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sending data from the form to DB quisatz 6 1,242 Nov-13-2023, 09:23 AM
Last Post: Annaat20
  Scraping Data from Website melkaray 3 741 Sep-22-2023, 12:41 PM
Last Post: melkaray
  Code to retrieve data from a website charlie13255 0 951 Jul-07-2022, 07:53 PM
Last Post: charlie13255
  Is this possible to write a script for checking data from website? WanW 2 1,081 Jun-02-2022, 02:31 AM
Last Post: Larz60+
  Help Sending Socket Data snippyro 0 1,014 Sep-23-2021, 01:52 AM
Last Post: snippyro
  get data (temperature and humidity) from DHT22 into CSV and sending them over the net apollo 0 3,797 Apr-16-2021, 07:49 PM
Last Post: apollo
  Extracting data from a website tgottsc1 2 2,209 Jan-09-2021, 08:14 PM
Last Post: tgottsc1
  please help me in loop i am trying to run this program in raspberry pi by sending msg saifullahbhutta 2 2,298 Jan-27-2020, 02:32 PM
Last Post: saifullahbhutta
  extracting data from json on website larry2311 2 5,038 Feb-09-2018, 01:27 AM
Last Post: larry2311
  sending data to second python script Cyberfly 1 3,132 Jan-29-2018, 10:09 AM
Last Post: Cyberfly

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020