After studying Python, hit the IRKit API to operate home appliances. See below for IRKit itself and API specifications. Simply put, a device that remembers the infrared rays of the remote control and allows you to hit them over the net.
http://getirkit.com/
#!/usr/bin/env python
# coding: utf-8
import requests
import json
class IrkitInternetAPI:
endpoint = "https://api.getirkit.com/1"
clientkey = ""
deviceid = ""
def __init__(self, clientkey, deviceid):
self.clientkey = clientkey
self.deviceid = deviceid
def get_messages(self):
params = {
'clientkey': self.clientkey,
}
headers = {'X-Requested-With': "irkit-python"}
url = self.endpoint + "/messages"
r = requests.get(url, headers=headers, params=params)
if r.status_code == 200:
return r.json()
def post_messages(self, data):
message = {
"format": "raw",
"freq": 38,
"data": data
}
message = json.dumps(message)
params = {
'clientkey': self.clientkey,
'deviceid': self.deviceid,
'message': message
}
url = self.endpoint + "/messages"
headers = {'X-Requested-With': "irkit-python"}
r = requests.post(url, headers=headers, params=params)
def main():
clientkey = "your_clientkey"
deviceid = "your_deviceid"
irkit = IrkitInternetAPI(clientkey, deviceid)
#Get the latest infrared signal (it will disappear soon, so just before that, point the remote control at IRKit)
messages = irkit.get_messages()
data = messages['message']['data']
#Call it again as it is
irkit.post_messages(data)
if __name__ == '__main__':
main()
For the time being, the lights turned on and off. It is interesting to be able to control home appliances from the program!
If you hit it with curl, you don't have to write this much code, but this time it's practice.
Recommended Posts