Jump to content

Add data to a database via HTTP


Steeri

This topic is 1691 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies

Hello,

Am a complete noob on this tool and can't get my head around a really (should be) basic task.

I have a database "test" with 2 fields, "Measurepoint" and "CO2", have some raspberry pi's that i want to send data via http that is collected to the filemaker server.

For now i would be happy to get proof of concept to add data from the local machine, kind of http://127.0.0.1/test/Measurepoint=1;CO2=20 and this will generate a new post in database ..

Anyone want to point me in the right direction ?

 

Running a FMP16 server on a mac 10.14

Link to comment
Share on other sites

I do something similar with my RPi's.

Below is the PHP script I use for this purpose. I have a Windows server that runs FMS, and the scripts are located in "C:\Program Files\FileMaker\FileMaker Server\HTTPServer\conf", your Mac will have a similar folder somewhere.

RPiLayout is the layout that is invoked, and RPiStats is the script that is run.

<?php

if ( substr($_SERVER['REMOTE_ADDR'],0,8) != '192.168.' ) { exit; }

require_once ('FileMaker.php');

$RPi_Start    = isset( $_GET['start'] ) ? preg_replace('/[^0-9]/', '', $_GET['start'] ) : "";
$RPi_Finish   = isset( $_GET['finish'] ) ? preg_replace('/[^0-9]/', '', $_GET['finish'] ) : "";
$RPi_Count    = isset( $_GET['imagecount'] ) ? preg_replace('/[^0-9]/', '', $_GET['imagecount'] ) : "";
$RPi_Case     = isset( $_GET['case'] ) ? preg_replace('/[^a-zA-Z0-9]/', '', $_GET['case'] ) : "";
$RPi_Studio   = isset( $_GET['studio'] ) ? preg_replace('/[^a-zA-Z0-9]/', '', $_GET['studio'] ) : "";
$RPi_Folder   = isset( $_GET['folder'] ) ? preg_replace('/[^a-zA-Z0-9-]/', '', $_GET['folder'] ) : "";

$fm = new FileMaker(); 
$fm->setProperty('database', 'DatabaseName'); 
$fm->setProperty('hostspec', 'http://localhost'); 
$fm->setProperty('username', 'username'); 
$fm->setProperty('password', 'password'); 

$param = '';
foreach( $_GET as $key => $value) {
         if( $param === "" ) {
             $param = $param . $key . "=" . $value;
             } else {
             $param = $param . "&" . $key . "=" . $value;
             }
         }
echo $param."<br>";

if( $RPi_Start === "" or $RPi_Finish === "" or $RPi_Count === "" or $RPi_Case === "" ) {
    if( $RPi_Start === "" ) echo 'missing Start time/date<br>';
    if( $RPi_Finish === "" ) echo 'missing Finish time/date<br>';
    if( $RPi_Count === "" ) echo 'missing Image Count<br>';
    if( $RPi_Case === "" ) echo 'missing Case Name<br>';
    if( $RPi_Studio === "" ) echo 'missing Studio Code<br>';
    if( $RPi_Folder === "" ) echo 'missing Folder Name<br>';
  } else {
    $newPerformScript = $fm->newPerformScriptCommand('RPiLayout', 'RPiStats', $param); 
    $result = $newPerformScript->execute();
    echo 'OK';
  }

?>

RPiStats processes the provided parameters ($param) and creates a new record, populating the fields with values from $param. Nowadays I built a JSON string in PHP and pass that on to FM, which is easier to process. But the above works nonetheless, it's just a bit more work in the script.

Make sure you assign the correct permissions for the username, and enable PHP on the server.

On the RPi I send data to FMS using the below curl command:

curl -f 'http://192.168.1.1/RPiStats.php?start='$START'&finish='$FINISH'&imagecount='$IMAGECOUNT'&case='$CASE'&studio='$STUDIO'&folder='$FOLDER

 

  • Like 1
Link to comment
Share on other sites

This topic is 1691 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.