Simple IOT Sunlight Sensing Raspberry Pi Project- SunIOT – Part 3
Adding an IOT Dashboard
We just have added a new product, a Grove Sunlight Sensor to our lineup and wanted to build a project using it. We are intending to add drivers for this sensing device to three of our product lines: OurWeather, the GroveWeatherPi and the WXLink wireless data transmission products. Since we are going to be using the Grove Sunlight Sensor so extensively, we thought we should build a quick example project.
SunIOT was thus born. We will be building this project in four postings. FIrst the description of the project (Part 1). Secondly, we get the hardware up and connected , Python connected to both of the Grove devices (Part 2), Part 3 will have us connect up to initialstate.com and then in Part 4, we will use MQTT to connect to a dashboard, freeboard.io (and pubnub.com).
- – Part 1 – Introduction to SunIOT
- – Part 2 – The SunIOT Hardware and Software
- – Part 3 – Hooking up SunIOT to initialstate.com
- – Part 4 – Hooking up SunIOT with MQTT to freeboard.io and pubhub.com
What is SunIOT?
The overall design of the project is simple. We use the Raspberry Pi to read a sensor that measures sunlight and breaks the sunlight down into three components (UV, IR and Visible). We also use an LED to provide visual feedback that a sample is being taken (two blinks) and that the process is still running (one blink).
The general idea of SunIOT is to build a software platform to build more complex IOT sensors. In this column and the next, we will be going through a complete, albeit simple, IOT design. As well as providing a test bed for the new Grove Sunlight Sensor.
There are many internet dashboards and IOT data servers around today. We chose initialstate.com to do first. InitialState has a free version, but it is limited to 25,000 streamed events per month and so we ran out in about 3+ hours (4 streaming events every 2 seconds = 7,200 events per hour – we hit the limit in 3.5 hours and got a pleasant (it was actually nice!) email telling us we were out of events until the start of the next calendar month. We had assumed (very mistakenly) that all of our data being sent was one event. Each stream call turns out to count as an event. Hindsight says we should have realized that. See our short review on initialstate.com below.
Installing Raspberry Pi support for InitialState is pretty straightforward. As is the software for connecting your SunIOT device to InitialState.
If you have followed the tutorial in our previous postings, you have already done the first two steps
Installing I2C on your Raspberry Pi
Make sure you installed I2C as in this link:
When you have done the tutorial type the following into your Raspberry Pi:
sudo i2cdetect -y 1
If everything is good, then you will see this:
<b>pi@RPi3-62</b>:<b>~/SunIOT $</b> i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: 60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
0x60 is the Sunlight Sensor.
The Advanced Python Scheduler (APScheduler) is a light but powerful in-process task scheduler that lets you schedule functions (or any other python callables) to be executed at times of your choosing.
We have used the APScheduler software for a number of projects in the past, such as Project Curacao [ref: Raspberry Pi Geek article on Project Curacao], SunRover [ref: Raspberry Pi Geek Article on SunRover software], the upcoming Project Curacao 2 project (we revisit wind power and the Caribbean with a 2nd generation Project Curacao) as well as other SwitchDoc Labs projects for customers. It’s a great package.
sudo pip install setuptools --upgrade sudo pip install apscheduler
Installing InitalState Library
sudo pip install ISStreamer
Setting up Initial State
Very straight forward. Go to initialstate.com and sign up for a free account. When you have done that go and set up your first bucket.
To work with the SunIOT_InitialState software, you will need to gather your Bucket Key and Access Key from settings under the bucket you just created.
You can name the bucket anything you want. Note that the keys you see in the picture will not work. They have been deleted for obvious reasons.
Next, to get things working create at least one tile. Make it a summary type and fill it out as in the picture below.
The three Signal Keys that we have defined in the SunIOT software are:
- – SunIOT_Visible
- – SunIOT_IR
- – SunIOT_UVIndex
Now you are ready to configure the software with your initial state account information.
In Part 2 of this series we go through the basic SunIOT software, so we will just focus on the new part of the software.
You can download the entire software by doing:
git clone https://github.com/switchdoclabs/SunIOT_InitialState.git
There are two parts of interest in this code that were not in the previous version. First, the setup of the keys and initializing the InititalState connection.
from ISStreamer.Streamer import Streamer # configuration - you must change these! InitialState_Bucket_Name = "SunIOT_InitialState" InitialState_Bucket_Key = "XXXXXXXXXXXX" InitialState_Access_Key = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY" streamer = Streamer(bucket_name= InitalState_Bucket_Name bucket_key=InitialState_Bucket_Key, access_key=InitialState_Access_Key)
And the second part is the routine used to send it to the InitialState dashboard that you set up above.
def reportToInitialState(): vis = sensor.readVisible() IR = sensor.readIR() UV = sensor.readUV() uvIndex = UV / 100.0 print('Sending Data to Initial State time: %s' % datetime.now()) print ' Vis: ' + str(vis) print ' IR: ' + str(IR) print ' UV Index: ' + str(uvIndex) streamer.log("SunIOT_Visible", vis) streamer.log("SunIOT_IR", IR) streamer.log("SunIOT_UVIndex", uvIndex) streamer.log("SunIOT_Status", "SwitchDoc Labs\nSunIOT") blinkLED(3,0.200) returnValue =  returnValue.append(vis) returnValue.append(IR) returnValue.append(uvIndex) return returnValue
Note that the Signal Keys that we mentioned above are in the code above in the streamer.log lines of the program.
The final line of interest is where we schedule the reportToInitialState call. Note this is where we sent information way too fast to the InitialState dashboard. Every two seconds made the 25,000 events happen very quickly (3.5 hours). You may want to change the to every 30 or 60 seconds.
# add the Update to Initial State scheduler.add_job(reportToInitialState, 'interval', seconds=2)
Looking at the Results
If you get the error:
"ImportError: No module named Adafruit_PureIO.smbus"
Try the following:
git clone https://github.com/adafruit/Adafruit_Python_PureIO.git cd Adafruit_Python_PureIO sudo python setup.py install
We ran the software until we ran out of events. It looked pretty good up on the site.
Our Opinion on InitialState
The software setup for InitialState was very easy. It came together in a matter of 30 minutes and we had our dashboard working. There are some great tiles, and a whole level of sophistication underneath the dashboard (waves, triggers, SmartThings integrations and lots more). Really good stuff to explore. We have just starting looking at all of these features. The tiles and dashboard look good and can be embedded in webpages. The great news is it NEVER bombed. Adafruit.io and the IBM BlueMix (our BlueMix tutorial is here.) all bombed at one time or another. Below is an example of the waves output. Very nice.
We had three issues with using InitialState for our dashboard. We have an email into the company about two of these issues and we will update this page when we hear back.
25,000 Event Limitation in Free Version – Seems light. maybe 50,000 would be better.
No way to save Buckets and share the code – Makes it hard to share structures for projects and articles. (Update Oct 31, 2016: Jamie at intialstate.com: This ability is planned for a future release. No due date.)
No way to load images into Tiles – This is a bummer for adding logos and webcam images, plus graphs generated by MatPlotLib and the Raspberry Pi. (Update Oct 31, 2016: Jamie at initialstate.com: They are discussing but do not have schedule.)
In our final installment on SunIOT we will be adding a dashboard that uses MQTT. First we sent the data to pubhub.com and then hook up freeboard.io for the display. A bit more complex than InitialState, but lots of flexibility and open source goodness. We have also written an MQTT tutorial for the Raspberry Pi here.
Subscribe to SwitchDoc via Email
- New Grove Product – Grove Rotary Dial and Button Combo for Raspberry Pi on
- New Grove Product – Grove Rotary Dial and Button Combo for Raspberry Pi on
- New Kickstarter! SmartPlantPi – Raspberry Pi Based Plant Monitoring and Watering System Kit on
- IOT ESP8266 Tutorial – Using nodeMCU/LUA on
- Tutorial: Intro to Grove Connectors for Arduino/Raspberry Pi Projects on
- January 2017
- December 2016
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- May 2016
- April 2016
- March 2016
- February 2016
- January 2016
- December 2015
- November 2015
- October 2015
- September 2015
- August 2015
- July 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- November 2014
- October 2014
- September 2014
- August 2014
- July 2014
- June 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013
- 3D Printing
- 8 GPIO I2C Board
- Arduino Software
- Bluetooth Low Energy
- Breakout Boards
- Building Tips
- Computer Security
- Featured Topic
- FTDI Cable
- Grove 4Ch 16Bit ADC Board
- Grove Digital Extender
- Grove I2C Mux Breakout Board
- Grove OLED
- Grove Sensors
- Guest Blogs
- I2C Mux Breakout Board
- IBM Bluemix
- IOT Projects Book
- Matplotlib Graphs
- Pi Camera
- Pro Mini LP
- Project Curacao
- Python Raspberry Pi Software
- Quad Power Management I2C Board
- Raspberry Pi
- Real Time Clocks
- Smart Plant
- Solar Cells
- Solar Power
- SwitchDoc Dual WatchDog Timer
- SwitchDoc Products
- USB Power Control
- Weather Board
- Wind Power