Things used in this project

Hardware components:
R8326274 01
Raspberry Pi 2 Model B
×1
Adafruit T-Cobbler Plus
×1
MCP3008 - 8-Channel 10-Bit ADC With SPI Interface
×1
SparkFun Ambient Light Sensor Breakout - TEMT6000
×1
SparkFun Sound Detector
×1
SparkFun Humidity and Temperature Sensor Breakout - HTU21D
×1
Raspberry Pi Wifi Module
×1
Can you imagine laser stars lamp
×1
Powerswitch Tail II
×1
12002 04
Breadboard (generic)
×2
Headers
×1
Software apps and online services:
10
Microsoft Windows 10 IoT Core
Vs2015logo
Microsoft Visual Studio 2015
New Relic
W9gt7hzo
Microsoft Azure
Hand tools and fabrication machines:
Solder Iron

Schematics

Main sensor array.
Baby monitor bb

Code

Reading class to serialize for AzureC#
This is the object class that we populate for sending events up to Azure.
    public class Reading
    {
        public int Light { get; set; }
        public int Audio { get; set; }
        public int Envelope { get; set; }
        public int Gate { get; set; }
        public float Temp { get; set; }
        public float Humidity { get; set; }
        public string Timestamp { get; set; }
        public string Type { get; set; }
        public DateTime SensorTime { get; set; }

        public string ToJson()
        {
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Reading));
            MemoryStream ms = new MemoryStream();
            ser.WriteObject(ms, this);
            string json = Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length);

            return json;
        }
    }
EventHubHelperC#
Helper class for sending events to Azure.
using System;
using System.Diagnostics;
using System.Linq;
using System.Net;
using Windows.Security.Cryptography;
using Windows.Security.Cryptography.Core;
using Windows.Web.Http;

namespace BabyMonitor1
{
    public class EventHubHelper
    {
        ...
        
        Uri uri;
        private string sas;
        HttpClient httpClient = new HttpClient();
        
        public EventHubHelper()
        {
            this.InitEventHubConnection();
        }

        public void SendData(Reading reading)
        {
            reading.Timestamp = DateTime.UtcNow.ToString("o");
            reading.SensorTime = DateTime.Now;
            reading.Type = "SensorArray";
            sendMessage(reading.ToJson());
        }

        public async void sendMessage(string message)
        {
            try
            {
                HttpStringContent content = new HttpStringContent(message, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/json");
                HttpResponseMessage postResult = await httpClient.PostAsync(uri, content);

                if (postResult.IsSuccessStatusCode)
                {
                    Debug.WriteLine("Message Sent: {0}", content);
                }
                else
                {
                    Debug.WriteLine("Failed sending message: {0}", postResult.ReasonPhrase);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception when sending message:" + e.Message);
            }
        }

        private string SASTokenHelper()
        {
            int expiry = (int)DateTime.UtcNow.AddHours(24).Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
            string stringToSign = WebUtility.UrlEncode(this.uri.ToString()) + "\n" + expiry.ToString();
            string signature = HmacSha256(KEY, stringToSign);
            string token = String.Format("sr={0}&sig={1}&se={2}&skn={3}", 
                WebUtility.UrlEncode(this.uri.ToString()), WebUtility.UrlEncode(signature), expiry, KEYNAME);
            return token;
        }
  
        public string HmacSha256(string key, string value)
        {
            var keyStrm = CryptographicBuffer.ConvertStringToBinary(key, BinaryStringEncoding.Utf8);
            var valueStrm = CryptographicBuffer.ConvertStringToBinary(value, BinaryStringEncoding.Utf8);

            var objMacProv = MacAlgorithmProvider.OpenAlgorithm(MacAlgorithmNames.HmacSha256);
            var hash = objMacProv.CreateHash(keyStrm);
            hash.Append(valueStrm);

            return CryptographicBuffer.EncodeToBase64String(hash.GetValueAndReset());
        }
        
        public bool InitEventHubConnection()
        {
            try
            {
                this.uri = new Uri("https://" + SERVICE_BUS_NAMESPACE +
                              ".servicebus.windows.net/" + EVENT_HUB_NAME +
                              "/publishers/" + DISPLAY_NAME + "/messages");
                this.sas = SASTokenHelper();

                this.httpClient.DefaultRequestHeaders.Authorization 
                    = new Windows.Web.Http.Headers.HttpCredentialsHeaderValue("SharedAccessSignature", sas);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Intelligent Community Alerts Beacon [-iCAB-]
Advanced
  • 211
  • 9

A cloud connected alert system that parses local alert feeds ranging from weather to missing persons and provides visual and audio feedback.

Wifi controlled ceiling fan
Advanced
  • 133
  • 4

Full instructions

My young children were not tall enough to pull the chains on the ceiling fan, to turn on the fan & light. Alexa, turn on the 'Boys Light'.

Power Lunch
Advanced
  • 114
  • 4

Full instructions

An insulated food container divided into two sections by a thermoelectric cooler module for quickly heating one side and cooling the other.

Power Lunch

5 members

Suicide Prevention Gun Safe Locking System
Advanced
  • 157
  • 3

Full instructions

An IoT device that helps prevent gun suicides through safe monitoring, only allowing access to a safe through a request/approval process.

Smart Compost System
Advanced
  • 104
  • 2

A smart system that can help anyone compost. The system aerates and hydrates your compost, and lets you know when you need to take action.

Smart Compost System

Team Boomer Sooner

Smart Home System [AHCS]
Advanced
  • 156
  • 1

Very easy and effective home automation system based on PIC16F877A. Control home appliances remotely and monitor fire and break-ins.

Smart Home System [AHCS]

Team Infinity Tech

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login