Skip to content

Commit

Permalink
fix websocket problems in development and production mode
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Dec 7, 2019
1 parent 044b57e commit aa95a28
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
instance
.vscode
gunicorn_config.py
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ install:

.PHONY: dev
dev:
pipenv run python app.py
pipenv run python app.py

prod:
pipenv run gunicorn -c gunicorn_config.py wsgi:app
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ flask-mqtt = "*"
flask-restful = "*"
gunicorn = "*"
flask-socketio = "*"
gevent = "*"

[requires]
python_version = "3.7"
56 changes: 55 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# Roller Shutter

TODO

## Production mode

### gunicorn conf file
Gunicorn configuration file isn't under version control.
You need to create a `gunicorn_config.py` like this:

```python
worker_class = "gevent"
workers = 1
bind = "0.0.0.0:5000"
```

If you need to run the server with ssl cert, add these rows:

```python
certfile = "/path/to/ssl/certfile.pem"
keyfile = "path/to/ssl/privkey.pem"
```
6 changes: 4 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@mqtt.on_connect()
def handle_connect(client, userdata, flags, rc):
mqtt.subscribe("shellies/command")
# mqtt.subscribe("shellies/command")
for blind in app.config.get("BLINDS", []):
mqtt.subscribe("shellies/{id}/online".format(id=blind.get("id", "")))
mqtt.subscribe("shellies/{id}/roller/0/pos".format(id=blind.get("id", "")))
Expand Down Expand Up @@ -100,4 +100,6 @@ def get(self, id, action):
api.add_resource(Action, "/roller/<string:id>/<string:action>")

if __name__ == "__main__":
socketio.run(app, debug=False)
socketio.run(
app, debug=False, host="0.0.0.0", threaded=True,
)

0 comments on commit aa95a28

Please sign in to comment.