HI,
I got my python script working well to seen me temperature data every three hours. What I'd like to do is an an 'answer' to the notification e.g. a=1 supply some text, and then have my code read the 'answer' I supply. I can't figure out whether this is possible or not. I can see the answers in the online API log - but is there a way to 'read' these back to my code? Here is my code below:
import http.client, urllib
import base64
import time
class Message:
def __init__(self, k, m,t,i,s,v,p='',a='0',a0=""):
self.k=k
self.m=m
self.t=t
self.i=i
self.s=s
self.v=v
self.p=p
self.a=a
self.a0=a0
def send(self):
conn = http.client.HTTPSConnection("pushsafer.com:443")
conn.request("POST", "/api",
urllib.parse.urlencode({
"k": self.k, # Your Private Key
"m": self.m, # Message Text
"t": self.t, # Title of message
"i": self.i, # Icon number 1-98
"s": self.s, # Sound number 0-28
"v": self.v, # Vibration number 0-3
"p": self.p, # Picture Data URL with Base64-encoded string
"a":self.a, # For adding a response
"a0":self.a0, #For adding options
}), { "Content-type": "application/x-www-form-urlencoded" })
response = conn.getresponse()
print(response.status, response.reason)
data = response.read()
print(data)
def imageconvert(img):
encoded = base64.b64encode(open(img, "rb").read())
picture="data:image/png;base64,"+str(encoded)[2:]
return picture
#Add your own path and filename
picture=imageconvert('plot.png')
message='The message'
title='Alert title'
message=Message(k="<Your Private Key>",m=message,t=title, i='1',s='0',v='0',p=picture,a='1')
message.send()
Reading Answer from device
- admin
- Site Admin
- Posts: 970
- Joined: 1. Dec 2014, 12:41
- Location: Germany
Re: Reading Answer from device
Hello,
use parameter a=1 to reply to a message!
parameter ao to have predefined option for an answer. Like ao=yes|no|maybe
To read answers, you have to use the "message read api" > https://www.pushsafer.com/en/pushapi#api-read
Kevin
use parameter a=1 to reply to a message!
parameter ao to have predefined option for an answer. Like ao=yes|no|maybe
To read answers, you have to use the "message read api" > https://www.pushsafer.com/en/pushapi#api-read
Kevin
Pushsafer DE: Dir gefällt Service und Support! Dann freuen wir uns auf deine Bewertung!
Pushsafer EN: You like Service and Support! Then we look forward to your review!
Pushsafer.com Website - iOS - Android - Windows 10
Pushsafer EN: You like Service and Support! Then we look forward to your review!
Pushsafer.com Website - iOS - Android - Windows 10
Re: Reading Answer from device
Excellent. Yes I worked out the a='1' part already, but reading back the 'answer' was baffling me. From your post and link, I figured it out. Briefly, I used a urllib.request using the address: "https://www.pushsafer.com/api-m?k="+ self.k+"&d="+self.deviceID and then I muddled my way to decode and then import into pandas dataframe, which I could then locate what I wanted. I need to become more familar with json, but using pandas I could locate the last alert sent, and the relevent data as a dict - then answer=message['answer'] There is probably an easier python solution, but it works.
- admin
- Site Admin
- Posts: 970
- Joined: 1. Dec 2014, 12:41
- Location: Germany
Re: Reading Answer from device
Great that you solution works!
Pushsafer DE: Dir gefällt Service und Support! Dann freuen wir uns auf deine Bewertung!
Pushsafer EN: You like Service and Support! Then we look forward to your review!
Pushsafer.com Website - iOS - Android - Windows 10
Pushsafer EN: You like Service and Support! Then we look forward to your review!
Pushsafer.com Website - iOS - Android - Windows 10
Who is online
Users browsing this forum: No registered users and 3 guests