Things used in this project

Schematics

Schematics 'Plantopia'
4vxjgmoyrmdorbvnyud2

Code

PlantopiaJavaScript
/*
 * testPcode Node.js starter app.
 *
 * Use this template to start an IoT Node.js app on any supported IoT board.
 * The target board must support Node.js. It is helpful if the board includes
 * support for I/O access via the MRAA and UPM libraries.
 *
 * https://software.intel.com/en-us/xdk/docs/lp-xdk-iot
 */



"use strict" ;

var mraa = require("mraa") ;
var mqtt = require('mqtt');
var fSystem = require('fs');

var LightSensorPin_A0 = new mraa.Aio(0);
var MoistureSensorPin_A2 = new mraa.Aio(2);

var ReadSensorValue = false;


var options = {
  host: 'a28xfzz2n1aori.iot.us-west-2.amazonaws.com',
  key: fSystem.readFileSync('/home/root/connect_device_package/myEdison.private.key'),
  cert: fSystem.readFileSync('/home/root/connect_device_package/myEdison.cert.pem'),
  ca:  [fSystem.readFileSync('/home/root/connect_device_package/root-CA.crt')],
  requestCert: true,
  rejectUnauthorized: true,
  port: 8883,
  cleanSession: true,
  //protocolId: 'MQIsdp',
  //protocolVersion: 
};


var mqttClient  = mqtt.connect('mqtts://data.iot.us-west-2.amazonaws.com',options);
console.log("Connecting to AWS MQTT ...");
mqttClient.on('connect', function onConnect(data) {
  console.log("Connected to AWS MQTT: " + data);
  if (ReadSensorValue == false) {
    fnLoop(); 
  }
});


var LightSensorStatus = 0;
var TempSensorStatus = 0;
var MoistureSensorStatus = 0;
var HumiditySensorStatus = 0;

var min_Moist_val = 0;
var max_Moist_val = 1023;
var min_Moist_perc = 0;
var max_Moist_perc = 100;

var five = require("johnny-five");
var Edison = require("edison-io");
var board = new five.Board({
  io: new Edison()
});

var fnLoop = function(){
    
    ReadSensorValue = true;
    var ReadLightSensor = false;
    var ReadMoistureSensor = false;
    
    var LightSensorValue    = LightSensorPin_A0.read();
    var MoistureSensorValue = MoistureSensorPin_A2.read();
    console.log("\nLight Intensity:", LightSensorValue);
    console.log("--------------------------------------");
    var moisture_percent = mapMoistureValue(MoistureSensorValue, 0, 1023, 0, 100);
    console.log("\nPercentage of Soil-Moisture:", moisture_percent + "%");
    console.log("--------------------------------------");
    
    var pubMessage = {reading_timestamp:new Date().getTime(), Illuminance:LightSensorValue};
        mqttClient.publish('Plantopia/Sensors/Illuminance/LightSensor', JSON.stringify(pubMessage),{
        }, function() {
          ReadLightSensor = true;
        }); 

    var pubMessage = {reading_timestamp:new Date().getTime(), Moisture:moisture_percent};
        mqttClient.publish('Plantopia/Sensors/Moisture/MoistureSensor', JSON.stringify(pubMessage), { 
        }, function() {
          ReadMoistureSensor = true;
        });

};

board.on("ready", function() {
    var mul = new five.Multi({
        controller: "TH02"
});

    mul.on("change", function() {
        
        console.log("Thermometer");
        //console.log("  celsius           : ", this.thermometer.celsius);
        //console.log("  fahrenheit        : ", this.thermometer.fahrenheit);
        //console.log("  kelvin            : ", this.thermometer.kelvin);
        console.log("--------------------------------------");

        console.log("Hygrometer");
        //console.log("  relative humidity : ", this.hygrometer.relativeHumidity);
        console.log("--------------------------------------");


        });
});

function mapMoistureValue(val, min_Moist_Val, max_Moist_val, min_Moist_perc, max_Moist_perc){
    return Math.round((val - min_Moist_val) * (max_Moist_perc - min_Moist_perc) / (max_Moist_val - min_Moist_val) + min_Moist_perc);
}


var intervalID = setInterval(fnLoop, 2000) ;  // read interval = 2s

process.on("exit", function(code) {
    clearInterval(intervalID) ;
    console.log("\nExiting " + ", with code:", code) ;
}) ;

Credits

N6doiusgtjbuxyyqiucv
Sampreeti Alam

Graduate Student in Dept. of ECE, New York University

Replications

Did you replicate this project? Share it!

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

Give feedback

Comments

Similar projects you might like

Arduino101 Bluetooth Interfacing
Intermediate
  • 213
  • 4

Full instructions

Use the Arduino101 Bluetooth wireless interface with the Blynk GUI Library for control of things directly from your phone or tablet !

Amazon Echo – Control IoT devices via HTTP
Intermediate
  • 265
  • 11

Full instructions

I am going to show how to use Amazon Echo to control IoT devices via HTTP protocol. Turning on/off a light bulb is an example.

Amazon Echo – Read Temperature and Humidity from Sensor
Intermediate
  • 323
  • 12

Full instructions

I am going to show how to use Amazon Echo to read temperature and humidity from sensor.

Amazon Echo – Control DIY IoT devices with PHPoC
Intermediate
  • 265
  • 9

Full instructions

In this article, I am going to show how to use Amazon Echo to voice-control the DIY IoT devices

Intel Curie TinyTILE Dress: Accelerometer + Optical Fibers
Intermediate
  • 396
  • 10

Full instructions

A dress using Intel Curie accelerometer on TinyTILE and its small form factor to control colors of the optical fibers with arm movements.

MAKERBALL
Intermediate
  • 997
  • 4

Makerball is a DIY pinball machine kit that can be upgraded digitally with the Arduino Genuino 101. Here we show you the electronical part.

MAKERBALL

Team Makerball.org

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Feedback