Smart Light SDK

From Atomation's Wiki
Jump to: navigation, search

Atomation’s mobile SDK is already integrated with Atomation's Hardware SDK wrapping it with a friendly API. The SDK will let you take advantage of all features included in the Hardware SDK (i.e. IMU, Temperature, Humidity, ADC read, RGB Led lighting, Motor controller, Transistors, Relays and more!). All can be easily controlled and the specific functions are up to you.

Getting Atomation's SDK


Visit the Atomation website and click on Download SDK tab.

Login at Atomation

After registration, Login at the Atomation website and reach the Admin. On the Admin Home Page, you will find instructions and guidelines.

Add your Application

Once you have logged in you should start defining your first app:

Your application's name.
A brief description of your application.
The name of the application package (from the IDE).

Adding the SDK and Setting the Token

Add the following line to Module-level /app/build.gradle before dependencies:

repositories {

Add the compile dependency in the build.gradle file:

 compile 'net.atomation.smartlight:sdk:1.0.0'

Add a meta-data element to the application element in the AndroidManifest.xml file:

<application android:label="@string/app_name" ...>
    <meta-data android:name="net.atomation.Token" android:value="ExampleToken" />

The meta-data value (ExampleToken) is Atomation's Token. The Token can be found in the center column in My Applications.


Atom Nucleus (the controller of the HW SDK) uses BLE to communicate with the mobile device. To work with this protocol you need to know and understand a few terms:

The Mobile device that handles the communication.
The Hardware SDK.
MAC Address 
A six byte hex number which represents a physical address of the peripheral, two peripherals cannot share the same MAC Address.
Received Signal Strength Indicator, how powerful a signal is, measured in Dbm.
A state that the peripheral advertises itself when not connected.
Device Name 
The name advertised by the peripheral.
The way to send information to the peripheral device.
The way to get data once (for each read) from the peripheral.

Initialize Atomation's SDK

The Atomation SDK is initialized by using a simple method:

public static void init(android.content.Context context, net.atomation.atomationsdk.api.ISdkInitializationListener listener)

For example:

AtomationSdk.init(this.getApplicationContext(), new ISdkInitializationListener() {
            public void onInitialized() {
                //do something

            public void onError(ErrorFactory.AtomationError error) {
                //do something

We recommend to implement the initialization in App.onCreate().

Creating Your First Atom

Atoms are objects that represent the Atom Nucleus and any additional skins. To create your Atom use the following methods:

public static net.atomation.atomationsdk.api.IRgbAtom getAtom(String macAddress)
public static net.atomation.atomationsdk.api.IRgbAtom createAtom(String deviceAddress)

The "macAddress" parameter is a String that represents the MAC address of the desired peripheral. For this example, we will set the MAC address of the peripheral to 80:30:DC:0C:EA:A6

macAddress = "80:30:DC:0C:EA:A6";

The implementation should be as follows:

IRgbAtom atom = AtomationRgbAtomManager.getAtom(macAddress);
if (atom == null) {
       atom = AtomationRgbAtomManager.createAtom(macAddress);

Connecting to the Atom

There are two steps to connect to the Atom:

  1. Create a listener that implements the SDK's IConnectionStateListener.
  2. Send that listener to the the Atom's method "connect" as follows:
atom.connect(new MyConnectionStateListener());
   public class MyConnectionStateListener implements IConnectionStateListener{

        public void onDeviceConnected() {

        public void onDeviceDisconnect() {


        public void onConnectionError(ErrorFactory.AtomationError error) {

To disconnect, use the method "disconnect" in the same way as the "connect" method.

Using the Atom on Connection

After connecting to the Atom, you can control the LED colors by writing the desired RGB values using this method:

public abstract void writeRGB(int ledId,
                              int red,
                              int green,
                              int blue,
                              net.atomation.atomationsdk.api.IWriteListener listener)

The argument "ledId" is:
Use the first one to control the first LED, and the second one for the others.

"IWriteListener" is another listener provided by the Atomation SDK.

A possible implementation can be:

 atom.writeRGB(IRgbAtom.AtomationLedId.LED_2, 0x00, 0x00, 0xFF, new IWriteListener() {
                    public void onWriteExecuted() {
                        //do something

                    public void onWriteError(ErrorFactory.AtomationError error) {
                        //do something