Skip to content

Commit

Permalink
Merge pull request #41 from kaulketh/develop
Browse files Browse the repository at this point in the history
emergency stop implemented
  • Loading branch information
kaulketh authored Feb 11, 2019
2 parents bbc4f65 + 5418e2e commit 347fcde
Show file tree
Hide file tree
Showing 21 changed files with 336 additions and 303 deletions.
26 changes: 19 additions & 7 deletions bot/conf/ext_greenhouse_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,25 @@
cmd_live = '{0}live'.format(cmd_prefix)
cmd_kill = '{0}kill'.format(cmd_prefix)

msg_help = 'Usage and possible commands in special mode:{0}{1} - this info{0}{2} - restart the whole RSBPi{0}{3} - ' \
'force update{0}{4} - force archiving and cleaning of log files{0}{5} - stop this bot mode ' \
'{0}{6}- switch all on{0}{7}- switch all off{0}{8}- switch group 1 on{0}{9}- switch group 1 ' \
'off{0}{10}- switch group 2 on{0}{11}- switch group 2 off{0}{12}- switch group 3 on{0}{13}- switch ' \
'group 3 off{0}{14} - Live stream'.format(
newline, cmd_help, cmd_restart, cmd_update, cmd_logrotate, cmd_kill, cmd_all_on, cmd_all_off, cmd_group1_on,
cmd_group1_off, cmd_group2_on, cmd_group2_off, cmd_group3_on, cmd_group3_off, cmd_live)
msg_help = 'Usage and possible commands in special mode:{0}' \
'{1} - this info{0}' \
'{2} - restart the whole RSBPi{0}' \
'{3} - force update{0}' \
'{4} - force archiving and cleaning of log files{0}' \
'{5} - stop this mode{0}' \
'{6} - switch all on{0}' \
'{7} - switch all off{0}' \
'{8} - switch group 1 on{0}' \
'{9} - switch group 1 off{0}' \
'{10} - switch group 2 on{0}' \
'{11} - switch group 2 off{0}' \
'{12} - switch group 3 on{0}' \
'{13} - switch group 3 off{0}' \
'{14} - Live stream'\
.format(newline,
cmd_help, cmd_restart, cmd_update, cmd_logrotate, cmd_kill,
cmd_all_on, cmd_all_off, cmd_group1_on, cmd_group1_off, cmd_group2_on,
cmd_group2_off, cmd_group3_on, cmd_group3_off, cmd_live)

msg_unknown = 'Unknown in this mode...!\nPlease use /help for more information.'
msg_update = 'Update forced manually, info is available in separate log file.'
Expand Down
54 changes: 2 additions & 52 deletions bot/conf/greenhouse_config.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# configs, constants and methods
# configs, command strings and constants
# author: Thomas Kaulke, [email protected]

from __future__ import absolute_import
import time
import RPi.GPIO as GPIO
import conf.access as access
import logger.logger as log

"""logging is configured in logger package in logger_config.ini"""
logging = log.get_logger('config')

# language selection
""" for English import greenhouse_lib_english """
Expand All @@ -32,18 +26,7 @@
[lib.stop_bot, lib.live_stream, lib.reload]
]
kb2 = [[lib.cancel, lib.stop_bot]]


# to use Raspberry Pi board pin numbers
def set_pins():
GPIO.setmode(GPIO.BOARD)
logging.info('Set GPIO mode: GPIO.BOARD')
# to use GPIO instead board pin numbers, then please adapt pin definition
# GPIO.setmode(GPIO.BCM)
# comment if warnings required
GPIO.setwarnings(False)
return GPIO

kb3 = [[lib.emergency_stop]]

# 7-segment display settings
clk_pin = 32
Expand Down Expand Up @@ -88,38 +71,5 @@ def set_pins():
run_gpio_check = 'sudo python /home/pi/scripts/TelegramBot/gpio_check.py '


# switch functions
def switch_on(pin):
logging.info('switch on: ' + str(pin))
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.LOW)
# os.system(run_gpio_check + str(pin))
return


def switch_off(pin):
logging.info('switch off: ' + str(pin))
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.HIGH)
# os.system(run_gpio_check + str(pin))
GPIO.cleanup(pin)
return


# date time strings
def get_timestamp():
return time.strftime('[%d.%m.%Y %H:%M:%S] ')


def get_timestamp_line():
return time.strftime('`[%d.%m.%Y %H:%M:%S]\n---------------------\n`')


# gets the state of pin, if 0 is switched on
def get_pin_state(pin):
GPIO.setup(pin, GPIO.OUT)
return GPIO.input(pin)


if __name__ == '__main__':
pass
3 changes: 2 additions & 1 deletion bot/conf/greenhouse_lib_english.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
all_channels = 'All'
stop_bot = 'End'
live_stream = 'Take a look!'
emergency_stop = 'EMERGENCY STOP'
reload = 'Reload'
group1 = ('Channel 1 to 3', 'Channel 1', 'Channel 2', 'Channel 3')
group2 = ('Channel 6 to 8', 'Channel 6', 'Channel 7', 'Channel 8')
Expand All @@ -37,7 +38,7 @@
msg_live = '[Click here for the live stream]({})'
msg_temperature = '`{}Current values\n{}, {}\n{}`'
msg_welcome = '`Hello {}!`'
msg_stop = '` STANDBY `'
msg_stop = '` S T A N D B Y `'
msg_duration = '`Specify switching time for \'{}\' in ' + time_units_name[time_units_index] + ':`'
water_on = '`\'{}\' is switched on for {}' + time_units_sign[time_units_index] + '.`'
water_on_group = '`{} are switched on for {}' + time_units_sign[time_units_index] + '.`'
Expand Down
6 changes: 4 additions & 2 deletions bot/conf/greenhouse_lib_german.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
stop_bot = 'Beenden'
live_stream = 'Schau mal!'
reload = 'Aktualisieren'
emergency_stop = 'NOT - STOP'
group1 = ('Kanal 1 bis 3', 'Kanal 1', 'Kanal 2', 'Kanal 3')
group2 = ('Kanal 6 bis 8', 'Kanal 6', 'Kanal 7', 'Kanal 8')
group3 = ('Kanal 4 und 5', 'Kanal 4', 'Kanal 5')
Expand All @@ -36,7 +37,7 @@
msg_live = '[Hier gehts zum Live Stream]({})'
msg_temperature = '`{}Aktuelle Werte\n{}, {}\n{}`'
msg_welcome = '`Hallo {}!`'
msg_stop = '` STANDBY `'
msg_stop = '` S T A N D B Y `'
msg_duration = '`Schaltzeit für \'{}\' in ' + time_units_name[time_units_index] + ' angeben:`'
water_on = '`\'{}\' wird jetzt für {}' + time_units_sign[time_units_index] + ' eingeschaltet.`'
water_on_group = '`{} werden jetzt für {}' + time_units_sign[time_units_index] + ' eingeschalten.`'
Expand All @@ -46,8 +47,9 @@
water_off_all = '`Alles wurde nach {}' + time_units_sign[time_units_index] + ' wieder abgeschalten.`\n\n'
msg_choice = '`Bitte auswählen:`'
msg_new_choice = '`Neue Auswahl oder Beenden?`'
msg_panic = '`PANIK-MODUS!`'
msg_panic = '*PANIK-MODUS*'
private_warning = '`Hallo {}, dies ist ein privater Bot!\nDeine ChatID: {} ist geblockt worden.`'


if __name__ == '__main__':
pass
14 changes: 0 additions & 14 deletions bot/conf/keyboard_lib.py

This file was deleted.

17 changes: 9 additions & 8 deletions bot/ext_greenhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
from __future__ import absolute_import
import conf.greenhouse_config as conf
import conf.ext_greenhouse_lib as lib
import utils.utils as utils
import peripherals.four_digit.display as display
import sys
import time
import telepot
import os
import logger.logger as log

logging = log.get_logger('extended bot')
logging = log.get_logger()

pins_state = False

Expand Down Expand Up @@ -46,14 +47,14 @@
# water a group of targets
def _water_on_group(group):
for member in group:
conf.switch_on(member)
utils.switch_on(member)
return


# water off for a group of targets
def _water_off_group(group):
for member in group:
conf.switch_off(member)
utils.switch_off(member)
return


Expand All @@ -78,7 +79,7 @@ def _send_msg(message, parse_mode):
def _check_pins_state():
global pins_state
for pin in group_all:
if not conf.get_pin_state(pin):
if not utils.get_pin_state(pin):
display.show_on()
pins_state = False
break
Expand Down Expand Up @@ -107,19 +108,19 @@ def _handle(msg):
elif command == lib.cmd_logrotate:
_send_msg(_read_cmd(lib.logrotate_bot), no_parse_mode)
elif command == lib.cmd_all_on:
_send_msg(conf.get_timestamp() + ' all on', no_parse_mode)
_send_msg(utils.get_timestamp() + ' all on', no_parse_mode)
_water_on_group(group_all)
elif command == lib.cmd_all_off:
_send_msg('all off.', no_parse_mode)
_water_off_group(group_all)
elif command == lib.cmd_group1_on:
_send_msg(conf.get_timestamp() + 'group 1 on', no_parse_mode)
_send_msg(utils.get_timestamp() + 'group 1 on', no_parse_mode)
_water_on_group(group_one)
elif command == lib.cmd_group1_off:
_send_msg('group 1 off', no_parse_mode)
_water_off_group(group_one)
elif command == lib.cmd_group2_on:
_send_msg(conf.get_timestamp() + 'group 2 on', no_parse_mode)
_send_msg(utils.get_timestamp() + 'group 2 on', no_parse_mode)
_water_on_group(group_two)
elif command == lib.cmd_group2_off:
_send_msg('group 2 off', no_parse_mode)
Expand Down Expand Up @@ -154,7 +155,7 @@ def init_and_start():
# logging.info('{0} is PID of running default bot, used to kill.'.format(str(pid1)))
_read_cmd('kill -9 {0}'.format(str(pid1)))

conf.set_pins()
utils.set_pins()
bot = telepot.Bot(apiToken)
bot.message_loop(_handle)
logging.info('I am listening...')
Expand Down
Loading

0 comments on commit 347fcde

Please sign in to comment.