Fermentrack Generic Push Target Payload

Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum

Help Support Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

KnotsmithBrewing

New Member
Joined
Jan 17, 2021
Messages
3
Reaction score
1
Hi all,

Brand new to homebrewing and even newer to using Fermentrack. Everything is functioning as it should be, but I was experimenting with Generic Push Targets. My goal is to push data to a MySql database for inclusion in another website. I was wondering what the payload looks like and how I can ingest it using PHP (preferably). Is anyone familiar with setting something like this up? I've read the documentation and all it mentions is HTTP request. Im not having luck parsing the json.

Thanks in advance, and I look forward to becoming active in this community. Cheers!
-Brian
 
Greetings Brian @KnotsmithBrewing, and welcome to the forums! :mug:

He may pick up on your post, but this would be a great question to pose at the tail of this thread, where the Fermentrack author @Thorrak holds court :) He'll definitely see it there, and the answers will be preserved for posterity in the thread most folks will land on via Search.

Cheers!
 
Hi all,

Brand new to homebrewing and even newer to using Fermentrack. Everything is functioning as it should be, but I was experimenting with Generic Push Targets. My goal is to push data to a MySql database for inclusion in another website. I was wondering what the payload looks like and how I can ingest it using PHP (preferably). Is anyone familiar with setting something like this up? I've read the documentation and all it mentions is HTTP request. Im not having luck parsing the json.

Thanks in advance, and I look forward to becoming active in this community. Cheers!
-Brian

Hey there! The documentation contains a copy of the JSON here: 7.5. “Push” Support — Fermentrack documentation

Is that not working for you? What issue are you encountering? Admittedly, it's been a good number of years since I wrote anything in PHP, but it should be fairly easy to ingest...
 
Hi Thorrak, and thanks for the reply. I probably should have been a bit more in depth, so forgive me.

Using the sample json, I was able to get my php end point to work by using Postman and pushing the json over a POST request. However, when the generic push target I set up in Fermentrack pushes the request, it does not ingest. I did modify the script to write the entire HTTP request to a file, and the json is there in my test, so it's not an issue with Fermentrack. I'm sure it's just a php programmatic issue, and I will keep plugging away. s
 
Hi Thorrak, and thanks for the reply. I probably should have been a bit more in depth, so forgive me.

Using the sample json, I was able to get my php end point to work by using Postman and pushing the json over a POST request. However, when the generic push target I set up in Fermentrack pushes the request, it does not ingest. I did modify the script to write the entire HTTP request to a file, and the json is there in my test, so it's not an issue with Fermentrack. I'm sure it's just a php programmatic issue, and I will keep plugging away. s

Do you have the code for the page handling the post available somewhere I could take a look?

I have an idea as to what might be happening but I have no idea off the top of my head if PHP makes a distinction between the request POST and the request BODY.
 
Last edited:
Do you have the code for the page handling the post available somewhere I could take a look?

I have an idea as to what might be happening but I have no idea off the top of my head if PHP makes a distinction between the request POST and the request BODY.
@Thorrak , your reply trigged a test that actually worked!

Here's the script I used to parse the Generic Push Target and post it to a mysq database. Thanks again for your awesome platform!

PHP:
<?php

// Read the input stream
$body = file_get_contents("php://input");

// Decode the JSON object
$object = json_decode($body, true);

// Loop through JSON Gravity Sensors
foreach ($object['gravity_sensors'] as $sensor){
    $name=$sensor['name'];
    $internal_id=$sensor['internal_id'];
    $sensor_type=$sensor['sensor_type'];
    $gravity= $sensor['gravity'];
    $temp=$sensor['temp'];
    $temp_format=$sensor['temp_format'];
 
    // Create SQL statement
    $sql = "insert into ferment(name,internal_id,sensor_type,gravity,temp,temp_format,timestamp) values('".$name."',".$internal_id.",'".$sensor_type."',".$gravity.",".$temp.",'".$temp_format."',NOW())";
 
    // Open DB Connection
    $mysqli = new mysqli("localhost", "kbc", "zgcBFk6VBC0iIkXB", "kbc");
 
    // Execute SQL query
    $mysqli->query($sql);
 
    // Close DB Connection
    $mysqli->close();
 
    }
 
Back
Top