skip to Main Content

Raspberry Pi – collects temperature data and stores in a file

Server – Apache, on VM, hosts website (HTML, PHP + JavaScript) with graph of some data

I need to securely send the data file from the Pi to the server, which will use that data file to populate the graph on the website.

What the best the easiest way to accomplish this?

I am relatively new to everything related to this, and have done so much reading and testing, but can’t seem to figure out how to properly do this.

I have two sets of code for the graph, one that uses an SQLite database (ideal) and one that uses a JSON file (works but not the most ideal). Both just use the files stored locally currently.

4

Answers


  1. Run an HTTPS web service on Server B which requires Server A to send a username / password along with the data.

    Login or Signup to reply.
  2. If possible, you can create VPN between both machines.

    Depends on the data sensitivity, HTTPS may be enough + some kind of the API with additional authorization.


    VERY BASIC IMPLEMENTATION

    Apache Server Side

    save.php:

    <?php
        $temperature = $_GET['temperature'];
        $timestamp = $_GET['timestamp'];
        // INSERT into database
        // or
        // save in the file
    

    Pi SIDE

    I don’t know what language you are using in the Pi side, but what you could do is execting HTTP GET request like: https://your.server.ip.or.domain/save.php?temperature=N&timestamp=999999999

    If possible (Pi has fixed IP), you can filter the request based on it. It will make it more secure.

    Login or Signup to reply.
  3. Make the PI save the temperature data to a simple local file. (ideally in a memory hosted partition as SD cards do wear out.)

    Configure a sftp server on the PI.

    Then on the web server pull the file from PHP with

    file_get_contents("ssh2.sftp://{$user}:{$pass}@{$pi_ip}:22{$pi_path}"))
    

    And process it accordingly.

    Login or Signup to reply.
  4. As discussed by many others HTTPS server will be a good start, if you have a registered domain name for your server you can use https://letsencrypt.org/ which provides a handy script certbot that will allow you to convert your existing setup to https.

    In case you don’t have a registered domain, you can self sign a SSL certificate (simple Google will point you to the required resources) and use the same to enable HTTPS on your Apache server.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search