42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
|
#! /usr/bin/env python3
|
||
|
# -*- coding: utf-8 -*-
|
||
|
"""
|
||
|
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.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)
|
||
|
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)
|