Things used in this project

Schematics

Temperature/Humidity Notifier Circuit
Intel Edison, HSM-20G T/H Sensor
H t notofier bb
Fritzing Source
h-t-notofier.fzz

Code

JavaScript Source CodeJavaScript
This code is for Intel Edison to publish notification to Amazon SNS
/*

MRAA - Low Level Skeleton Library for Communication on GNU/Linux platforms
Library in C/C++ to interface with Galileo & other Intel platforms, in a structured and sane API with port nanmes/numbering that match boards & with bindings to javascript & python.

Steps for installing MRAA & UPM Library on Intel IoT Platform with IoTDevKit Linux* image
Using a ssh client: 
1. echo "src maa-upm http://iotdk.intel.com/repos/1.1/intelgalactic" > /etc/opkg/intel-iotdk.conf
2. opkg update
3. opkg upgrade

*/
var awsIot = require('aws-iot-device-sdk'); //require for aws iot 
var mraa = require('mraa'); //require mraa for analog/digital read/write
console.log('MRAA Version: ' + mraa.getVersion()); //write the mraa version to the console

var myThingName = 'raspberry-pi';

var thingShadows = awsIot.thingShadow({
   keyPath: './b91fc77cfb-private.pem.key',
  certPath: './b91fc77cfb-certificate.pem.crt',
    caPath: './rootCA.pem',
  clientId: myThingName,
    region: 'us-west-2'
});

mythingstate = {
  "state": {
    "reported": {
      "ip": "unknown"
    }
  }
}

var networkInterfaces = require( 'os' ).networkInterfaces( );
mythingstate["state"]["reported"]["ip"] = networkInterfaces['wlan0'][0]['address'];

var temperaturePin = new mraa.Aio(2); //setup access analog input Analog pin #2 (A2)
var humidityPin = new mraa.Aio(1); //setup access analog input Analog pin #1 (A1)
var temperatureValue = temperaturePin.read(); //read the value of the analog pin
var humidityValue = humidityPin.read();
console.log(temperatureValue); //write the value of the analog pin to the console
console.log(humidityValue);

// calculate humidity
var humVoltage = ((humidityValue*5.0)/1023.0);
var humidity = (3.71*Math.pow(humVoltage,3))-(20.65*Math.pow(humVoltage,2))+(64.81*humVoltage)-27.44;
console.log(humidity);

// calculate temperature
var tmpVoltage = ((temperatureValue*5.0)/1023.0); // convert analog value to voltage
var temperature = (5.26*Math.pow(tmpVoltage,3))-(27.34*Math.pow(tmpVoltage,2))+(68.87*tmpVoltage)-17.81;
console.log(temperature);


  thingShadows.on('connect', function() {
  console.log("Connected...");
  console.log("Registering...");
  thingShadows.register( myThingName );

  // An update right away causes a timeout error, so we wait about 2 seconds
  setTimeout( function() {
    console.log("Updating my IP address...");
    clientTokenIP = thingShadows.update(myThingName, mythingstate);
    console.log("Update:" + clientTokenIP);
  }, 2500 );


  // Code below just logs messages for info/debugging
  thingShadows.on('status',
    function(thingName, stat, clientToken, stateObject) {
       console.log('received '+stat+' on '+thingName+': '+
                   JSON.stringify(stateObject));
    });

  thingShadows.on('update',
      function(thingName, stateObject) {
         console.log('received update '+' on '+thingName+': '+
                     JSON.stringify(stateObject));
      });

  thingShadows.on('delta',
      function(thingName, stateObject) {
         console.log('received delta '+' on '+thingName+': '+
                     JSON.stringify(stateObject));
      });

  thingShadows.on('timeout',
      function(thingName, clientToken) {
         console.log('received timeout for '+ clientToken)
      });

  thingShadows
    .on('close', function() {
      console.log('close');
    });
  thingShadows
    .on('reconnect', function() {
      console.log('reconnect');
    });
  thingShadows
    .on('offline', function() {
      console.log('offline');
    });
  thingShadows
    .on('error', function(error) {
      console.log('error', error);
    });
	
  
  //Watch for temperature & humidity
if(temperature > 35 && humidity < 60){//SNS terget: arn:aws:sns:us-west-2:316723939866:TemperaturAlarm
   thingShadows.publish('arn:aws:sns:us-west-2:316723939866:TemperaturAlarm', 
                        'Your room temperature is greater than 35deg C');
   }
if(humidity > 60 && temperature < 35){
   thingShadows.publish('arn:aws:sns:us-west-2:316723939866:TemperaturAlarm', 
                        'Humidity is greater than 60% which is not desireable');
   }
if(humidity > 60 && temperature > 35){
   thingShadows.publish('arn:aws:sns:us-west-2:316723939866:TemperaturAlarm', 
                        'Both, Humidity & Temperature are in abnormal condition');
   }

});

Credits

Taifur1
Md. Khairul Alam

Engineer, developer, maker, hacker & tech lover.

Contact

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

Self Balancing Robot Using Mpu6050 Accelerometer
Intermediate
  • 32
  • 4

Protip

this is self balancing robot on two wheels using mpu6050 accelerometer based on arduino..

Arduino on Internal Oscillator Crystal as Clock Source
Intermediate
  • 958
  • 72

Protip

Want to make an Arduino having only an ATmega328 chip and nothing else? Not even the crystal oscillator!

Reducing Arduino Power Consumption
Intermediate
  • 1,190
  • 98

Protip

One the most important feature of portable electronics should be long battery life. We can reduce the current drawn by several ways.

Node-Red and MQTT for Your IoT Projects
Intermediate
  • 122
  • 3

Work in progress

The idea is to create an environment running an MQTT Server, Mosquitto, and Node-Red, and start developing projects with connected sensors.

IoT Red Phone
Intermediate
  • 1,291
  • 11

Work in progress

The phone will ring if you have an alert in your AWS Cloudwatch. If you pick up the handset, it tells you whats wrong.

RING PONG
Intermediate
  • 2,043
  • 8

A simple Ping Pong game played on a NeoPixel Ring with Arduino.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login