Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to publish commands to devices via Meadow.Cloud #341

Merged
merged 1 commit into from
Aug 18, 2023

Conversation

stevenkuhn
Copy link
Contributor

@stevenkuhn stevenkuhn commented Aug 17, 2023

This adds the ability to publish commands to a collection of devices via Meadow.Cloud using Meadow.Cloud's new Command & Control publish command feature. The new command is meadow cloud command publish <COMMAND_NAME>. The generated help text for this new command is:

USAGE
  meadow cloud command publish <COMMAND_NAME> --collectionId <value> [options]

DESCRIPTION
  Publish a command to Meadow devices via the Meadow Service

PARAMETERS
* COMMAND_NAME      The name of the command

OPTIONS
* -c|--collectionId  The target collection for publishing the command
  -a|--args         The arguments for the command as a JSON string
  -q|--qos          The MQTT-defined quality of service for the command Choices: "AtLeastOnce", "AtMostOnce", "ExactlyOnce". Default: "AtLeastOnce".
  --host            Optionally set a host (default is https://www.meadowcloud.co)
  -h|--help         Shows help text.

For this initial version, meadow cloud command publish requires a collectionId which is the collection of Meadow devices that this command will sent. A future update will allow a list of device ids as an additional option.

Example

An example of this command would be:

C:\>meadow login
Signed in as [email protected]
Done!

C:\>meadow cloud command publish TurnOnWater -c example_collection_id -a "{""durationInMinutes"":15}"
Publishing 'TurnOnWater ' command to Meadow.Cloud. Please wait...
Publish command successful.
Done!

If the included arguments are not properly formatted (quotes need to be escaped), a JSON error will occur:

C:\>meadow cloud command publish TurnOnWater -c example_collection_id -a "{"duration":15}"
Provided arguments is not valid JSON: 'd' is an invalid start of a property name. Expected a '"'. LineNumber: 0 | BytePositionInLine: 1.
Done!

Subcommand Changes

This change also bundles up the meadow cloud commands into a single command:

USAGE
  meadow [options]
  meadow [command] [...]

OPTIONS
  -h|--help         Shows help text.
  --version         Shows version information.

COMMANDS
  app deploy        Deploy the specified app to the Meadow
  cloud             Provides Meadow.Cloud service related commands. Subcommands: cloud command, cloud login, cloud logout.
  collection list   List Meadow Collections
  debug             Debug a Meadow Application
  ...more...

Each subcommand under meadow cloud then has its own help file.

meadow cloud --help

USAGE
  meadow cloud [options]
  meadow cloud [command] [...]

DESCRIPTION
  Provides Meadow.Cloud service related commands.

OPTIONS
  -h|--help         Shows help text.

COMMANDS
  command           Provides command & control related commands for devices. Subcommands: command publish.
  login             Log into the Meadow Service
  logout            Logout of the Meadow Service

You can run `meadow cloud [command] --help` to show help on a specific command.
Done!

meadow cloud command --help

USAGE
  meadow cloud command [options]
  meadow cloud command [command] [...]

DESCRIPTION
  Provides command & control related commands for devices.

OPTIONS
  -h|--help         Shows help text.

COMMANDS
  publish           Publish a command to Meadow devices via the Meadow Service

You can run `meadow cloud command [command] --help` to show help on a specific command.
Done!

Copy link
Collaborator

@lamebrain lamebrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. One suggestion.

Meadow.CLI.Core/CloudServices/CommandService.cs Outdated Show resolved Hide resolved
@stevenkuhn stevenkuhn merged commit 91b6206 into develop Aug 18, 2023
6 checks passed
@stevenkuhn stevenkuhn deleted the cloud-command-publish branch August 18, 2023 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants