Skip to content

Commit b5e59db

Browse files
Juliana MashonJuliana Mashon
Juliana Mashon
authored and
Juliana Mashon
committed
Reorg v1--tokens not set correctly
1 parent e77e0f0 commit b5e59db

22 files changed

+1249
-1101
lines changed

LICENSE

-21
This file was deleted.

README.md

+85-134
Original file line numberDiff line numberDiff line change
@@ -1,169 +1,120 @@
11
# sidecar-starter-pack
22
Authentication and communication utilities for FarmBot sidecars
33

4-
## 📖 Contents
5-
6-
* [Installation](#-installation-mac-os)
7-
* [Getting Started](#-getting-started)
8-
* [Functions](#-functions)
9-
* [Setup](#setup)
10-
* [Information](#information)
11-
* [Messaging](#messaging)
12-
* [Basic Commands](#basic-commands)
13-
* [Movement](#movement)
14-
* [Peripherals](#peripherals)
15-
* [Broker Commands](#broker-commands)
16-
* [Developer Info](#-developer-info)
17-
* [api_connect.py](#api_connectpy)
18-
* [broker_connect.py](#broker_connectpy)
19-
20-
## 💻 Installation (Mac OS)
21-
To set up the project locally, follow these steps:
22-
23-
(1) Clone the repository.
24-
```
25-
git clone https://github.com/FarmBot-Labs/sidecar-starter-pack
26-
```
4+
## :book: Contents
275

28-
(2) Navigate to the project directory.
29-
```
30-
cd path/to/sidecar-starter-pack
31-
```
6+
* [Installation](#computer-installation-mac-os)
7+
* [Getting Started](#seedling-getting-started)
8+
* [Get your authentication token](#get-your-authentication-token)
9+
* [Configure echo and verbosity](#configure-echo-and-verbosity)
10+
* [Functions](#compass-functions)
11+
* [Developer Info](#toolbox-developer-info)
12+
* [Formatting message broker messages](#formatting-message-broker-messages)
13+
* [Formatting API requests](#formatting-api-requests)
3214

33-
(3) Create a virtual environment.
34-
```
35-
python -m venv path/to/venv/location
36-
```
15+
## :computer: Installation (Mac OS)
3716

38-
(4) Activate the virtual environment.
39-
```
40-
source path/to/venv/bin/activate
41-
```
17+
## :seedling: Getting Started
4218

43-
(5) Install the required libraries within venv:
19+
Import `main.py` and create an instance of the Farmbot class:
4420
```
45-
python3 -m pip install requests
46-
python3 -m pip install paho-mqtt
47-
```
48-
49-
## 🌱 Getting Started
50-
To generate your authorization token and get started:
51-
52-
(1) Import `main.py` and create an instance.
53-
```
54-
from farmbot_utilities import Farmbot
21+
from main.py import Farmbot
5522
bot = Farmbot()
5623
```
5724

58-
(2) Generate your authorization token.
59-
The server is https://my.farm.bot by default.
60-
```
61-
bot.get_token('email', 'password', 'server')
62-
```
25+
### Get your authentication token
6326

64-
(3.1) To interact with your Farmbot via the API, try getting your device info:
65-
```
66-
bot.get_info('device')
67-
```
27+
### Configure echo and verbosity
6828

69-
(3.2) Try editing your device name:
70-
```
71-
bot.edit_info('device', 'name', 'Carrot Commander')
72-
```
73-
> [!NOTE]
74-
> 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.
29+
## :compass: Functions
7530

76-
(4.1) Connect to the message broker:
7731
```
78-
bot.connect_broker()
32+
sidecar-starter-pack/
33+
├── functions/
34+
│ ├── __init__.py
35+
│ ├── authentication.py
36+
│ ├── basic_commands.py
37+
│ ├── broker.py
38+
│ ├── camera.py
39+
│ ├── imports.py
40+
│ ├── information.py
41+
│ ├── jobs.py
42+
│ ├── messages.py
43+
│ ├── movements.py
44+
│ ├── peripherals.py
45+
│ ├── resources.py
46+
│ └── tools.py
47+
├── tests/
48+
│ ├── __init__.py
49+
│ └── tests_main.py
50+
├── __init.py__
51+
├── imports.py
52+
├── main.py
53+
└── README.md
7954
```
8055

81-
(4.2) Try sending a new log message:
82-
```
83-
bot.send_message('Hello from the message broker!', 'success')
84-
```
85-
86-
(4.3) Try sending a movement command:
87-
```
88-
bot.move(30,40,10)
89-
```
90-
91-
(4.5) After sending messages, don't forget to disconnect from the message broker:
92-
```
93-
bot.disconnect_broker()
94-
```
95-
96-
## 🧭 Functions
56+
> [!TIP]
57+
> 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).
9758
98-
### Setup
59+
### authentication.py
60+
class `Authentication()`
9961

100-
`get_token()` generates user authentication token; call before any other function
101-
`connect_broker()` establishes persistent connect to message broker
102-
`disconnect_broker()` disconnects from the message broker
103-
`listen_broker()` displays messages sent to/from message broker
62+
### basic_commands.py
63+
class `BasicCommands()`
10464

105-
### Information
65+
### broker.py
66+
class `BrokerConnect()`
10667

107-
`get_info()` returns information about a specific endpoint
108-
`set_info()` edits information belonging to preexisting endpoint
109-
env()
110-
group()
111-
curve()
112-
read_status()
113-
read_sensor()
114-
safe_z()
115-
garden_size()
68+
### camera.py
69+
class `Camera()`
11670

117-
### Messaging
71+
### information.py
72+
class `Information()`
11873

119-
`log()` sends a new log message via the API
120-
`message()` sends a new log message via the message broker
121-
`debug()` sends a log message of type 'debug' via the message broker
122-
`toast()` sends a log message of type 'toast' via the message broker
123-
124-
### Basic Commands
125-
126-
wait()
127-
e_stop()
128-
unlock()
129-
reboot()
130-
shutdown()
131-
132-
### Movement
74+
> [!CAUTION]
75+
> 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.
13376
134-
move()
135-
set_home()
136-
find_home()
137-
axis_length()
77+
> [!NOTE]
78+
> Not sure which endpoint to access? [Find the list here](https://developer.farm.bot/v15/docs/web-app/api-docs).
13879
139-
### Peripherals
80+
### jobs.py
81+
class `JobHandling()`
14082

141-
control_peripheral()
142-
toggle_peripheral()
143-
on()
144-
off()
83+
### messages.py
84+
class `MessageHandling()`
14585

146-
### Broker Commands
86+
### movement.py
87+
class `MovementControls()`
14788

148-
calibrate_camera()
149-
control_servo()
150-
take_photo()
151-
soil_height()
152-
detect_weeds()
89+
### peripherals.py
90+
class `Peripherals()`
15391

154-
## 🧰 Developer Info
92+
### resources.py
93+
class `Resources()`
15594

156-
### api_connect.py
157-
Background: https://developer.farm.bot/v15/docs/web-app/rest-api
95+
### tools.py
96+
class `ToolControls()`
15897

159-
Formatting: functions in `api_functions.py` and `main.py` which interact with the API require an endpoint, which is truncated onto the HTTP request.
98+
## :toolbox: Developer Info
16099

161-
List of endpoints: https://developer.farm.bot/v15/docs/web-app/api-docs
100+
### Formatting message broker messages
162101

163-
> [!CAUTION]
164-
> 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.
102+
> [!NOTE]
103+
> Messages sent via the message broker contain [CeleryScript nodes](https://developer.farm.bot/v15/docs/celery-script/nodes.html) which require special formatting.
165104
166-
### broker_connect.py
167-
Background: https://developer.farm.bot/v15/docs/message-broker
105+
```
106+
message = {
107+
"kind": "rpc_request",
108+
"args": {
109+
"label": # node,
110+
"priority": # number
111+
},
112+
"body": [
113+
{
114+
# instructions
115+
}
116+
]
117+
}
118+
```
168119

169-
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.
120+
### Formatting API requests

__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
Initialization for main module.
3+
"""

api_functions.py

-92
This file was deleted.

0 commit comments

Comments
 (0)