Skip to content

Commit

Permalink
Add WiFi reset functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
thorrak committed Jun 6, 2018
1 parent 4e463c5 commit d51b6da
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,12 @@ def reset_eeprom(self):
synced = self.sync_temp_format() # ...then resync the temp format
return synced

def reset_wifi(self):
response = self.send_message("resetWiFi") # Reset the controller WiFi settings
time.sleep(1) # Give it 1 second to complete
synced = self.sync_temp_format() # ...then resync the temp format
return synced

def get_control_constants(self):
return json.loads(self.send_message("getControlConstants", read_response=True))

Expand Down
9 changes: 9 additions & 0 deletions app/templates/device_manage.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ <h2>Reset EEPROM</h2>
</p>
<a href="{% url 'device_eeprom_reset' active_device.id %}" class="btn btn-danger btn-large btn-lg">Reset EEPROM</a>

<h2>Reset WiFi Settings</h2>
<p>
If you need to reset the WiFi configuration on your device (for switching to a new network/router, for example)
click the button below to delete the WiFi connection settings on the device. Once the settings have been erased
you will need to physically reset the device to cause it to launch the configuration access point.
</p>
<a href="{% url 'device_wifi_reset' active_device.id %}" class="btn btn-danger btn-large btn-lg">Reset WiFi Settings</a>


<h2>Uninstall Device</h2>
<p>
To uninstall a device from Fermentrack, approve the following statements and click the "Uninstall Device" button
Expand Down
23 changes: 23 additions & 0 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,29 @@ def device_eeprom_reset(request, device_id):
messages.success(request, "Device EEPROM reset")
return redirect("device_control_constants", device_id=device_id)


@login_required
@site_is_configured
def device_wifi_reset(request, device_id):
try:
active_device = BrewPiDevice.objects.get(id=device_id)
except:
messages.error(request, "Unable to load device with ID {}".format(device_id))
return redirect('siteroot')

# Using this as a proxy to check if we can connect
control_constants, is_legacy = active_device.retrieve_control_constants()

if control_constants is None:
# We weren't able to retrieve the version from the controller.
messages.error(request, u"Unable to reach brewpi-script for device {}".format(active_device))
return redirect('device_dashboard', device_id=device_id)
else:
active_device.reset_wifi()
messages.success(request, "Device WiFi settings reset. Reset the device to access the configuration AP.")
return redirect("device_control_constants", device_id=device_id)


def site_help(request):
return render(request, template_name='site_help.html', context={})

Expand Down
5 changes: 5 additions & 0 deletions brewpi-script/brewpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,11 @@ def trigger_refresh(read_values=False):
bg_ser.writeln('c') # request control constants cc
bg_ser.writeln('v') # request control variables cv

trigger_refresh(True) # Refresh the device list cache (will also raise socket.timeout)
elif messageType == "resetWiFi":
logMessage("Resetting controller WiFi settings")
bg_ser.writeln("w")
# TODO - Determine if we should sleep & exit here
trigger_refresh(True) # Refresh the device list cache (will also raise socket.timeout)
else:
logMessage("Error: Received invalid message on socket: " + message)
Expand Down
1 change: 1 addition & 0 deletions fermentrack_django/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
# TODO - Implement temperature control AJAX API calls
url(r'^devices/(?P<device_id>\d{1,20})/temp_control/$', app.views.device_temp_control, name='device_temp_control'),
url(r'^devices/(?P<device_id>\d{1,20})/reset/$', app.views.device_eeprom_reset, name='device_eeprom_reset'),
url(r'^devices/(?P<device_id>\d{1,20})/wifi_reset/$', app.views.device_wifi_reset, name='device_wifi_reset'),
url(r'^devices/(?P<device_id>\d{1,20})/manage/$', app.views.device_manage, name='device_manage'),
url(r'^devices/(?P<device_id>\d{1,20})/uninstall/$', app.views.device_uninstall, name='device_uninstall'),

Expand Down

0 comments on commit d51b6da

Please sign in to comment.