-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Juliana Mashon
authored and
Juliana Mashon
committed
Aug 15, 2024
1 parent
e77e0f0
commit b5e59db
Showing
22 changed files
with
1,249 additions
and
1,101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,169 +1,120 @@ | ||
# sidecar-starter-pack | ||
Authentication and communication utilities for FarmBot sidecars | ||
|
||
## 📖 Contents | ||
|
||
* [Installation](#-installation-mac-os) | ||
* [Getting Started](#-getting-started) | ||
* [Functions](#-functions) | ||
* [Setup](#setup) | ||
* [Information](#information) | ||
* [Messaging](#messaging) | ||
* [Basic Commands](#basic-commands) | ||
* [Movement](#movement) | ||
* [Peripherals](#peripherals) | ||
* [Broker Commands](#broker-commands) | ||
* [Developer Info](#-developer-info) | ||
* [api_connect.py](#api_connectpy) | ||
* [broker_connect.py](#broker_connectpy) | ||
|
||
## 💻 Installation (Mac OS) | ||
To set up the project locally, follow these steps: | ||
|
||
(1) Clone the repository. | ||
``` | ||
git clone https://github.com/FarmBot-Labs/sidecar-starter-pack | ||
``` | ||
## :book: Contents | ||
|
||
(2) Navigate to the project directory. | ||
``` | ||
cd path/to/sidecar-starter-pack | ||
``` | ||
* [Installation](#computer-installation-mac-os) | ||
* [Getting Started](#seedling-getting-started) | ||
* [Get your authentication token](#get-your-authentication-token) | ||
* [Configure echo and verbosity](#configure-echo-and-verbosity) | ||
* [Functions](#compass-functions) | ||
* [Developer Info](#toolbox-developer-info) | ||
* [Formatting message broker messages](#formatting-message-broker-messages) | ||
* [Formatting API requests](#formatting-api-requests) | ||
|
||
(3) Create a virtual environment. | ||
``` | ||
python -m venv path/to/venv/location | ||
``` | ||
## :computer: Installation (Mac OS) | ||
|
||
(4) Activate the virtual environment. | ||
``` | ||
source path/to/venv/bin/activate | ||
``` | ||
## :seedling: Getting Started | ||
|
||
(5) Install the required libraries within venv: | ||
Import `main.py` and create an instance of the Farmbot class: | ||
``` | ||
python3 -m pip install requests | ||
python3 -m pip install paho-mqtt | ||
``` | ||
|
||
## 🌱 Getting Started | ||
To generate your authorization token and get started: | ||
|
||
(1) Import `main.py` and create an instance. | ||
``` | ||
from farmbot_utilities import Farmbot | ||
from main.py import Farmbot | ||
bot = Farmbot() | ||
``` | ||
|
||
(2) Generate your authorization token. | ||
The server is https://my.farm.bot by default. | ||
``` | ||
bot.get_token('email', 'password', 'server') | ||
``` | ||
### Get your authentication token | ||
|
||
(3.1) To interact with your Farmbot via the API, try getting your device info: | ||
``` | ||
bot.get_info('device') | ||
``` | ||
### Configure echo and verbosity | ||
|
||
(3.2) Try editing your device name: | ||
``` | ||
bot.edit_info('device', 'name', 'Carrot Commander') | ||
``` | ||
> [!NOTE] | ||
> To interact with your Farmbot via the message broker, you must first establish a connection. Publishing single messages without establishing a connection may trigger your device rate limit. | ||
## :compass: Functions | ||
|
||
(4.1) Connect to the message broker: | ||
``` | ||
bot.connect_broker() | ||
sidecar-starter-pack/ | ||
├── functions/ | ||
│ ├── __init__.py | ||
│ ├── authentication.py | ||
│ ├── basic_commands.py | ||
│ ├── broker.py | ||
│ ├── camera.py | ||
│ ├── imports.py | ||
│ ├── information.py | ||
│ ├── jobs.py | ||
│ ├── messages.py | ||
│ ├── movements.py | ||
│ ├── peripherals.py | ||
│ ├── resources.py | ||
│ └── tools.py | ||
├── tests/ | ||
│ ├── __init__.py | ||
│ └── tests_main.py | ||
├── __init.py__ | ||
├── imports.py | ||
├── main.py | ||
└── README.md | ||
``` | ||
|
||
(4.2) Try sending a new log message: | ||
``` | ||
bot.send_message('Hello from the message broker!', 'success') | ||
``` | ||
|
||
(4.3) Try sending a movement command: | ||
``` | ||
bot.move(30,40,10) | ||
``` | ||
|
||
(4.5) After sending messages, don't forget to disconnect from the message broker: | ||
``` | ||
bot.disconnect_broker() | ||
``` | ||
|
||
## 🧭 Functions | ||
> [!TIP] | ||
> Functions marked with [API] communicate with the Farm Designer web app via the [REST API](https://developer.farm.bot/v15/docs/web-app/rest-api.html) and those marked with [BROKER] communicate with the FarmBot via the [message broker](https://developer.farm.bot/v15/docs/message-broker). | ||
### Setup | ||
### authentication.py | ||
class `Authentication()` | ||
|
||
`get_token()` generates user authentication token; call before any other function | ||
`connect_broker()` establishes persistent connect to message broker | ||
`disconnect_broker()` disconnects from the message broker | ||
`listen_broker()` displays messages sent to/from message broker | ||
### basic_commands.py | ||
class `BasicCommands()` | ||
|
||
### Information | ||
### broker.py | ||
class `BrokerConnect()` | ||
|
||
`get_info()` returns information about a specific endpoint | ||
`set_info()` edits information belonging to preexisting endpoint | ||
env() | ||
group() | ||
curve() | ||
read_status() | ||
read_sensor() | ||
safe_z() | ||
garden_size() | ||
### camera.py | ||
class `Camera()` | ||
|
||
### Messaging | ||
### information.py | ||
class `Information()` | ||
|
||
`log()` sends a new log message via the API | ||
`message()` sends a new log message via the message broker | ||
`debug()` sends a log message of type 'debug' via the message broker | ||
`toast()` sends a log message of type 'toast' via the message broker | ||
|
||
### Basic Commands | ||
|
||
wait() | ||
e_stop() | ||
unlock() | ||
reboot() | ||
shutdown() | ||
|
||
### Movement | ||
> [!CAUTION] | ||
> Making requests other than `GET` to the API will permanently alter the data in your account. `DELETE` and `POST` requests may destroy data that cannot be recovered. Altering data through the API may cause account instability. | ||
move() | ||
set_home() | ||
find_home() | ||
axis_length() | ||
> [!NOTE] | ||
> Not sure which endpoint to access? [Find the list here](https://developer.farm.bot/v15/docs/web-app/api-docs). | ||
### Peripherals | ||
### jobs.py | ||
class `JobHandling()` | ||
|
||
control_peripheral() | ||
toggle_peripheral() | ||
on() | ||
off() | ||
### messages.py | ||
class `MessageHandling()` | ||
|
||
### Broker Commands | ||
### movement.py | ||
class `MovementControls()` | ||
|
||
calibrate_camera() | ||
control_servo() | ||
take_photo() | ||
soil_height() | ||
detect_weeds() | ||
### peripherals.py | ||
class `Peripherals()` | ||
|
||
## 🧰 Developer Info | ||
### resources.py | ||
class `Resources()` | ||
|
||
### api_connect.py | ||
Background: https://developer.farm.bot/v15/docs/web-app/rest-api | ||
### tools.py | ||
class `ToolControls()` | ||
|
||
Formatting: functions in `api_functions.py` and `main.py` which interact with the API require an endpoint, which is truncated onto the HTTP request. | ||
## :toolbox: Developer Info | ||
|
||
List of endpoints: https://developer.farm.bot/v15/docs/web-app/api-docs | ||
### Formatting message broker messages | ||
|
||
> [!CAUTION] | ||
> Making requests other than GET to the API will permanently alter the data in your account. DELETE and POST requests may destroy data that cannot be recovered. Altering data through the API may cause account instability. | ||
> [!NOTE] | ||
> Messages sent via the message broker contain [CeleryScript nodes](https://developer.farm.bot/v15/docs/celery-script/nodes.html) which require special formatting. | ||
### broker_connect.py | ||
Background: https://developer.farm.bot/v15/docs/message-broker | ||
``` | ||
message = { | ||
"kind": "rpc_request", | ||
"args": { | ||
"label": # node, | ||
"priority": # number | ||
}, | ||
"body": [ | ||
{ | ||
# instructions | ||
} | ||
] | ||
} | ||
``` | ||
|
||
Formatting: functions in `broker_functions.py` and `main.py` which interact with the message broker send a message containing CeleryScript. The messages require the pre-formatted `RPC_request` included in `broker_functions.py` as the first line of the message. | ||
### Formatting API requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
""" | ||
Initialization for main module. | ||
""" |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.