Skip to content

Commit

Permalink
Merge pull request #446 from thorrak/dev
Browse files Browse the repository at this point in the history
Release bugfixes & Tilt troubleshooting
  • Loading branch information
thorrak committed Apr 11, 2020
2 parents f5d4d7f + 8e56454 commit 049f86d
Show file tree
Hide file tree
Showing 27 changed files with 741 additions and 330 deletions.
6 changes: 4 additions & 2 deletions app/api/clog.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from gravity.models import GravitySensor


def get_filepath_to_log(device_type, logfile, device_id=None):
def get_filepath_to_log(device_type, logfile="", device_id=None):
# get_filepath_to_log is being broken out so that we can use it in help/other templates to display which log file
# is being loaded
if device_type == "brewpi":
Expand All @@ -22,6 +22,8 @@ def get_filepath_to_log(device_type, logfile, device_id=None):
log_filename = 'fermentrack-stderr.log'
elif device_type == "ispindel":
log_filename = 'ispindel_raw_output.log'
elif device_type == "upgrade":
log_filename = 'upgrade.log'
else:
return None

Expand All @@ -44,7 +46,7 @@ def get_device_log_combined(req, return_type, device_type, logfile, device_id=No
# gravity - A specific gravity sensor object
# spawner - the circus spawner
# fermentrack - Fermentrack itself
valid_device_types = ['brewpi', 'gravity', 'spawner', 'fermentrack', 'ispindel']
valid_device_types = ['brewpi', 'gravity', 'spawner', 'fermentrack', 'ispindel', 'upgrade']
if device_type not in valid_device_types:
# TODO - Log this
return HttpResponse("Cannot read log files for devices of type {} ".format(device_type), status=500)
Expand Down
Binary file modified app/static/favicon.ico
Binary file not shown.
6 changes: 6 additions & 0 deletions app/templates/github_trigger_upgrade.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ <h4>Remote Commit Info:</h4>

{% endif %}

<p>Need to manually refresh the Python packages without upgrading? Click the below to trigger a refresh without pulling
new code from GitHub</p>
<p>
<a href="{% url "trigger_requirements_reload" %}" class="btn btn-primary">Update/Install Missing Python Packages</a>
</p>

{% if allow_git_branch_switching %}

<h3>Switch Branch</h3>
Expand Down
13 changes: 12 additions & 1 deletion app/templates/site_help.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<h1 class="page-header">Help</h1>

<p>
<a href="http://fermentrack.readthedocs.io//" class="btn btn-primary btn-large btn-lg">Fermentrack Docs</a>
<a href="http://docs.fermentrack.com/" class="btn btn-primary btn-large btn-lg">Fermentrack Docs</a>
</p>

<p>
Expand Down Expand Up @@ -99,9 +99,20 @@ <h4>Other logs</h4>
<th scope="row">iSpindel Raw Output</th>
<td><a href="{% url "get_app_log" "text" "ispindel" "stderr" %}">{% log_file_path "ispindel" "stderr" %}</a></td>
</tr>
<tr>
<th scope="row">Upgrade Log</th>
<td><a href="{% url "get_app_log" "text" "upgrade" "stderr" %}">{% log_file_path "upgrade" "stderr" %}</a></td>
</tr>
</tbody>
</table>


<h4>Other troubleshooting tools</h4>

<p>
<a href="{% url "gravity_tilt_test" %}" class="btn btn-primary">Troubleshoot Tilt/Bluetooth Support</a>
</p>

{% endblock %}

{% block scripts %}{% endblock %}
30 changes: 30 additions & 0 deletions app/templates/trigger_requirements_reload.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends "sitewide/flat_ui_template.html" %}
{% load custom_tags %}
{% load static %}

{% block title %}Reload Python Requirements{% endblock %}

{% block header_scripts %}
{% endblock %}


{% block content %}
<h1>Reload Python Requirements</h1>

<p>
You have triggered a manual reload of the Python packages required by Fermentrack. Please wait several minutes
for this refresh to complete and for Fermentrack to relaunch before proceeding.
</p>

<p>
Once complete, you can view the <a href="{% url "get_app_log" "text" "upgrade" "stderr" %}">upgrade log</a> to see
what was installed/updated.
</p>


{% endblock %}



{% block scripts %}
{% endblock %}
38 changes: 20 additions & 18 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,26 +500,14 @@ def github_trigger_upgrade(request, variant=""):
branch_to_use = request.POST.get('new_branch', "master")

if variant == "":
if sys.version_info[0] < 3:
# TODO - After April 2018, delete the Python 2 option here
cmds['tag'] = "nohup utils/upgrade.sh -t \"{}\" -b \"master\" &".format(request.POST.get('tag', ""))
cmds['branch'] = "nohup utils/upgrade.sh -b \"{}\" &".format(branch_to_use)
messages.success(request, "Triggered an upgrade from GitHub")
else:
cmds['tag'] = "nohup utils/upgrade3.sh -t \"{}\" -b \"master\" &".format(request.POST.get('tag', ""))
cmds['branch'] = "nohup utils/upgrade3.sh -b \"{}\" &".format(branch_to_use)
messages.success(request, "Triggered an upgrade from GitHub")
cmds['tag'] = "nohup utils/upgrade3.sh -t \"{}\" -b \"master\" &".format(request.POST.get('tag', ""))
cmds['branch'] = "nohup utils/upgrade3.sh -b \"{}\" &".format(branch_to_use)
messages.success(request, "Triggered an upgrade from GitHub")

elif variant == "force":
if sys.version_info[0] < 3:
# TODO - After April 2018, delete the Python 2 option here
cmds['tag'] = "nohup utils/force_upgrade.sh -t \"{}\" -b \"master\" &".format(request.POST.get('tag', ""))
cmds['branch'] = "nohup utils/force_upgrade.sh -b \"{}\" &".format(branch_to_use)
messages.success(request, "Triggered an upgrade from GitHub")
else:
cmds['tag'] = "nohup utils/force_upgrade3.sh -t \"{}\" -b \"master\" &".format(request.POST.get('tag', ""))
cmds['branch'] = "nohup utils/force_upgrade3.sh -b \"{}\" &".format(branch_to_use)
messages.success(request, "Triggered an upgrade from GitHub")
cmds['tag'] = "nohup utils/force_upgrade3.sh -t \"{}\" -b \"master\" &".format(request.POST.get('tag', ""))
cmds['branch'] = "nohup utils/force_upgrade3.sh -b \"{}\" &".format(branch_to_use)
messages.success(request, "Triggered an upgrade from GitHub")

else:
cmds['tag'] = ""
Expand Down Expand Up @@ -552,6 +540,20 @@ def github_trigger_force_upgrade(request):



@login_required
@site_is_configured
def trigger_requirements_reload(request):
# TODO - Add permission check here

# All that this view does is trigger the utils/fix_python_requirements.sh shell script and return a message letting
# the user know that Fermentrack will take a few minutes to restart.
cmd = "nohup utils/fix_python_requirements.sh &"
messages.success(request, "Triggered a reload of your Python packages")
subprocess.call(cmd, shell=True)

return render(request, template_name="trigger_requirements_reload.html", context={})


def login(request, next=None):
if not next:
if 'next' in request.GET:
Expand Down
42 changes: 32 additions & 10 deletions brewpi-script/scriptlibs/pinList.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,47 @@ def getPinList(boardType, shieldType):
{'val': 20, 'text': 'A2', 'type': 'free'},
{'val': 21, 'text': 'A3', 'type': 'free'}]
elif boardType == "uno" and shieldType == "revC":
pinList = [{'val': 6, 'text': ' 6 (Act 1)', 'type': 'act'},
{'val': 5, 'text': ' 5 (Act 2)', 'type': 'act'},
pinList = [{'val': 0, 'text': ' 0', 'type': 'serial'},
{'val': 1, 'text': ' 1', 'type': 'serial'},
{'val': 2, 'text': ' 2 (Act 3)', 'type': 'act'},
{'val': 19, 'text': 'A5 (Act 4)', 'type': 'act'},
{'val': 4, 'text': ' 4 (Door)', 'type': 'door'},
{'val': 18, 'text': 'A4 (OneWire)', 'type': 'onewire'},
{'val': 3, 'text': ' 3', 'type': 'beep'},
{'val': 4, 'text': ' 4 (Door)', 'type': 'door'},
{'val': 5, 'text': ' 5 (Act 2)', 'type': 'act'},
{'val': 6, 'text': ' 6 (Act 1)', 'type': 'act'},
{'val': 7, 'text': ' 7', 'type': 'rotary'},
{'val': 8, 'text': ' 8', 'type': 'rotary'},
{'val': 9, 'text': ' 9', 'type': 'rotary'},
{'val': 10, ' text': '10', 'type': 'spi'},
{'val': 11, ' text': '11', 'type': 'spi'},
{'val': 12, ' text': '12', 'type': 'spi'},
{'val': 13, ' text': '13', 'type': 'spi'},
{'val': 0, 'text': ' 0', 'type': 'serial'},
{'val': 1, 'text': ' 1', 'type': 'serial'},
{'val': 14, 'text': 'A0', 'type': 'free'},
{'val': 15, 'text': 'A1', 'type': 'free'},
{'val': 16, 'text': 'A2', 'type': 'free'},
{'val': 17, 'text': 'A3', 'type': 'free'}]
{'val': 17, 'text': 'A3', 'type': 'free'},
{'val': 18, 'text': 'A4 (OneWire)', 'type': 'onewire'},
{'val': 19, 'text': 'A5 (Act 4)', 'type': 'act'}]
elif boardType == "uno" and shieldType == "I2C":
pinList = [{'val': 0, 'text': ' 0', 'type': 'serial'},
{'val': 1, 'text': ' 1', 'type': 'serial'},
{'val': 2, 'text': ' 2 (Act 3)', 'type': 'act'},
{'val': 3, 'text': ' 3 (Alarm)', 'type': 'beep'},
{'val': 4, 'text': ' 4 (Door)', 'type': 'door'},
{'val': 5, 'text': ' 5 (Act 1)', 'type': 'act'},
{'val': 6, 'text': ' 6 (Act 2)', 'type': 'act'},
{'val': 7, 'text': ' 7', 'type': 'rotary'},
{'val': 8, 'text': ' 8', 'type': 'rotary'},
{'val': 9, 'text': ' 9', 'type': 'rotary'},
{'val': 10, 'text': '10 (Act 4)', 'type': 'act'},
{'val': 11, 'text': '11', 'type': 'free'},
{'val': 12, 'text': '12', 'type': 'free'},
{'val': 13, 'text': '13', 'type': 'free'},
{'val': 14, 'text': 'A0 (OneWire)', 'type': 'onewire'},
{'val': 15, 'text': 'A1 (OneWire)', 'type': 'free'},
{'val': 16, 'text': 'A2 (OneWire)', 'type': 'free'},
{'val': 17, 'text': 'A3 (Act 4)', 'type': 'act'},
{'val': 18, 'text': 'A4 (SDA)', 'type': 'i2c'},
{'val': 19, 'text': 'A5 (SCL)', 'type': 'i2c'}]
elif boardType == "leonardo" and shieldType == "revA":
pinList = [{'val': 6, 'text': ' 6 (Cool)', 'type': 'act'},
{'val': 5, 'text': ' 5 (Heat)', 'type': 'act'},
Expand Down Expand Up @@ -152,10 +173,11 @@ def getPinListJson(boardType, shieldType):
return 0

def pinListTest():
print(getPinListJson("leonardo", "revC"))
print(getPinListJson("uno", "revC"))
print(getPinListJson("leonardo", "revA"))
print(getPinListJson("leonardo", "revC"))
print(getPinListJson("uno", "revA"))
print(getPinListJson("uno", "revC"))
print(getPinListJson("uno", "I2C"))
print(getPinListJson("core", "V1"))
print(getPinListJson("core", "V2"))
print(getPinListJson("photon", "V1"))
Expand Down
32 changes: 30 additions & 2 deletions docs/source/develop/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,35 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) because it was the first relatively standard format to pop up when I googled "changelog formats".


[2019-02-17] - Improved ESP32 Flashing Support
[2020-04-11] - Bugfixes & Tilt Troubleshooting
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Added
---------------------

- Added explicit support for LBussy's BrewPi-Remix I2C Board
- Exposed upgrade.log from the help screen
- Store the exact last time that a message was received from a Tilt to Redis
- Add sentry support to tilt_monitor_aio.py
- Added "debug" scripts for bluetooth Tilt connections
- Added TiltBridge connection settings to Tilt management page



Changed
---------------------

- Removed legacy Python 2 code
- Reduced gravity sensor temp precision to 0.1 degrees
- Locked pybluez, aioblescan, and redis versions to prevent undesired format changes going forward


Fixed
---------------------

- Fix display of TiltBridge mDNS settings on Tilt settings page

[2020-02-17] - Improved ESP32 Flashing Support
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Added
Expand All @@ -21,7 +49,7 @@ Changed
- SPIFFS partitions can now be flashed to ESP8266 devices


[2019-02-15] - ThingSpeak and Grainfather Support
[2020-02-15] - ThingSpeak and Grainfather Support
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Added
Expand Down
38 changes: 38 additions & 0 deletions docs/source/gravitysensors/tilt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,41 @@ To integrate your Tilt logging with a BrewPi controller:
#. Click "Attach sensor to controller"

Now, to view your Tilt sensor readings, navigate to the BrewPi controller dashboard. You will have to restart a log if you had one running before associating the Tilt with the BrewPi sensor. Now, any wort you ferment with this controller will incorporate the Tilt's temperature and gravity readings onto your graph. Once the Tilt (or any gravity sensor) is attached to a BrewPi controller, that controller dashboard will become the main method with which to interact with the Tilt, specifically for things like logging.


Troubleshooting Tilt Support
----------------------------

Tilt Hydrometer support relies on a number of components beyond those used for other functions in Fermentrack, and as a result is particularly sensitive to changes in the program environment on the device on which Fermentrack is installed. Testing has been added to Fermentrack to help diagnose some of these environmental issues if they happen to impact an installation.


Fixing Missing System Packages
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If there are system packages missing, you will unfortunately need to fix them manually. For Raspberry Pis running
Raspbian, here is how to fix this issue. For other OS's, please adapt these instructions as necessary

#. Log into your Raspberry Pi via as the `pi` user
#. Type `sudo apt-get update` and allow the package system to update
#. Type `sudo-apt-get upgrade` and follow the prompts to upgrade all installed packages
#. For each missing package identified by the test script, type `sudo apt-get install -y {package name}`
#. Allow each package to install. Repeat the previous step for all missing packages.



Fixing Missing/Incorrect Python Packages
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Although all Python packages should be automatically installed as part of the installation script, it is possible that
packages come out of sync for a variety of reasons. If you are missing packages they will need to be installed for
Fermentrack to properly interface with your Tilt.

A manual refresh of the Python packages can be triggered from the GitHub upgrade page without updating Fermentrack from
GitHub. To trigger a refresh:

#. Log into Fermentrack
#. Click the 'gear' icon in the upper right hand corner of the page
#. Click 'Update from GitHub'
#. Click the 'Update/Install Missing Python Packages' button


1 change: 1 addition & 0 deletions fermentrack_django/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

url(r'^upgrade/$', app.views.github_trigger_upgrade, name='github_trigger_upgrade'),
url(r'^upgrade/force/$', app.views.github_trigger_force_upgrade, name='github_trigger_force_upgrade'),
url(r'^upgrade/reload/$', app.views.trigger_requirements_reload, name='trigger_requirements_reload'),

### Device Views
url(r'^devices/$', app.views.device_lcd_list, name='device_lcd_list'),
Expand Down
2 changes: 1 addition & 1 deletion gravity/api/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def getGravitySensors(req, device_id=None):

temp, temp_format = dev.retrieve_loggable_temp()
if temp is None:
temp_string = "--.-&deg; -"
temp_string = "--.-&deg;"
else:
temp_string = "{}&deg; {}".format(temp, temp_format)

Expand Down
26 changes: 16 additions & 10 deletions gravity/gravity_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# and to assist with debugging anything that isn't working properly. The idea is that gravity support was added later
# in the development cycle of Fermentrack and therefore cannot be assumed to be working out of the box.

from fermentrack_django import settings

import uuid

try:
Expand All @@ -11,14 +13,15 @@
redis_installed = False


def try_redis(host,port,password):
def try_redis(host=settings.REDIS_HOSTNAME, port=settings.REDIS_PORT, password=settings.REDIS_PASSWORD) -> (bool, bool, bool):
# Returns a tuple: (redis_installed, able_to_connect_test_result, key_set_and_retreival_test_result)

if not redis_installed:
# If we don't have the redis libraries, we can't exactly do anything else...
return False, False, False

try:

r = redis.Redis(host=host, port=port, password=password, socket_timeout=3)
r.ping() # Test if the connection is active
except redis.exceptions.TimeoutError:
Expand All @@ -40,13 +43,16 @@ def try_redis(host,port,password):
# The following was used for testing during development, and is a standalone test that can be run if needed
if __name__ == "__main__":
# Setting these here for the standalone test
redis_host = '127.0.0.2'
redis_port = 6379
redis_pass = ''

redis_install_test, redis_connection_test, redis_value_test = try_redis(redis_host, redis_port, redis_pass)
print "Redis Installed: {}".format(redis_install_test)
print "Testing redis connection to ({},{},{}):".format(redis_host, redis_port, redis_pass)
print "Connection Test: {}".format(redis_connection_test)
print "Value Set/Read Test: {}".format(redis_value_test)
# redis_host = '127.0.0.2'
# redis_port = 6379
# redis_pass = ''

# redis_install_test, redis_connection_test, redis_value_test = try_redis(redis_host, redis_port, redis_pass)
redis_install_test, redis_connection_test, redis_value_test = try_redis()

print("Redis Installed: {}".format(redis_install_test))
# print("Testing redis connection to ({},{},{}):".format(redis_host, redis_port, redis_pass))
print("Testing redis connection to ({},{},{}):".format(settings.REDIS_HOSTNAME, settings.REDIS_PORT, settings.REDIS_PASSWORD))
print("Connection Test: {}".format(redis_connection_test))
print("Value Set/Read Test: {}".format(redis_value_test))

Loading

0 comments on commit 049f86d

Please sign in to comment.