Custom Notifications for Fire TV via HTTP


#1

1) Give a description of the problem
I’m trying to send custom notifications to Amazon Fire TV. I install the App Notifications for Fire TV on the Fire Tv stick. I’m basing the piston using the solution for Homeseer and Home Assistant, but I having difficulties to arrange the variables with the correct Webcore syntax for curl.
This is the code section form Homeseer, Hope you can help me. Tnx

2) What is the expected behaviour?
Using HHTP Post to send the custom message to the Fire TV port 7676.

3) What is happening/not happening?
I can confirm that the APP “Notifications for Fire TV” is reciving the POST form Webcore but only showing a empty Toast Notification.

**4) Post a Green Snapshot of the piston![image|45x37]

5) Attach logs after turning logging level to Full


#2

It looks like you are sending JSON but the example is FORM encoded. I’d imagine it is intended that you define variables like ‘force’ and ‘filename’ and add those to ‘Send Variables’ with the content set to FORM.


#3

Thanks @orangebucket for notice that.
I change the request type with FORM, Im using PUT and the information still is missing.
I’m still trying. Tnx

P.S. I’m using PUT because when try with POST doesn’t Show the blank notification.


#4

I have had good luck testing with https://requestcatcher.com/

Hit that with your curl statement for a known template then adjust your piston configuration until it is the same. Then go back to your private IPv4 address.


#5

Thanks @Bloodtick_Jones for the link, awesome tool!

I inspect the traffic from my android APP , and I notice that App uses a custom html boundary “SwA1592325033828SwA” maybe here is the problem.
It’s posible to send custom boundary in webcore?

Here the header an part of the Form:

POST / HTTP/1.1
Authorization: Basic Og==
Connection: Keep-Alive
Content-Type: ; boundary=SwA1592325033828SwA
User-Agent: Dalvik/2.1.0 (Linux; U; Android 6.0; xxxxx Build/MRA58K)
Host: 192.168.0.17:7676
Accept-Encoding: gzip
Content-Length: 2946

–SwA1592325033828SwA
Content-Type: text/plain
Content-Disposition: form-data; name=“type”

0
–SwA1592325033828SwA


#6

I know this is an old topic but I’m posting this in case it’s useful for someone else - this thread shows up when trying to get Notifications for FireTV to work with custom messages.

There is a Home Assistant module for this, I don’t use home assistant, but have instead written a php script based on the code found here https://gist.github.com/maxivak/18fcac476a2f4ea02e5f80b303811d5f

My php script sits on a RPi and receives input parameters via GET for the message title, message body and icon - I can do this manually, or via a node-red flow.
eg
http://ipofyourrpi/folder/message.php?title=yourtitlehere&message=yourmessagehere&icon=youriconchoice

The rpi then sends the request to my firestick to get the message to display on the TV - the icons I use sit in the same webfolder as the php script

As I say, this may be of use to someone else trying the same thing without HA

Regards RSP

<?php

//get the input data



if (isset($_GET["title"])) {
    $message_title = filter_var(urldecode($_GET["title"]), FILTER_SANITIZE_STRING);
} else {
    $message_title = "Notification";
}
if (isset($_GET["message"])) {
    $message_body = filter_var(urldecode($_GET["message"]), FILTER_SANITIZE_STRING);
} else {
    $message_body = "Hello World";
}
if (isset($_GET["icon"])) {
    $message_icon = filter_var(urldecode($_GET["icon"]), FILTER_SANITIZE_STRING);
} else {
    $message_icon = "default";
}

//title     = notification title
//msg       = message body text
//duration  = time in seconds for message to be shown
//transparency = 0 transparent/ 1 solid

// default data fields for POST request
$fields = array("title" => "Notification", "msg" => "Hello World", "duration" => "10", "fontsize" => 0,     "position" => 0, "width" => 0, "bkgcolor" => "#607d8b", "transparency" => 1, "offset" => 0, "offsety" => 0,     "app" => "Notifications for Fire TV", "force" => true);

//populate with our message
$fields["title"] = $message_title;
$fields["msg"] = $message_body;



//change background depending on message type
/*
switch ($message_type) {
    case "Warning":
        $fields["bkgcolor"] = "#ff0000";
        break;
    default:
        $fields["bkgcolor"] = "#607d8b";
        break;
}
$fields["bkgcolor"] = "#ff0000";
*/

//change icon file
switch ($message_icon) {
case "warning":
        $file = file_get_contents('http://servernameorip/notifications/warning.png');
        break;
case "freezer":
        $file = file_get_contents('http://servernameorip/notifications/freezer.png');
        break;
case "fridge":
        $file = file_get_contents('http://servernameorip/notifications/fridge.png');
        break;
case "mail":
        $file = file_get_contents('http://servernameorip/notifications/mail.png');
        break;
default:
        $file = file_get_contents('http://servernameorip/notifications/notification.png');
        break;
}



//firestick IP
$url = "http://ipoffirestickgoeshere:7676";

// curl
$curl = curl_init();

$url_data = http_build_query($fields);

$boundary = 'SwA1592325033828SwA';
$delimiter = '' . $boundary;

$post_data = build_data_files($boundary, $fields, $file);

curl_setopt_array($curl, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    //CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => $post_data,
    CURLOPT_VERBOSE => true,
    CURLOPT_HTTPHEADER => array(
//"Authorization: Bearer $TOKEN",
//    "Authorization: Basic 0g==",
        "Connection: Keep-Alive",
        "Content-Type: multipart/form-data; boundary=" . $delimiter,
//    "Accept-Encoding: gzip",
        "Content-Length: " . strlen($post_data)
    ),
));

//
$response = curl_exec($curl);

$info = curl_getinfo($curl);
//echo "code: ${info['http_code']}";
//print_r($info['request_header']);
//var_dump($response);
//$err = curl_error($curl);
//echo "error";
//var_dump($err);
curl_close($curl);

function build_data_files($boundary, $fields, $file) {
    $data = '';
    $eol = "\r\n";

    $delimiter = '' . $boundary;

    //add the fields
    foreach ($fields as $name => $content) {
        $data .= "--" . $delimiter . $eol
                . 'Content-Type: text/plain' . $eol
                . 'Content-Disposition: form-data; name="' . $name . "\"" . $eol . $eol
                . $content . $eol;
    }


    //add the image
    $data .= "--" . $delimiter . $eol
            . 'Content-Disposition: form-data; name="filename"; filename="icon.png"' . $eol
            . 'Content-Type: application/octet-stream' . $eol
            . 'Content-Transfer-Encoding: binary' . $eol
    ;

    $data .= $eol;
    $data .= $file . $eol;

    $data .= "--" . $delimiter . "--" . $eol;

    return $data;
}


echo "Done";
?>