Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jul 25, 2024
1 parent 7d12a1e commit 040c656
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 23 deletions.
25 changes: 17 additions & 8 deletions developer-guide/03-Background jobs/02-writing-background-jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ class IntroJob(BackgroundJob):

if __name__ == "__main__":
from pioreactor.whoami import get_unit_name
from pioreactor.whoami import get_latest_experiment_name
from pioreactor.whoami import get_assigned_experiment_name

job = IntroJob(unit=get_unit_name(), experiment=get_latest_experiment_name())
unit = get_unit_name()
experiment = get_unit_name(unit)

job = IntroJob(unit=unit, experiment=experiment)


job.block_until_disconnected()
Expand All @@ -163,9 +166,12 @@ Adding an additional line in `intro_job.py`:
```python {6}
if __name__ == "__main__":
from pioreactor.whoami import get_unit_name
from pioreactor.whoami import get_latest_experiment_name
from pioreactor.whoami import get_assigned_experiment_name

unit = get_unit_name()
experiment = get_assigned_experiment_name(unit)

job = IntroJob(unit=get_unit_name(), experiment=get_latest_experiment_name())
job = IntroJob(unit=unit, experiment=experiment)
job.set_intensity(10)

job.block_until_disconnected()
Expand Down Expand Up @@ -396,18 +402,21 @@ def click_motor_driver(initial_dc, hz):
"""
Start the external motor
"""
from pioreactor.whoami import get_unit_name, get_latest_experiment_name
from pioreactor.whoami import get_unit_name, get_assigned_experiment_name

unit = get_unit_name()
experiment = get_assigned_experiment_name(unit)

job = MotorDriver(
hz=hz,
initial_duty_cycle=initial_dc,
unit=get_unit_name(),
experiment=get_latest_experiment_name(),
unit=unit,
experiment=experiment,
)
job.block_until_disconnected()
```

Note the helper functions `get_unit_name` and `get_latest_experiment_name` to get the metadata for the class. The method `block_until_disconnected` will halt the program at that line (and only continue when a keyboard interrupt is detected).
Note the helper functions `get_unit_name` and `get_assigned_experiment_name` to get the metadata for the class. The method `block_until_disconnected` will halt the program at that line (and only continue when a keyboard interrupt is detected).

If you save it in the `plugins` folder, you can now execute: `pio run motor_driver --initial-dc 10` and it should just work! You can exit with ctrl-c, and note that the `on_disconnect` is called when you do this.

Expand Down
2 changes: 1 addition & 1 deletion developer-guide/04-Automations/03-writing-automations-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Let's design a simple LED automation for Light/Dark cycles. The basic idea is th
# -*- coding: utf-8 -*-
from __future__ import annotations
from pioreactor.automations.led.base import LEDAutomationJobContrib
from pioreactor.whoami import get_unit_name, get_latest_experiment_name
from pioreactor.whoami import get_unit_name, get_assigned_experiment_name
from pioreactor.automations import events
```

Expand Down
6 changes: 3 additions & 3 deletions developer-guide/05-Scripts/01-writing-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Since the behaviour of the Pioreactor is controlled by Python objects, you can w
```python
from pioreactor.background_jobs.stirring import Stirrer, RpmFromFrequency
from pioreactor.whoami import get_unit_name
from pioreactor.whoami import get_latest_experiment_name
from pioreactor.whoami import get_assigned_experiment_name

unit = get_unit_name()
experiment = get_latest_experiment_name()
experiment = get_assigned_experiment_name(unit)

st = Stirrer(
target_rpm=300,
Expand All @@ -29,7 +29,7 @@ st.block_until_disconnected() # pauses the execution, but stirring continues
Save this code to a local file on your Pioreactor's Raspberry Pi called `stirring_script.py`. Then, running `python stirring_scripy.py`, you should see that stirring on the Pioreactor starts. With the script running, you should also updates on the Pioreactor UI (ex: see [pioreactor.local/pioreactors](http://pioreactor.local/pioreactors) page). Typing `ctrl-c` will exit the script.

:::info
What is `get_unit_name` and `get_latest_experiment_name`? These are helper functions that get the current name of the Pioreactor, and the current experiment name, respectively. Using the current experiment name will ensure that your data shows up in the UI, and is correctly stored in the database.
What is `get_unit_name` and `get_assigned_experiment_name`? These are helper functions that get the current name of the Pioreactor, and the current experiment name, respectively. Using the current experiment name will ensure that your data shows up in the UI, and is correctly stored in the database.
:::


Expand Down
9 changes: 6 additions & 3 deletions developer-guide/07-Plugins/01-intro-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Here's an example: place the following code into the file `/home/pioreactor/.pio
```python title="/home/pioreactor/.pioreactor/plugins/demo_job.py"
# -*- coding: utf-8 -*-
import click
from pioreactor.whoami import get_unit_name, get_latest_experiment_name
from pioreactor.whoami import get_unit_name, get_assigned_experiment_name
from pioreactor.background_jobs.base import BackgroundJob

__plugin_summary__ = "Just a demo job"
Expand All @@ -78,9 +78,12 @@ class DemoJob(BackgroundJob):

@click.command(name="demo_job", help=__plugin_summary__)
def click_demo_job():

unit = get_unit_name()
experiment = get_assigned_experiment_name(unit)
job = DemoJob(
unit=get_unit_name(),
experiment=get_latest_experiment_name(),
unit=unit,
experiment=experiment,
)
job.block_until_disconnected()
```
Expand Down
9 changes: 6 additions & 3 deletions developer-guide/10-Hardware/06-button-down.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ An example to pause a job over MQTT:
```python
from pioreactor.background_jobs.monitor import Monitor
from pioreactor.pubsub import publish
from pioreactor.whoami import get_latest_experiment_name, get_unit_name
from pioreactor.whoami import get_assigned_experiment_name, get_unit_name

target="od_reading"

def pause(*args):
publish(f"pioreactor/{get_unit_name()}/{get_latest_experiment_name()}/{target}/$state/set", "sleeping")
unit = get_unit_name()
experiment = get_assigned_experiment_name(unit)

publish(f"pioreactor/{unit}/{experiment}/{target}/$state/set", "sleeping")

def unpause(*args):
publish(f"pioreactor/{get_unit_name()}/{get_latest_experiment_name()}/{target}/$state/set", "ready")
publish(f"pioreactor/{unit}/{experiment}/{target}/$state/set", "ready")

Monitor.add_pre_button_callback(pause)
Monitor.add_post_button_callback(unpause)
Expand Down
4 changes: 2 additions & 2 deletions user-guide/03-Extending your Pioreactor/11-using-stemma-qt.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ import board
import adafruit_scd4x

from pioreactor.pubsub import publish
from pioreactor.whoami import get_unit_name, get_latest_experiment_name
from pioreactor.whoami import get_unit_name, get_assigned_experiment_name

i2c = board.I2C()
scd4x = adafruit_scd4x.SCD4X(i2c)

exp = get_latest_experiment_name()
unit = get_unit_name()
exp = get_assigned_experiment_name(unit)

scd4x.start_periodic_measurement()

Expand Down
5 changes: 3 additions & 2 deletions user-guide/30-Advanced/01-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ The leader also has their own unique set of `pio` commands (these commands do no
* `pio mqtt`: tail the MQTT broker.
* `pio update ui` will update the UI software to the latest version and adding `--app` will upgrade the Pioreactor Python app (repo: pioreactor/pioreactor).
* `pio update app` will update the software to the latest version.
* `pio cluster-status` will report to the user each Pioreactor in the cluster, and metadata like status, IP, and state.
* `pio workers` has many subcommands for manager your cluster. For example:
* `pio workers add <hostname>`: add a Pioreactor to your cluster, with given (unique) name. Need a worker Pioreactor on the network first. See instructions [here](https://github.com/Pioreactor/pioreactor/wiki/Installation).
* `pio workers discover` will return a list of workers on the network (may be a superset of the current cluster.)
* `pio workers status` will report to the user each Pioreactor in the cluster, and metadata like status, IP, and state.

#### Leader-only commands to control workers

Expand All @@ -44,7 +44,8 @@ The leader computer interacts with the worker computers using the `pios` command
* `pios run <job>` on each worker, run the job `<job>` in the background. Job specific arguments can be specified after. Ex: `pios run add_media --ml 1`. Use `-y` to skip confirmation.
* `pios update` install the latest PioreactorApp code on each worker.
* `pios sync-configs` deploy the config.ini files to workers.
* `pios install-plugin <plugin name>` will install the plugin on each worker _and_ the leader.
* `pios plugins install <plugin name>` will install the plugin on each worker _and_ the leader.
* `pios plugins uninstall <plugin name>` will uninstall the plugin on each worker _and_ the leader.
* `pios reboot` will reboot all workers, by default, in the cluster. See `--units` arg below.
* `pios shutdown` will shut down all workers, by default, in the cluster. See `--units` arg below.
* `pios cp <filepath>` will copy (and overwrite) `filepath` on the leader to all the workers.
Expand Down
2 changes: 1 addition & 1 deletion user-guide/50-Troubleshooting/UI troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Your IP may be different than the one above.

#### If you are using a remote access service, like ngrok or tailscale

Likely you didn't fill out the `ws` parameter in the configuration correctly. See the [remote access instructions](https://docs.pioreactor.com/user-guide/remote-access) again.
Likely you didn't fill out the `mqtt` `broker_address` parameter in the configuration correctly. See the [remote access instructions](https://docs.pioreactor.com/user-guide/remote-access) again.


### When I click an action in the UI, I don't see any response. Or the button just spins and does nothing.
Expand Down

0 comments on commit 040c656

Please sign in to comment.