UbiFunctions

Create, manage, and locally develop UbiFunctions using the Ubidots CLI.

This command allows you to:

  • Perform CRUD operations over UbiFunctions in Ubidots.

  • Set up a local development environment for UbiFunctions.

Its subcommands are:

Usage: ubidots functions [OPTIONS] COMMAND [ARGS]...

 Tool for managing and deploying functions.

โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ --help          Show this message and exit.                                 โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
โ•ญโ”€ Commands โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ add       Adds a new function.                                              โ”‚
โ”‚ delete    Deletes a specific function using its id or label.                โ”‚
โ”‚ get       Retrieves a specific function using its id or label.              โ”‚
โ”‚ list      Lists all available functions.                                    โ”‚
โ”‚ update    Update a function.                                                โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Cloud operations

Create a function

Create an UbiFunction in your Ubidots account.

Get an UbiFunction

Retrieve an UbiFunction from Ubidots.

Update an UbiFunction

Update an existing UbiFunction in Ubidots.

Delete an UbiFunction

Delete an UbiFunction from your Ubidots account.

circle-exclamation

List all UbiFunctions

List all UbiFunctions on your account.

Local development

The Ubidots CLI enables you to set up a fully-featured local development environment for UbiFunctions, replicating runtimes and their included libraries. As specified in the Installing section, Dockerarrow-up-right is required for this.

circle-info

Before starting with local UbiFunctions development, remember to run the ubidots config command in order to properly set the environment's required configuration.

Create a local UbiFunction

Create a new local UbiFunction with the given runtime, method and other settings.

UbiFunction directory structure

Upon creating an UbiFunction, a directory named after it will be created in the current one. This directory will the following:

main file

The main file is the entry point to the UbiFunction, that is, the starting point from where your logic will start to execute.

circle-info

The main file is mandatory, otherwise the UbiFunction won't work properly.

manifest file

The .manifest.yaml contains all the required configuration for UbiFunction. It looks like this:

By editing this file, you can can manually change the UbiFunction's settings; however, it's recommended to use the designated options for each command to make changes.

Start the local development environment

Start the local development environment in order to enable the UbiFunction's execution.

circle-exclamation

After executing, this command will output the following:

circle-info

The displayed URL is where the local UbiFunction is exposed.

Push a local UbiFunction

Push a local UbiFunction to Ubidots cloud.

circle-exclamation

After executing this command and if the UbiFunction doesn't exists yet in the Ubidots cloud, it will prompt you for creating it:

On the other hand, if the function already exists in Ubidots, it will promp you for overwriting:

Pull an UbiFunction from Ubidots

This command is helpful when you've pushed a local UbiFunction to Ubidots, made further changes there, and now want to pull those updates back to your local environment.

circle-exclamation

Example

Create the local UbiFunction

This example creates a local UbiFunction named my-first-function with runtime python3.9:lite. Run the following command:

It will output something like:

Navigate to the UbiFunction's directory and open the main.py file with your preferred text editor. In the main function, locate the following lines:

Then add the following line just below del args['device']

The code should now look like this:

Starting the UbiFunction

Now save the changes and go back to the terminal. Then run the following command to start the local UbiFunction:

The output of that command will look like:

The displayed URL is where the UbiFunction is exposed, thus you can perform HTTP request to it in order to trigger the UbiFunction's execution.

Running the UbiFunction

Perform an HTTP POST request to the given URL by running:

It shoud output the following:

You can confirm proper execution by going to your Ubidots account and checking if there's a new device called first-device-cli containing a variable called temperature holding a value of 78.

Pushing the UbiFunction to Ubidots

After runing locally your UbiFunction and determining it's working as intended, you can deploy it to your production environment (Ubidots) by running:

This will prompt you for overwriting the changes in Ubidots. Upon confirmation, the local changes will be pushed to Ubidots.

Pulling the UbiFunction from Ubidots

If you need to make changes to the UbiFunction's production version and want to edit it from your local machine, you can pull the changes from Ubidots, make the necessary modifications locally, and then push the updates back to Ubidots. Start by pulling the changes by running:

After that, you can use the start, run and push commands as described before.

Last updated

Was this helpful?