Electric Imp offers an innovative and powerful Internet of Things platform that securely connects devices with advanced cloud computing resources. Every device on the Electric Imp platform is powered by impOSTM, a small, efficient, secure and operating system. The imp Platform includes unique management layers for full lifecycle management, such as secure Over the Air (OTA) updates, secured communications, and remote monitoring.  Electric Imp seamlessly connects devices to the cloud, enabling innovative commercial and industrial applications that empower manufacturers to manage and quickly scale their connected products and services to millions of users.

Developers can leverage Electric Imp’s platform and Ubidots to quickly deploy end-user ready IoT applications. In this guide you’ll learn how to use Electric Imp's impExplorer™ Kit to send data from the sensors to Ubidots.

The Electric Imp impExplorer™ Kit is the ideal basis for building self-contained connected devices. It includes not only a trio of temperature and humidity, motion, and pressure sensors, but also an RGB LED for visible feedback. In addition, it provides Grove System headers for expansions. Two of these connectors are intended for I²C peripherals, the others for analog and/or digital devices.


In this guide you’ll learn how to use Electric Imp's impExplorer™ Kit to send data from the sensors to Ubidots.

Requirements

Setup

1.- The best way to become familiar with the Imp is to follow their Blinkup guide. Use this guide to connect your impExplorer device to your Electric Imp account. To "Blinkup" please reference the following Blinkup Tutorial.

The most important thing to know is that the Electric Imp IDE is divided in three main windows: agent code, device code, and the log.

  • Agent code window: This code is run in the Imp cloud, not in your device. It allows you to do heavy processing, HTTP requests, store small amounts of data, etc.
  • Device code window: As the name suggests, this code WILL run in your device. Here is where you typically manage your input/ouput pins that connect the Imp to the real world.
  • Log window: Very useful for understanding what’s going on, both in the Agent and in the Device code.

Sending sensors data to the Ubidots Cloud

After completing the Blinkup tutorial and setting up your Ubidots account, you can now program the Imp to send data to Ubidots by following these steps:

1.- Open the Electric Imp IDE. Go to the device section and select the chip icon. Pictured below:

In this section you can see and manages your devices. If this is the first time you're setting up your impExplorer, the MODEL of the device should read "Unassigned." This means your Imp has been detected but is not yet assigned to any project. Now we need to change this and assign it a MODEL.

NOTE: Verify that the STATUS of the device is "Online" as you can see on the image below:

On the right side of the page, go to the "ACTIONS" section and select Settings

You'll see a new windows called "Device Settings". Set the name of your preference to the Imp, select "New Model" and assign it a name too. Remember the model's name will be the name of your project on the Electric Imp IDE. Next, press "Save Changes".

Now, you'll see the new device setting. To program the Imp, go to the ACTIONS section select "Code".

Programming the ImpExplorer

We're going to provide you a code to send the sensors readings to Ubidots. Copy and paste the following code in its respective windows.

NOTE: You have been assigned an Ubidots TOKEN to input into your code, if you do not know how to find your unique Ubidots TOKEN,  the TOKEN from your Ubidots account, please reference to this article.

  • Agent code window
#require "Ubidots.agent.lib.nut:1.0.0"

Ubidots <- Ubidots.Client("Your_Ubidots_TOKEN_here");

Ubidots.setDeviceLabel("impExplorer"); // to set the device label

device.on("saveValue", function(data){
   
    Ubidots.sendToDevice(data);
    server.log("Sending data to Ubidots");
    server.log(http.jsonencode(data));
});
  • Device code window
#require "HTS221.device.lib.nut:2.0.0"
#require "LPS22HB.class.nut:1.0.0"

data <- {};
data.temp <- 0;
data.humid <- 0;
data.pressure <-0;

hardware.i2c89.configure(CLOCK_SPEED_400_KHZ);

// Temperature and humidity sensor
tempHumid <- HTS221(hardware.i2c89);
local dataRate = tempHumid.setMode(HTS221_MODE.CONTINUOUS, 7);

//pressure sensor
pressureSensor <- LPS22HB(hardware.i2c89);
pressureSensor.softReset();


function mainLoop() {
   
    pressureSensor.read(function(result) {
       data.pressure = result.pressure;
   
        tempHumid.read(function(result) {
           
            data.temp = result.temperature;
            data.humid = result.humidity;
           
           
            agent.send("saveValue", data);
           
            imp.wakeup(1.0, mainLoop);
        });

    });
}

mainLoop();

Once you pasted the codes to the respective windows you should see something like this

Now, select the button called "Check" (at the top of your IDE) to verify the program, then select "Build and Run" to upload the code to the ImpExplorer. 

Once the code is uploaded, you will receive the following confirmation messages in the log window:

Confirmation of data connection

Now we need go to your Ubidots account to confirm everything is correct. On the device tab in your Ubidots account, you will see a new device created called "impexplorer." 

Select the device to visualize the sensor readings

Now it is time to create a dashboard to control and manage the variables of your impExplorer. If you don't know how Ubidots widgets work, please check out these video tutorials.

Happy hacking! :)

As always, with any questions or concerns, please contact your friendly Ubidots Engineers for assistance by starting a conversation with our In-App services at Ubidots.com or you may also find your answer in our ever growing Ubidots Help Center.

Did this answer your question?