Skip to main content

Reading A Sensor

Introduction To Squirrel Applications Example 1

Begin by learning the basics of programming Electric Imp applications. We will use the Electric Imp HTS221 library to take temperature and humidity readings from a sensor. We will also use the Initial State library to send the data we collect from the sensor to a cloud service.

This code can be easily configured for use with an impExplorer™ Developer Kit, impAccelerator™ Battery Powered Sensor Node or impC001 Breakout Board.

Skill Level

Beginner

This example will focus on writing Squirrel code. If you have not already done so, please visit the Getting Started Guide to learn how to configure your device with BlinkUp™ and how to use the Electric Imp IDE, impCentral™.

What You Learn

  • How to use Electric Imp libraries.
  • How to configure a device’s sensor and take synchronous readings.
  • How to exchange data between device and agent.
  • How to send data to a cloud service such as Initial State.

What You Need

Instructions

  • Activate your device with BlinkUp.
  • Log into impCentral.
  • Create a new Product and Development Device Group.
  • Copy and paste the Device Code into the Device Code pane in the impCentral code editor.
  • Enter the i2c hardware object for your device into the i2c variable on line 32.
  • Copy and paste the Agent Code into the Agent Code pane in the impCentral code editor.
  • Sign into Initial State.
  • Find your Streaming Access Key on the My Account page.
  • Navigate back to impCentral.
  • In the Agent Code, enter your Initial State Streaming Access Key into the STREAMING_ACCESS_KEY constant on line 19.
  • Hit the Build and Force Restart button to start the code.
  • Note the agent ID in the logs.
  • Navigate back to Initial State, find the Bucket that matches your agent ID.
  • Watch your data update in the Source, Lines, Waves, and Tile views on the Initial State website.

Code

Device Code

Agent Code