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

Hank the HexaPod - Mega Bread Robotics Series # 7
Advanced
  • 130
  • 4

Work in progress

After a few months of gathering parts, reading about the new hardware, and ripping my hair out due to no support. I done did it Paw.

Punch Activated Arm Flamethrowers (Real Firebending)
Advanced
  • 40,200
  • 306

Shoot fireballs from your fists when you throw a punch with these arm mounted smart flamethrowers!

Magic VR Hat
Advanced
  • 529
  • 5

Wear the hat, get transported to different 360 VR experience.

Get Nostalgic and Use Nokia 84x48 LCD with Arduino
Advanced
  • 3,011
  • 14

Protip

These 84 by 48 pixel LCDs are what you might have found in Nokia 3310. And what about using them in the Arduino projects?

GPS + WiFi Rover
Advanced
  • 1,304
  • 12

Full instructions

An outdoor rover, capable of autonomous navigation (using GPS and sonar sensors) or controlled over WiFi.

Smart Energy Monitor Based on Arduino
Advanced
  • 281
  • 3

Full instructions

Open source Smart energy monitor with some new features like "Terminal Commands " , "Readings Logger", "Data Plotting ".

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog