Getting Temperature from a Spark Core

I have been doing a lot of hardware stuff lately. Just after Thanksgiving, I went to pre-order a Spark Photon ( and ultimately ended up ordering the prototyping bundle ( This bundle is a Spark Core on a solderless breadboard with a Photon to be shipped at a later date. I figured this would be a good way to get started with the Spark API sooner than later.

The gist of the Spark Core is that it is an ARM processor with a Wi-Fi module built right in. This means that you can do some pretty cool hardware projects that are easily connected to the internet. (At $39 the core is great…at $19 the photon will be awesome.) The other cool thing is that they are already FCC certified, so you could actually start building a real product on day one.

Following the startup guide (, I had my core connected to my wi-fi and claimed in a matter of minutes. I bought two, so I went through the smart app with the first one…easy peasy. I went through the USB configuration with the second one…a little more painful, but if you are building hardware at this level, you probably won’t face too much you can’t handle.

After setup, I started walking through a couple of samples to get the onboard LED blinking and make sure I understood the environment and how code was deployed to the Core.

So here’s the setup…I have a USB power block connected to the Core; the Core connected to the wi-fi. Code gets pushed to the Core through the web.


Now I wanted to take a temperature/humidity sensor and connect that to the Core. This is where things got interesting. In the Arduino side of the the world, I would load a library for the sensor and then with an “includes” statement I could just use the sensor. I can similarly do that on the Spark Build code site, but I have have the cpp and h files added to my project (they don’t just sit out in my folder like they do in Arduino).

In the end, I ended up finding a single file approach for my DHT22 sensor. wgbartley had a Spark Core class for reading temperature and humidity from my sensor. While his file approach is all in one file (I am sure for simplicity), I took the liberty to break it out into a class library that I could reuse.

Here’s my spark setup.


Next, I have three code files on my Spark App.




Now I can use the following as standard HTTP POST to read the value of the three variables from the Spark.

Next Up:
Pushing Data to the Cloud…This approach makes me reach out to the Spark and query for the values. In the next post, I will show you how to use the events to have the Spark updating the variables as well as using the TCPClient to POST the values to a waiting web service.