Skip to main content

Reading A Sensor

Introduction To Squirrel Applications Example 1

Begin by learning the basics of programming Electric Imp. We will use Electric Imp HTS221 library to take temperature and humidity readings from a sensor. We will also use the InitialState library to send the data we collect from the sensor to the cloud. This code can be easily configured for use with an imp006 Breakout Kit, impExplorer Kit, impAccelerator Battery Powered Sensor Node or impC001 Breakout Board.

Skill level

Beginner

This example will focus on writing Squirrel code. Please visit the Getting Started Guide on the Electric Imp Dev Center 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 sensor and take synchronous readings.
  • How to send 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 object for your device into the i2c variable on line 34.
  • 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 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