Skip to content

Commit

Permalink
removing MQTT stuff from this branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric George committed Jul 3, 2017
1 parent b1ae076 commit d944f29
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 64 deletions.
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
install_requires=[
'RPi.GPIO',
'requests',
'AWSIoTPythonSDK',
'adafruit-mcp3008',
],
scripts=['wsp_control/runwsp.py'],
Expand Down
22 changes: 22 additions & 0 deletions wsp_control/http_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import requests

from config import PUMP_ENDPOINT, TEMP_ENDPOINT, AUTH, logger

def post_data(endpoint, data):

try:
r = requests.post(endpoint, data, auth=AUTH)
except:
logger.error('Requests error publishing data')
else:
if r.status_code != 200:
logger.error('Http error publishing data: {0}'\
.format(r.status_code))
return r

def post_temp(**data):
return post_data(TEMP_ENDPOINT, data)

def post_pump(**data):
return post_data(PUMP_ENDPOINT, data)

32 changes: 4 additions & 28 deletions wsp_control/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,17 @@
import time
from datetime import datetime

import requests
import RPi.GPIO as GPIO
import Adafruit_GPIO.SPI as SPI
import Adafruit_MCP3008

from wsp_control.config import (PIN,
LITERS_PER_REV,
TEMP_ENDPOINT,
PUMP_ENDPOINT,
AUTH,
logger,
SPI_PORT,
SPI_DEVICE)

from .mqtt_client import log_to_iot

def post_data(endpoint, data):

try:
r = requests.post(endpoint, data, auth=AUTH)
except:
logger.error('Requests error publishing data')
else:
if r.status_code != 200:
logger.error('Http error publishing data: {0}'\
.format(r.status_code))
return r
from .http_client import post_temp, post_pump

class DataLog:
""" Publish to website
Expand All @@ -48,14 +32,8 @@ def tick(self, *args):
self.update(*args)

def update(self, t1, t2, t3, t4, chlorine, ph):
""" Post data to the http server and IOT thing """
data = {'t1': t1, 't2': t2, 't3': t3, 't4': t4}
post_data(TEMP_ENDPOINT, data)

# More fields for this one
data['chlorine'] = chlorine
data['ph'] = ph
log_to_iot(data)
""" Post data to the server """
post_temp(t1=t1, t2=t2, t3=t3, t4=t4, chlorine=chlorine, ph=ph)


class FlowMeter:
Expand All @@ -77,7 +55,6 @@ def tick(self, data):
flow = LITERS_PER_REV / td

logger.info('Flowmeter tick: {0:.2f}l/s'.format(flow))
log_to_iot({'flow': flow})


class Pump:
Expand Down Expand Up @@ -114,8 +91,7 @@ def confirm(self):
state = self.is_on()
logger.info('Turning Pump {0}'.format(('OFF', 'ON')[state]))

post_data(PUMP_ENDPOINT, {'is_on': state})
log_to_iot({'pump': bool(state)}, self.disconnect_mqtt)
post_pump(is_on=state)


class Thermometer:
Expand Down
35 changes: 0 additions & 35 deletions wsp_control/mqtt_client.py

This file was deleted.

0 comments on commit d944f29

Please sign in to comment.