Skip to content

Commit

Permalink
v0.9.0 Merge pull request #11 from mudpi/feature
Browse files Browse the repository at this point in the history
v0.9.0
  • Loading branch information
olixr authored Aug 15, 2020
2 parents d336134 + 4978177 commit 9cf9480
Show file tree
Hide file tree
Showing 57 changed files with 1,277 additions and 1,004 deletions.
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ These are the devices and sensors I tested and used with MudPi successfully. Man
Let me know if you are able to confirm tests on any other devices

## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
This project is licensed under the BSD-4-Clause License - see the [LICENSE.md](LICENSE.md) file for details


<img alt="MudPi Smart Garden" title="MudPi Smart Garden" src="https://mudpi.app/img/mudPI_LOGO_small_flat.png" width="50px">
Expand Down
7 changes: 5 additions & 2 deletions action.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import subprocess
import sys
sys.path.append('..')
import variables

class Action():

Expand All @@ -15,6 +14,10 @@ def __init__(self, config):
self.key = config.get("key", None).replace(" ", "_").lower() if config.get("key") is not None else self.name.replace(" ", "_").lower()
# Actions will be either objects to publish for events or a command string to execute
self.action = config.get("action")
try:
self.r = config["redis"] if config["redis"] is not None else redis.Redis(host='127.0.0.1', port=6379)
except KeyError:
self.r = redis.Redis(host='127.0.0.1', port=6379)
return

def init_action(self):
Expand All @@ -31,7 +34,7 @@ def trigger(self, value=None):
return

def emitEvent(self):
variables.r.publish(self.topic, json.dumps(self.action))
self.r.publish(self.topic, json.dumps(self.action))
return

def runCommand(self, value=None):
Expand Down
4 changes: 2 additions & 2 deletions controls/arduino/button_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

class ButtonControl(Control):

def __init__(self, pin, name='ButtonControl', key=None, connection=default_connection, analog_pin_mode=False, topic=None):
super().__init__(pin, name=name, key=key, connection=connection, analog_pin_mode=analog_pin_mode)
def __init__(self, pin, name='ButtonControl', key=None, connection=default_connection, analog_pin_mode=False, topic=None, redis_conn=None):
super().__init__(pin, name=name, key=key, connection=connection, analog_pin_mode=analog_pin_mode, redis_conn=redis_conn)
self.topic = topic.replace(" ", "/").lower() if topic is not None else 'mudpi/relay/'
self.state_counter = 3
self.previous_state = 0
Expand Down
9 changes: 6 additions & 3 deletions controls/arduino/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
from nanpy import (ArduinoApi, SerialManager)
import sys
sys.path.append('..')
import variables

default_connection = SerialManager()

# Base sensor class to extend all other arduino sensors from.
class Control():

def __init__(self, pin, name='Control', connection=default_connection, analog_pin_mode=False, key=None):
def __init__(self, pin, name='Control', connection=default_connection, analog_pin_mode=False, key=None, redis_conn=None):
self.pin = pin
self.name = name
self.key = key.replace(" ", "_").lower() if key is not None else self.name.replace(" ", "_").lower()
self.analog_pin_mode = analog_pin_mode
self.connection = connection
self.api = ArduinoApi(connection)
try:
self.r = redis_conn if redis_conn is not None else redis.Redis(host='127.0.0.1', port=6379)
except KeyError:
self.r = redis.Redis(host='127.0.0.1', port=6379)
return

def init_control(self):
Expand Down Expand Up @@ -46,4 +49,4 @@ def emitEvent(self, data):
}
}
print(message["data"])
variables.r.publish('controls', json.dumps(message))
self.r.publish('controls', json.dumps(message))
4 changes: 2 additions & 2 deletions controls/arduino/potentiometer_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

class PotentiometerControl(Control):

def __init__(self, pin, name='PotentiometerControl', key=None, connection=default_connection, analog_pin_mode=True, topic=None, reading_buffer=3):
super().__init__(pin, name=name, key=key, connection=connection, analog_pin_mode=analog_pin_mode)
def __init__(self, pin, name='PotentiometerControl', key=None, connection=default_connection, analog_pin_mode=True, topic=None, reading_buffer=3, redis_conn=None):
super().__init__(pin, name=name, key=key, connection=connection, analog_pin_mode=analog_pin_mode, redis_conn=redis_conn)
self.previous_state = 0
# Reading buffer helps prevent multiple events when values are floating between small amounts
self.reading_buffer = reading_buffer
Expand Down
4 changes: 2 additions & 2 deletions controls/arduino/switch_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

class SwitchControl(Control):

def __init__(self, pin, name='SwitchControl', key=None, connection=default_connection, analog_pin_mode=False, topic=None):
super().__init__(pin, name=name, key=key, connection=connection, analog_pin_mode=analog_pin_mode)
def __init__(self, pin, name='SwitchControl', key=None, connection=default_connection, analog_pin_mode=False, topic=None, redis_conn=None):
super().__init__(pin, name=name, key=key, connection=connection, analog_pin_mode=analog_pin_mode, redis_conn=redis_conn)
self.topic = topic.replace(" ", "/").lower() if topic is not None else 'mudpi/relay/'
self.state_counter = 3
self.previous_state = 0
Expand Down
4 changes: 2 additions & 2 deletions controls/pi/button_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

class ButtonControl(Control):

def __init__(self, pin, name='ButtonControl', key=None, resistor=None, edge_detection=None, debounce=None, topic=None):
super().__init__(pin, name=name, key=key, resistor=resistor, edge_detection=edge_detection, debounce=debounce)
def __init__(self, pin, name='ButtonControl', key=None, resistor=None, edge_detection=None, debounce=None, topic=None, redis_conn=None):
super().__init__(pin, name=name, key=key, resistor=resistor, edge_detection=edge_detection, debounce=debounce, redis_conn=redis_conn)
self.topic = topic.replace(" ", "/").lower() if topic is not None else 'mudpi/relay/'
return

Expand Down
9 changes: 6 additions & 3 deletions controls/pi/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
import RPi.GPIO as GPIO
import sys
sys.path.append('..')
import variables

# Base sensor class to extend all other arduino sensors from.
class Control():

def __init__(self, pin, name='Control',key=None, resistor=None, edge_detection=None, debounce=None):
def __init__(self, pin, name='Control',key=None, resistor=None, edge_detection=None, debounce=None, redis_conn=None):
self.pin = pin
self.name = name
self.key = key.replace(" ", "_").lower() if key is not None else self.name.replace(" ", "_").lower()
self.gpio = GPIO
self.debounce = debounce if debounce is not None else None
try:
self.r = redis_conn if redis_conn is not None else redis.Redis(host='127.0.0.1', port=6379)
except KeyError:
self.r = redis.Redis(host='127.0.0.1', port=6379)

if resistor is not None:
if resistor == "up" or resistor == GPIO.PUD_UP:
Expand Down Expand Up @@ -67,4 +70,4 @@ def emitEvent(self, data):
}
}
print(message["data"])
variables.r.publish('controls', json.dumps(message))
self.r.publish('controls', json.dumps(message))
4 changes: 2 additions & 2 deletions controls/pi/switch_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

class SwitchControl(Control):

def __init__(self, pin, name='SwitchControl', key=None, resistor=None, edge_detection=None, debounce=None, topic=None):
super().__init__(pin, name=name, key=key, resistor=resistor, edge_detection=edge_detection, debounce=debounce)
def __init__(self, pin, name='SwitchControl', key=None, resistor=None, edge_detection=None, debounce=None, topic=None, redis_conn=None):
super().__init__(pin, name=name, key=key, resistor=resistor, edge_detection=edge_detection, debounce=debounce, redis_conn=redis_conn)
self.topic = topic.replace(" ", "/").lower() if topic is not None else 'mudpi/relay/'
# Keep counter 1 above delay to avoid event on boot
self.state_counter = 3
Expand Down
Loading

0 comments on commit 9cf9480

Please sign in to comment.