61 lines
1.5 KiB
Python
Executable File
61 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Long live the Internet of Things!
|
|
"""
|
|
import requests
|
|
|
|
import module
|
|
|
|
|
|
@module.require_admin
|
|
@module.commands('lamp')
|
|
def lampToggle(bot, trigger):
|
|
"""
|
|
Turns my lamp on and off. The glory of IoT!
|
|
"""
|
|
try:
|
|
res = requests.get("http://192.168.1.12/gpio?0=toggle", timeout=10)
|
|
except requests.exceptions.ReadTimeout:
|
|
return bot.msg("Connection error. Timeout reached.")
|
|
except requests.exceptions.ConnectionError:
|
|
return bot.msg("Connection error. Is the unit dead?")
|
|
if res.text[32] == 'L':
|
|
bot.msg("Lamp is now OFF.")
|
|
elif res.text[32] == 'H':
|
|
bot.msg("Lamp is now ON.")
|
|
|
|
|
|
#@module.require_admin
|
|
@module.commands('roomtemp')
|
|
def roomTemp(bot, trigger):
|
|
"""
|
|
Gets the temperature of my room.
|
|
"""
|
|
try:
|
|
res = requests.get("http://192.168.1.25/", timeout=10)
|
|
except requests.exceptions.ReadTimeout:
|
|
return bot.msg("Connection error. Timeout reached.")
|
|
except requests.exceptions.ConnectionError:
|
|
return bot.msg("Connection error. Is the unit dead?")
|
|
bot.msg(res.text)
|
|
|
|
|
|
@module.require_admin
|
|
@module.commands('inkwrite')
|
|
def inkWrite(bot, trigger):
|
|
"""
|
|
Writes shit to my e-ink screen.
|
|
"""
|
|
text = trigger.replace(".inkwrite ", "")
|
|
if not text:
|
|
return bot.msg("Need something to write.")
|
|
|
|
try:
|
|
res = requests.get(f"http://192.168.1.125:8000/?text={text}",
|
|
timeout=10)
|
|
except requests.exceptions.ReadTimeout:
|
|
return bot.msg("Connection error. Timeout reached.")
|
|
except requests.exceptions.ConnectionError:
|
|
return bot.msg("Connection error. Is the unit dead?")
|
|
bot.msg("Wrote: " + res.text)
|