Code in main.js:

=================================================================================

 

"use strict" ;

 

var m

 

raa = require("mraa") ;

 

// add any UPM requires that you need

// and the rest of your app goes here

// see the samples for more detailed examples

 

console.log(mraa) ;     // prints mraa object to XDK IoT debug output panel

 

 

// Load Grove module

var groveSensor = require('jsupm_grove');

 

 

// Create the light sensor object using AIO pin 0

var light = new groveSensor.GroveLight(0);

 

 

// Read the input and print both the raw value and a rough lux value,

// waiting one second between readings

function readLightSensorValue() {

    console.log(light.name() + " raw value is " + light.raw_value() +

            ", which is roughly " + light.value() + " lux");

   

    $.ajax({

        url: "http://localhost:64664/api/Sensor",

        contentType: "application/json; charset=utf-8",

        type: "POST",

        data: "{SensorID:'CB0001', Value:'" + light.raw_value() + "', Lastupdate:'22/04/2017 18:45:00'}",

        dataType: "json"

    });

}

setInterval(readLightSensorValue, 2000);