2017-11-22 19:26:40 -05:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Long live the Internet of Things!
|
|
|
|
"""
|
2018-03-02 21:25:50 -05:00
|
|
|
import time
|
|
|
|
|
2017-11-22 19:26:40 -05:00
|
|
|
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.say("Connection error. Timeout reached.")
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
|
|
return bot.say("Connection error. Is the unit dead?")
|
|
|
|
if res.text[32] == 'L':
|
|
|
|
bot.say("Lamp is now OFF.")
|
|
|
|
elif res.text[32] == 'H':
|
|
|
|
bot.say("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)
|
2018-03-02 21:25:50 -05:00
|
|
|
time.sleep(0.5)
|
|
|
|
res = requests.get("http://192.168.1.25/", timeout=10)
|
2017-11-22 19:26:40 -05:00
|
|
|
except requests.exceptions.ReadTimeout:
|
|
|
|
return bot.say("Connection error. Timeout reached.")
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
|
|
return bot.say("Connection error. Is the unit dead?")
|
|
|
|
bot.say(res.text)
|
2017-12-16 02:10:36 -05:00
|
|
|
|
|
|
|
|
|
|
|
@module.require_admin
|
|
|
|
@module.commands('inkwrite')
|
2018-01-05 08:46:52 -05:00
|
|
|
def inkWrite(bot, trigger):
|
2017-12-16 02:10:36 -05:00
|
|
|
"""
|
|
|
|
Writes shit to my e-ink screen.
|
|
|
|
"""
|
|
|
|
text = trigger.replace(".inkwrite ", "")
|
|
|
|
if not text:
|
|
|
|
return bot.say("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.say("Connection error. Timeout reached.")
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
|
|
return bot.say("Connection error. Is the unit dead?")
|
|
|
|
bot.say("Wrote: " + res.text)
|