ThingSpeak - An Internet of Things


My grandson installed a wind turbine on a shed in his back yard and needed more detailed data to better understand how the turbine was performing.  I designed and built a simple data logger which was composed of an Atmel AVR processor with analog and digital inputs, an interface with display and pushbuttons, and an SD card interface.  The logger works fine but he still has to go out to the shed, get the card, bring it into the house, upload it to a computer, and then import it into Excel to graph and analyze the data.  We had been talking about how to get the data "in the cloud" when we discovered ThingSpeak.  The folks at ThingSpeak describe it as - "An open application platform designed to enable meaningful connections between things and people".  We thought this might be the answer.

Here's the wind turbine data logger:


I'm still working on the web page for the logger but it should be up shortly.

And here it is with full display attached:
logger and display

Finding a Test Application

We still need to get the data into the house - probably wirelessly (looks like my next project).  But in the mean time, I decided to set up a 'proof of concept' application to understand how it all worked.  We have a heated waterbed and I always wondered how good the temperature control was.  This seemed like a possible test project.  My wife was a little concerned when I said I was going to put our bed on the Internet but I guess she's used to my weird projects by now.


I had a spare data logger at home that I used for developing and testing software for the wind turbine logger and I also had a Red Bokito board that I purchased from Ben's Hobby Corner several years ago.  This board has an Atmel ATmega 168, a Wiznet WIZ810MJ module that uses Wiznet's W5100 chip, and a serial converter chip.  The board also has some relays but I didn't need them for this application.  That sounded like all of the hardware I would need and so the rest is software as they say.


I have done quite a bit of testing with the Wiznet module and have even completed one successful project using Bascom AVR from MCS Electric- a clock that updates itself regularly from an Internet Time Server.  So I thought it would be pretty easy to get some software working.  All I had to do was initialize the WIZ810MJ module and all of the appropriate registers and wait for data on the serial port.  Then I could open a socket, connect to the ThingSpeak server, build my POST, send it to ThingSpeak, get the response, close the connection, and go back to waiting for the next serial message.

After a few simple errors, this worked and I had updated my channel.  The problem was that, when I tried to send another update a few minutes later, the Wiznet module timed out during the connection phase.  This really stumped me.  I tried many things including a hardware reset of the module, a software reset of the module, changing the local IP address, and even powering down the module to ensure all internal registers were clear and nothing helped.  Finally I discovered that I could change the local port and I could again update my channel - but only one time and then I couldn't connect again.  I spent quite a bit of time trying to figure this out and finally came to the conclusion that the problem was in the ARP request but I still didn't know why the problem existed.  Back to researching on the Internet.  I finally found a link that helped me understand the problem.  I have Frontier (formerly Verizon) and FIOS for my Internet connection and apparently they cache all ARP requests for two hours.  So when I tried the second connection, Verizon thought that the port was still in use and didn't make the connection.  If I waited the appropriate time, I could re-use the port.  While this explained my problem, it didn't solve it.

I actually got my solution from Microsoft.  I wrote a simple VB6 program to POST to ThingSpeak in the same manner as my Wiznet module and I got similar results.  I could post one time but the second connection failed.  The error was 10048 which is a Winsock error indicating that the connection is still open.  The Microsoft solution is to use a local port of 0.  This forces the Winsock control to choose a random port.  Setting a local port of 0 wouldn't work with the Wiznet module but, since Bascom AVR has a random function, I thought this would be an acceptable solution.  I let the program choose a random number between 1024 and 65000 and everything worked from then on.


Throughout the process I captured the output from the test board in Hyperterminal so that I could see what was happening.  So here's a dump of a successful POST and the ThingSpeak response:

Here's an image of the test hardware:

test bed

The test was actually to measure two temperatures.  I used an LM34DZ to measure the actual bed temperature and there is a Microchip TC1047a mounted on the board that measures the temperature on the PCB.  The test was successful and met all of my expectations.  Here's my actual web page with live data from the past 5 days.  The temperature control was much better than I expected.  During the day, when no one is in the bed, the temperature never ranged more than 0.2 degrees F and at night, even with people moving about and causing the water to slosh around, the temperature was within 1.0 degrees F.  Looking at the PCB temperature you can also see the effect of the house thermostat setback during the night.

What's Next

I have two project ideas for ThingSpeak.  The first is to get the Wind Turbine logger data into ThingSpeak.  The second is a plugin for my Home Control System.  I have lots of data in the system that would be nice to get into ThingSpeak.  The current software side of the system has a powerful plugin API that accepts plugins written in TCL.  I think a ThingSpeak client plugin would be a great idea and relatively easy to accomplish.  So many ideas and so little time. Here's a link to download the Bascom AVR source files.  Please feel free to contact me with any questions or comments.


link_blue16 (1K)