Page 1 of 1

Pushover attach a image

Posted: Friday 16 February 2018 20:54
by Minglarn
Hi..
Trying to send a attachment with pushover without success..

Sending normal messages with topics works fine.
Does anyone have any ideas or a working script?

Using this example to send messages and it works well to send notifications to my Sony tv..
But how do I include a image in this php code?

Code: Select all

<?php
curl_setopt_array($ch = curl_init(), array(
  CURLOPT_URL => "https://api.pushover.net/1/messages.json",
  CURLOPT_POSTFIELDS => array(
    "token" => "APP_TOKEN",
    "user" => "USER_KEY",
    "message" => "hello world",
  ),
  CURLOPT_SAFE_UPLOAD => true,
  CURLOPT_RETURNTRANSFER => true,
));
curl_exec($ch);
curl_close($ch);
?>
As seen on Pushovers examples using curl is should be like this, but I have difficulties to implement this in PHP.
Code from https://updates.pushover.net/post/17004 ... ushover-30

Code: Select all

If you use curl to send notifications, it’s as easy as:

curl -s \
 --form-string "token=APP_TOKEN" \
 --form-string "user=USER_KEY" \
 --form-string "message=here is an image attachment" \
 -F "attachment=@/path/to/your/image.jpg" \
 https://api.pushover.net/1/messages.json


Skickat från min SM-N950F via Tapatalk

Re: Pushover attach a image

Posted: Saturday 17 February 2018 16:11
by Mediacj
I didn't succeed either in doing this directly in php but solved it this way:

In my php script I have this line:

Code: Select all

$output = exec("/home/pi/hw/watch/grpu.sh $zna");
The bash script I am calling grpu.sh is this:

Code: Select all

#!/bin/sh
curl -s \
 --form-string "token=TOKEN" \
 --form-string "user=USER" \
 --form-string "message=Er is $1 kWh opgewekt vandaag." \
 -F "attachment=@/home/pi/domoticz/www/zp.png" \
 https://api.pushover.net/1/messages.json

Re: Pushover attach a image

Posted: Saturday 17 February 2018 19:23
by Minglarn
Thanks... but using curl is not an option at the moment.. . :(

I have the need to use the PHP script as a function so I can send messages and other stuff, like camera snapshots and etc.