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

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

IoT Red Phone
Intermediate
  • 1,528
  • 12

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.

Real-Time Workspace Occupancy Sensing Based on AWS IoT
Intermediate
  • 725
  • 6

Sensor-based presence detection for individual workstations: capturing occupancy trends and space utilization in real-time.

LoRaCatKitty Build IoT Applications with LoRaWAN in 3 Steps
Intermediate
  • 1,110
  • 7

Protip

LoRaCatKitty Build IoT Applications with LoRaWAN in 3 steps with The Thing Networks and Cayenne.

Build Your Own Amazon Echo Using a RPI and ReSpeaker HAT
Intermediate
  • 6,526
  • 33

Full instructions

How to build your own Amazon Echo using a Raspberry Pi and ReSpeaker 2-Mics HAT.

Alexa Quran Translator
Intermediate
  • 208
  • 7

Work in progress

Listen English translation of the Holy Quran.

Smart Shoes (Auto-lacing and Generating Electricity)
Intermediate
  • 663
  • 8

Full instructions

Features of smart shoes: generates electricity, auto lacing, step counting, etc.

Sign up / LoginProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlog