Reading Answer from device
Posted: 24. Jan 2022, 17:02
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()
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()