From 80cda08333074675efb2975cbc2af060f44695ae Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 26 Jan 2021 06:56:52 +0000 Subject: [PATCH 01/13] GitBook: [master] 2 pages modified --- README.md | 32 ++++++++++++++++++++++++++++---- SUMMARY.md | 4 ++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 SUMMARY.md diff --git a/README.md b/README.md index 6793c9d..66ba0b6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,30 @@ -# CraftBeerPi4 +# CraftBeerPi -This is the development project for CraftBeerPi4. -It's not ready to use at the moment. +## Intro + +CraftBeerPi is an open source brewing controller. + +## Installation + +CraftBeerPi is python based and will require at last python 3.7.x + +```text +sudo python3 -m pip install cbpi +``` + +```text +cbpi setup +``` + +```text +cbpi start +``` + +## Links + +{% embed url="https://www.facebook.com/groups/craftbeerpi" %} + +{% embed url="https://www.youtube.com/channel/UCy47sYaG8YLwJWw2iY5\_aNg" %} + +{% embed url="http://web.craftbeerpi.com" %} -[See Documentation](https://manuel83.github.io/craftbeerpi4/) \ No newline at end of file diff --git a/SUMMARY.md b/SUMMARY.md new file mode 100644 index 0000000..245c4d7 --- /dev/null +++ b/SUMMARY.md @@ -0,0 +1,4 @@ +# Table of contents + +* [CraftBeerPi](README.md) + From 30d40a6f3159cc8039c184b010f54d28119754d3 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 26 Jan 2021 07:02:33 +0000 Subject: [PATCH 03/13] GitBook: [master] 2 pages modified --- SUMMARY.md | 1 + development.md | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 development.md diff --git a/SUMMARY.md b/SUMMARY.md index 245c4d7..bd79073 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -1,4 +1,5 @@ # Table of contents * [CraftBeerPi](README.md) +* [Development](development.md) diff --git a/development.md b/development.md new file mode 100644 index 0000000..4eb4ebb --- /dev/null +++ b/development.md @@ -0,0 +1,62 @@ +# Development + +## Custom Sensor + +```python +# -*- coding: utf-8 -*- +import asyncio +import random +import re +import random +from aiohttp import web +from cbpi.api import * + + + +@parameters([Property.Number(label="Param1", configurable=True), + Property.Text(label="Param2", configurable=True, default_value="HALLO"), + Property.Select(label="Param3", options=[1,2,4]), + Property.Sensor(label="Param4"), + Property.Actor(label="Param5")]) +class CustomSensor(CBPiSensor): + + def __init__(self, cbpi, id, props): + + super(CustomSensor, self).__init__(cbpi, id, props) + self.value = 0 + + + @action(key="Test", parameters=[]) + async def action1(self, **kwargs): + ''' + A custom action. Which can be called from the user interface + ''' + print("ACTION!", kwargs) + + async def run(self): + ''' + This method is executed asynchronousely + In this example the code is executed every second + ''' + while self.running is True: + self.value = random.randint(0,50) + self.push_update(self.value) + await asyncio.sleep(1) + + def get_state(self): + # return the current state of the sensor + return dict(value=self.value) + + +def setup(cbpi): + + ''' + This method is called by the server during startup + Here you need to register your plugins at the server + + :param cbpi: the cbpi core + :return: + ''' + cbpi.plugin.register("CustomSensor", CustomSensor) +``` + From c6237c5849ae4f8a9c441a176a77bfdca75c8ce2 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 26 Jan 2021 07:06:56 +0000 Subject: [PATCH 04/13] GitBook: [master] one page modified --- development.md | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/development.md b/development.md index 4eb4ebb..1dd1eac 100644 --- a/development.md +++ b/development.md @@ -1,6 +1,22 @@ # Development -## Custom Sensor +## Development Setup + +Custom Plugins are shipped as standard Python packages. Just create a python virtual env and add `cbpi`as dependency + +{% hint style="info" %} +How to create virtual env in Python +[https://docs.python.org/3/tutorial/venv.html](https://docs.python.org/3/tutorial/venv.html) +{% endhint %} + +```bash + +python3 -m venv venv +source venv/bin/activate +python3 -m pip insatll cbpi +``` + +## Sensor ```python # -*- coding: utf-8 -*- @@ -11,7 +27,9 @@ import random from aiohttp import web from cbpi.api import * - +''' +Make sure to extend CBPiSensor +''' @parameters([Property.Number(label="Param1", configurable=True), Property.Text(label="Param2", configurable=True, default_value="HALLO"), From eb0cb4f6b037198fe12e970ef2062d890649323f Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 26 Jan 2021 07:11:58 +0000 Subject: [PATCH 05/13] GitBook: [master] 2 pages modified --- development.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/development.md b/development.md index 1dd1eac..5246662 100644 --- a/development.md +++ b/development.md @@ -9,13 +9,36 @@ How to create virtual env in Python [https://docs.python.org/3/tutorial/venv.html](https://docs.python.org/3/tutorial/venv.html) {% endhint %} -```bash +### 1. Create a virtual env with CBPi +```bash python3 -m venv venv source venv/bin/activate python3 -m pip insatll cbpi ``` +### 2. Create Folder structure + + + +### 3. Add Custom Code + + + +### 4. Test the Code + + + +### 3. Build plugin + + + +### 4. Upload the plugin + +### Full Example + +[https://github.com/Manuel83/cbpi4-ui-plugin](https://github.com/Manuel83/cbpi4-ui-plugin) + ## Sensor ```python From 1ec74322859a764fc60bcd5ae2eb54bf8e0991b3 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 26 Jan 2021 07:17:02 +0000 Subject: [PATCH 06/13] GitBook: [master] one page modified --- development.md | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/development.md b/development.md index 5246662..f441dc5 100644 --- a/development.md +++ b/development.md @@ -101,3 +101,78 @@ def setup(cbpi): cbpi.plugin.register("CustomSensor", CustomSensor) ``` +## Actor + +```python + +import logging +from unittest.mock import MagicMock, patch + +from cbpi.api import * + + +logger = logging.getLogger(__name__) + +try: + import RPi.GPIO as GPIO +except Exception: + logger.error("Failed to load RPi.GPIO. Using Mock") + MockRPi = MagicMock() + modules = { + "RPi": MockRPi, + "RPi.GPIO": MockRPi.GPIO + } + patcher = patch.dict("sys.modules", modules) + patcher.start() + import RPi.GPIO as GPIO + + +@parameters([Property.Number(label="Param1", configurable=True), + Property.Text(label="Param2", configurable=True, default_value="HALLO"), + Property.Select(label="Param3", options=[1,2,4]), + Property.Sensor(label="Param4"), + Property.Actor(label="Param5")]) +class CustomActor(CBPiActor): + my_name = "" + + # Custom property which can be configured by the user + @action("test", parameters={}) + async def action1(self, **kwargs): + print("ACTION !", kwargs) + self.my_name = kwargs.get("name") + pass + + def init(self): + print("INIT") + + self.state = False + pass + + async def on(self, power=0): + logger.info("ACTOR 1111 %s ON" % self.id) + self.state = True + + async def off(self): + logger.info("ACTOR %s OFF " % self.id) + self.state = False + + def get_state(self): + + return self.state + + async def run(self): + pass + +def setup(cbpi): + + ''' + This method is called by the server during startup + Here you need to register your plugins at the server + + :param cbpi: the cbpi core + :return: + ''' + + cbpi.plugin.register("CustomActor", CustomActor) +``` + From 54a14ac02941c4f74a8be49f41bb34702bedbf9e Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 26 Jan 2021 07:17:10 +0000 Subject: [PATCH 07/13] GitBook: [master] 2 pages modified --- SUMMARY.md | 1 + untitled.md | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 untitled.md diff --git a/SUMMARY.md b/SUMMARY.md index bd79073..cdb4dd1 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -1,5 +1,6 @@ # Table of contents * [CraftBeerPi](README.md) +* [Untitled](untitled.md) * [Development](development.md) diff --git a/untitled.md b/untitled.md new file mode 100644 index 0000000..5094080 --- /dev/null +++ b/untitled.md @@ -0,0 +1,2 @@ +# Untitled + From 69b281b90d1bb23b2b0da42320564e552b4fb6ac Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 26 Jan 2021 07:17:25 +0000 Subject: [PATCH 08/13] GitBook: [master] 2 pages modified --- SUMMARY.md | 1 - untitled.md | 2 -- 2 files changed, 3 deletions(-) delete mode 100644 untitled.md diff --git a/SUMMARY.md b/SUMMARY.md index cdb4dd1..bd79073 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -1,6 +1,5 @@ # Table of contents * [CraftBeerPi](README.md) -* [Untitled](untitled.md) * [Development](development.md) diff --git a/untitled.md b/untitled.md deleted file mode 100644 index 5094080..0000000 --- a/untitled.md +++ /dev/null @@ -1,2 +0,0 @@ -# Untitled - From c0e1f79355c113c537cc511e48b5b31db1806be8 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 26 Jan 2021 07:24:16 +0000 Subject: [PATCH 09/13] GitBook: [master] 2 pages modified --- SUMMARY.md | 1 + untitled.md | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 untitled.md diff --git a/SUMMARY.md b/SUMMARY.md index bd79073..7fd8be3 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -2,4 +2,5 @@ * [CraftBeerPi](README.md) * [Development](development.md) +* [Untitled](untitled.md) diff --git a/untitled.md b/untitled.md new file mode 100644 index 0000000..84b080f --- /dev/null +++ b/untitled.md @@ -0,0 +1,4 @@ +# Untitled + +Test + From 0209286ce0070d827ee7bdeb34e70596efeef444 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 26 Jan 2021 07:26:52 +0000 Subject: [PATCH 10/13] GitBook: [master] 3 pages modified --- untitled.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/untitled.md b/untitled.md index 84b080f..8ef58ef 100644 --- a/untitled.md +++ b/untitled.md @@ -1,4 +1,4 @@ # Untitled -Test +Test111 From e29437e076c05f895fba13f275c575cf7a39053e Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 26 Jan 2021 07:29:10 +0000 Subject: [PATCH 11/13] GitBook: [master] 2 pages modified --- SUMMARY.md | 1 - untitled.md | 4 ---- 2 files changed, 5 deletions(-) delete mode 100644 untitled.md diff --git a/SUMMARY.md b/SUMMARY.md index 7fd8be3..bd79073 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -2,5 +2,4 @@ * [CraftBeerPi](README.md) * [Development](development.md) -* [Untitled](untitled.md) diff --git a/untitled.md b/untitled.md deleted file mode 100644 index 8ef58ef..0000000 --- a/untitled.md +++ /dev/null @@ -1,4 +0,0 @@ -# Untitled - -Test111 - From a8d40109ccc40df480f024529eee9451d3f20bb3 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 26 Jan 2021 12:59:39 +0000 Subject: [PATCH 12/13] GitBook: [master] one page modified --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 66ba0b6..1647cdd 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,12 @@ CraftBeerPi is an open source brewing controller. ## Installation -CraftBeerPi is python based and will require at last python 3.7.x +CraftBeerPi is python based and will require at last python 3.7.x +You can run CBPi 4.x on your Laptop. + +Download an install Python 3.7 [https://www.python.org/downloads/](https://www.python.org/downloads/) + +Open a terminal window and run the following commands. ```text sudo python3 -m pip install cbpi @@ -20,6 +25,8 @@ cbpi setup cbpi start ``` +The server is running under http://localhost:8000 by default. + ## Links {% embed url="https://www.facebook.com/groups/craftbeerpi" %} From b3606b03754ff8866cc4403d71fdadc330c24244 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 26 Jan 2021 13:00:19 +0000 Subject: [PATCH 13/13] GitBook: [master] one page modified --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1647cdd..77eb82b 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ CraftBeerPi is an open source brewing controller. ## Installation CraftBeerPi is python based and will require at last python 3.7.x -You can run CBPi 4.x on your Laptop. +You can run CBPi 4.x on your Laptop. It's not required to use a Raspberry Pi. Download an install Python 3.7 [https://www.python.org/downloads/](https://www.python.org/downloads/)