3 Replies Latest reply on Sep 8, 2016 1:06 PM by Intel Corporation

    Getting started with Edison Board

    Ed_Edison_Pic

      Dear Community,

       

      I would like to ask if someone can help me to Getting started with the Intel Edison Board,

       

      My board is connect with AWS, I created a topic and a rule for store a data ( temperature ) on my DynamoDB.


      But I'm not able to create an history of the temperature received from my sensor connect to the board on PIN A0 ( analog PIN)

       

      Problems:

       

      - I cannot read the data inside DynamoDB

       

      - I don't know how to create a appropriate JSON  ( I mean the logic structure )


      - In this moment, I'm using SNS (I created a rule, of course) for receive an email with a condition ( temperature = 25, send me an email ) WORKS!

       

        Same procedure with DynamoDB, DOESN'T WORK

       

      - How works the thingShadow.publish and the thingShadow logic structure? Very crucial for me

       

      - How works Lambda function?

       

      - What is the best way to use the relational database management system? Also crucial

       

       

       

      *****************

      *****************************

      JAVASCRIPT CODE

      ****************************

      *****************

       

       

      var awsIot = require('aws-iot-device-sdk'); //require for awsiot
      var mraa = require('mraa'); //require mraa for analog/digital read/write
      console.log('MRAA Version: ' + mraa.getVersion()); //write the mraa version to the console
      
      
      /*
      * CONFIGURATION varIABLES
      * To set your AWS credentials, export them to your environment variables.
      * Run the following from the Edison command line:
      * export AWS_ACCESS_KEY_ID='AKID'
      * export AWS_SECRET_ACCESS_KEY='SECRET'
      */
      
      
      // AWS IoT variables
      
      
      var mqttPort = 8883;
      var rootPath = '/home/root/awscerts/';
      var awsRootCACert = "root-CA.pem.crt";
      var awsClientCert = "certificate.pem.crt";
      var awsClientPrivateKey = "private.pem.key";
      var topicName = "Edison";
      var awsClientId = "Edison";
      var awsIoTHostAddr = "host";
      
      
      /*
      * Instance AWS variables for use in the application for
      * AWS IoT Certificates for secure connection.
      */
      
      var privateKeyPath = rootPath + awsClientPrivateKey;
      var clientCertPath = rootPath + awsClientCert;
      var rootCAPath = rootPath + awsRootCACert;
      
      
      /*
      *Initializing Device Communication for AWS IoT
      */
      
      
      var myThingName = 'Edison';
      
      
      var thingShadows = awsIot.thingShadow({
      keyPath: privateKeyPath,
      certPath: clientCertPath,
      caPath: rootCAPath,
      clientId: awsClientId,
      region: 'us-west-2'
      });
      console.log("AWS IoT Device object initialized");
      
      
      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 temperatureValue = temperaturePin.read(); //read the value of the analog pin
      console.log(temperatureValue); //write the value of the analog pin to the console
      
      
      // 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);// convert analog value to voltage
      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
      if(temperature > 35 ){
      thingShadows.publish('topic',
                              'Your room temperature is greater than 35deg C');
         }
      
      
      
      
      });
      

       

       

       

      IDE: Intel XD

       

      Language: Javascript