Skip to content

Commit 347fcde

Browse files
authored
Merge pull request #41 from kaulketh/develop
emergency stop implemented
2 parents bbc4f65 + 5418e2e commit 347fcde

21 files changed

+336
-303
lines changed

bot/conf/ext_greenhouse_lib.py

+19-7
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,25 @@
2222
cmd_live = '{0}live'.format(cmd_prefix)
2323
cmd_kill = '{0}kill'.format(cmd_prefix)
2424

25-
msg_help = 'Usage and possible commands in special mode:{0}{1} - this info{0}{2} - restart the whole RSBPi{0}{3} - ' \
26-
'force update{0}{4} - force archiving and cleaning of log files{0}{5} - stop this bot mode ' \
27-
'{0}{6}- switch all on{0}{7}- switch all off{0}{8}- switch group 1 on{0}{9}- switch group 1 ' \
28-
'off{0}{10}- switch group 2 on{0}{11}- switch group 2 off{0}{12}- switch group 3 on{0}{13}- switch ' \
29-
'group 3 off{0}{14} - Live stream'.format(
30-
newline, cmd_help, cmd_restart, cmd_update, cmd_logrotate, cmd_kill, cmd_all_on, cmd_all_off, cmd_group1_on,
31-
cmd_group1_off, cmd_group2_on, cmd_group2_off, cmd_group3_on, cmd_group3_off, cmd_live)
25+
msg_help = 'Usage and possible commands in special mode:{0}' \
26+
'{1} - this info{0}' \
27+
'{2} - restart the whole RSBPi{0}' \
28+
'{3} - force update{0}' \
29+
'{4} - force archiving and cleaning of log files{0}' \
30+
'{5} - stop this mode{0}' \
31+
'{6} - switch all on{0}' \
32+
'{7} - switch all off{0}' \
33+
'{8} - switch group 1 on{0}' \
34+
'{9} - switch group 1 off{0}' \
35+
'{10} - switch group 2 on{0}' \
36+
'{11} - switch group 2 off{0}' \
37+
'{12} - switch group 3 on{0}' \
38+
'{13} - switch group 3 off{0}' \
39+
'{14} - Live stream'\
40+
.format(newline,
41+
cmd_help, cmd_restart, cmd_update, cmd_logrotate, cmd_kill,
42+
cmd_all_on, cmd_all_off, cmd_group1_on, cmd_group1_off, cmd_group2_on,
43+
cmd_group2_off, cmd_group3_on, cmd_group3_off, cmd_live)
3244

3345
msg_unknown = 'Unknown in this mode...!\nPlease use /help for more information.'
3446
msg_update = 'Update forced manually, info is available in separate log file.'

bot/conf/greenhouse_config.py

+2-52
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
3-
# configs, constants and methods
3+
# configs, command strings and constants
44
# author: Thomas Kaulke, [email protected]
55

66
from __future__ import absolute_import
7-
import time
8-
import RPi.GPIO as GPIO
97
import conf.access as access
10-
import logger.logger as log
11-
12-
"""logging is configured in logger package in logger_config.ini"""
13-
logging = log.get_logger('config')
148

159
# language selection
1610
""" for English import greenhouse_lib_english """
@@ -32,18 +26,7 @@
3226
[lib.stop_bot, lib.live_stream, lib.reload]
3327
]
3428
kb2 = [[lib.cancel, lib.stop_bot]]
35-
36-
37-
# to use Raspberry Pi board pin numbers
38-
def set_pins():
39-
GPIO.setmode(GPIO.BOARD)
40-
logging.info('Set GPIO mode: GPIO.BOARD')
41-
# to use GPIO instead board pin numbers, then please adapt pin definition
42-
# GPIO.setmode(GPIO.BCM)
43-
# comment if warnings required
44-
GPIO.setwarnings(False)
45-
return GPIO
46-
29+
kb3 = [[lib.emergency_stop]]
4730

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

9073

91-
# switch functions
92-
def switch_on(pin):
93-
logging.info('switch on: ' + str(pin))
94-
GPIO.setup(pin, GPIO.OUT)
95-
GPIO.output(pin, GPIO.LOW)
96-
# os.system(run_gpio_check + str(pin))
97-
return
98-
99-
100-
def switch_off(pin):
101-
logging.info('switch off: ' + str(pin))
102-
GPIO.setup(pin, GPIO.OUT)
103-
GPIO.output(pin, GPIO.HIGH)
104-
# os.system(run_gpio_check + str(pin))
105-
GPIO.cleanup(pin)
106-
return
107-
108-
109-
# date time strings
110-
def get_timestamp():
111-
return time.strftime('[%d.%m.%Y %H:%M:%S] ')
112-
113-
114-
def get_timestamp_line():
115-
return time.strftime('`[%d.%m.%Y %H:%M:%S]\n---------------------\n`')
116-
117-
118-
# gets the state of pin, if 0 is switched on
119-
def get_pin_state(pin):
120-
GPIO.setup(pin, GPIO.OUT)
121-
return GPIO.input(pin)
122-
123-
12474
if __name__ == '__main__':
12575
pass

bot/conf/greenhouse_lib_english.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
all_channels = 'All'
2424
stop_bot = 'End'
2525
live_stream = 'Take a look!'
26+
emergency_stop = 'EMERGENCY STOP'
2627
reload = 'Reload'
2728
group1 = ('Channel 1 to 3', 'Channel 1', 'Channel 2', 'Channel 3')
2829
group2 = ('Channel 6 to 8', 'Channel 6', 'Channel 7', 'Channel 8')
@@ -37,7 +38,7 @@
3738
msg_live = '[Click here for the live stream]({})'
3839
msg_temperature = '`{}Current values\n{}, {}\n{}`'
3940
msg_welcome = '`Hello {}!`'
40-
msg_stop = '` STANDBY `'
41+
msg_stop = '` S T A N D B Y `'
4142
msg_duration = '`Specify switching time for \'{}\' in ' + time_units_name[time_units_index] + ':`'
4243
water_on = '`\'{}\' is switched on for {}' + time_units_sign[time_units_index] + '.`'
4344
water_on_group = '`{} are switched on for {}' + time_units_sign[time_units_index] + '.`'

bot/conf/greenhouse_lib_german.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
stop_bot = 'Beenden'
2525
live_stream = 'Schau mal!'
2626
reload = 'Aktualisieren'
27+
emergency_stop = 'NOT - STOP'
2728
group1 = ('Kanal 1 bis 3', 'Kanal 1', 'Kanal 2', 'Kanal 3')
2829
group2 = ('Kanal 6 bis 8', 'Kanal 6', 'Kanal 7', 'Kanal 8')
2930
group3 = ('Kanal 4 und 5', 'Kanal 4', 'Kanal 5')
@@ -36,7 +37,7 @@
3637
msg_live = '[Hier gehts zum Live Stream]({})'
3738
msg_temperature = '`{}Aktuelle Werte\n{}, {}\n{}`'
3839
msg_welcome = '`Hallo {}!`'
39-
msg_stop = '` STANDBY `'
40+
msg_stop = '` S T A N D B Y `'
4041
msg_duration = '`Schaltzeit für \'{}\' in ' + time_units_name[time_units_index] + ' angeben:`'
4142
water_on = '`\'{}\' wird jetzt für {}' + time_units_sign[time_units_index] + ' eingeschaltet.`'
4243
water_on_group = '`{} werden jetzt für {}' + time_units_sign[time_units_index] + ' eingeschalten.`'
@@ -46,8 +47,9 @@
4647
water_off_all = '`Alles wurde nach {}' + time_units_sign[time_units_index] + ' wieder abgeschalten.`\n\n'
4748
msg_choice = '`Bitte auswählen:`'
4849
msg_new_choice = '`Neue Auswahl oder Beenden?`'
49-
msg_panic = '`PANIK-MODUS!`'
50+
msg_panic = '*PANIK-MODUS*'
5051
private_warning = '`Hallo {}, dies ist ein privater Bot!\nDeine ChatID: {} ist geblockt worden.`'
5152

53+
5254
if __name__ == '__main__':
5355
pass

bot/conf/keyboard_lib.py

-14
This file was deleted.

bot/ext_greenhouse.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
from __future__ import absolute_import
1010
import conf.greenhouse_config as conf
1111
import conf.ext_greenhouse_lib as lib
12+
import utils.utils as utils
1213
import peripherals.four_digit.display as display
1314
import sys
1415
import time
1516
import telepot
1617
import os
1718
import logger.logger as log
1819

19-
logging = log.get_logger('extended bot')
20+
logging = log.get_logger()
2021

2122
pins_state = False
2223

@@ -46,14 +47,14 @@
4647
# water a group of targets
4748
def _water_on_group(group):
4849
for member in group:
49-
conf.switch_on(member)
50+
utils.switch_on(member)
5051
return
5152

5253

5354
# water off for a group of targets
5455
def _water_off_group(group):
5556
for member in group:
56-
conf.switch_off(member)
57+
utils.switch_off(member)
5758
return
5859

5960

@@ -78,7 +79,7 @@ def _send_msg(message, parse_mode):
7879
def _check_pins_state():
7980
global pins_state
8081
for pin in group_all:
81-
if not conf.get_pin_state(pin):
82+
if not utils.get_pin_state(pin):
8283
display.show_on()
8384
pins_state = False
8485
break
@@ -107,19 +108,19 @@ def _handle(msg):
107108
elif command == lib.cmd_logrotate:
108109
_send_msg(_read_cmd(lib.logrotate_bot), no_parse_mode)
109110
elif command == lib.cmd_all_on:
110-
_send_msg(conf.get_timestamp() + ' all on', no_parse_mode)
111+
_send_msg(utils.get_timestamp() + ' all on', no_parse_mode)
111112
_water_on_group(group_all)
112113
elif command == lib.cmd_all_off:
113114
_send_msg('all off.', no_parse_mode)
114115
_water_off_group(group_all)
115116
elif command == lib.cmd_group1_on:
116-
_send_msg(conf.get_timestamp() + 'group 1 on', no_parse_mode)
117+
_send_msg(utils.get_timestamp() + 'group 1 on', no_parse_mode)
117118
_water_on_group(group_one)
118119
elif command == lib.cmd_group1_off:
119120
_send_msg('group 1 off', no_parse_mode)
120121
_water_off_group(group_one)
121122
elif command == lib.cmd_group2_on:
122-
_send_msg(conf.get_timestamp() + 'group 2 on', no_parse_mode)
123+
_send_msg(utils.get_timestamp() + 'group 2 on', no_parse_mode)
123124
_water_on_group(group_two)
124125
elif command == lib.cmd_group2_off:
125126
_send_msg('group 2 off', no_parse_mode)
@@ -154,7 +155,7 @@ def init_and_start():
154155
# logging.info('{0} is PID of running default bot, used to kill.'.format(str(pid1)))
155156
_read_cmd('kill -9 {0}'.format(str(pid1)))
156157

157-
conf.set_pins()
158+
utils.set_pins()
158159
bot = telepot.Bot(apiToken)
159160
bot.message_loop(_handle)
160161
logging.info('I am listening...')

0 commit comments

Comments
 (0)