Build A Simple IoT Application With Electric Imp Hardware And The Losant Application Enablement Platform
Electric Imp’s impExplorer™ Kit features on-board temperature, humidity and pressure sensors. Those values can be read and sent to Losant, an application enablement platform which provides components and tools that allow you to build end-user IoT applications. You can create dashboards, APIs, web pages and full-blown user experiences directly from within the platform.
In this tutorial, we’ll configure the impExplorer to read sensor data and periodically send that data to its agent, which is a virtual device twin in the cloud. Every device on the Electric Imp Platform has its own, unique agent, which mediates all communications between device and the wider Internet, keeping the device secure. When it receives sensor data from the device, your impExplorer’s agent will forward that data to Losant using Electric Imp’s Losant integration.
Note If you’d like to try this tutorial with a different imp-enabled device, you’ll need to modify the device code’s i2c variable in the EnvMonitor class constructor to match the I²C bus used on your hardware:
The device code is simply reading the temperature, humidity and pressure using the impExplorer’s on-board sensors. It then sends the readings to its agent. This process occurs once every second.
The “sending” happens on this line:
The agent code listens for sensor readings using this line:
When readings arrive, it sends them to Losant via an HTTP POST request. This is done in the sendData() function.
Simultaneously, the agent is listening for commands from the Losant dashboard:
This registers a number of functions that will be called when the Losant library receives a message from the dashboard. The function _commandHandler() is called and this just logs that the command has been received.
Here is the code you need for your impExplorer (the device code) and its online partner, the agent. Just copy and paste each listing into the relevant pane within impCentral’s code editor.