# Tutorials/OpenWrt Tutorials/UBUS_Tutorial/Part1_Ubus_Intro

Last edited by greenbreakfast, 2016-04-14 22:28:17

## Introduction to UBUS

This is the first part of a mini series dedicated to introducing users of the Omega to one of the most powerful tools on OpenWRT, the ubus. We strongly recommend users to go through our Linux Basics tutorial, found here, prior to proceeding with this tutorial series. Furthermore, users should be comfortable with shell scripting to get the most out of this tutorial. This series may seem challenging, however, completing it is paramount to realizing the full potential of the Omega and your projects. Without further ado.

#### What Is Ubus?

The ubus is an interface that allows users to access and use services from the same place. Some services are built-in to OpenWRT and other services are executable files that we have created ourselves.

##### Example

The best way to understand ubus is to study some examples of how we use. To start, let's take a look at how to use the ubus. Enter this into your command line.

ubus

The command has given us some options, that we can pass in.

Let's try using the list option to see what services are available to us.

ubus list

You should have a screen that looks like this. Fear not if you have a slightly different list, we may have updated somethings.

Let's try using the onion service, to do some function. But first we have to what we have functions we have available and how to access them. In general, we can do this by entering this.

ubus list -v servicename

Since, we are interested in what the onion has to offer enter this into the command line.

ubus list -v onion

You should see a screen like this.

Now lets try to get the omega to blink the LED on the Omega using the heartbeat option. Similar to how we did it in this tutorial.

To do this we have to use the call option provided by ubus to access the onion service. We then select the function we want and pass the additional parameters using a json format. To re-iterate:

ubus call <service> <function> '{<JSON parameters>}'

Specifically, enter this into the command line.

ubus call onion omega-led '{"set_trigger":"heartbeat"}'

And see what happen's to the Omega's LED. It should mimic a heartbeat. Now that we have used ubus let's take a more intricate look a what happened behind the scenes.

### The Ubus Structure

The figure below is a basic outline of how ubus works.

In the previous example we connected to ubus via the ubus command line interface, ubus_cli on the figure. The ubus allowed us connect to onion service through the rcpd, which we will discuss in depth later on. Once the onion service executed the requested function, the ouput was relayed back to the ubus_cli via the ubus.

The ubus gives us a very powerful tool for accessing Omega's services both locally and remotely. For example, when we use the Omega as a server, we can use the httpd-mod-ubus service to connect to the Omega's ubus locally. Also if we are using the Omega's cloud, we can connect to the Omega's ubus through the onion device client service.