Things used in this project

Hardware components:
Tessel
Tessel 1 (discontinued - see Tessel 2)
×1
Battery
×1
Ambient Module for Tessel
Plugged into Port A
×1

Code

file_14419.jsJavaScript
var http = require('http');
var https = require('https');
var req = null;

//for tessel
var tessel = require('tessel');
var ambientlib = require('ambient-attx4');
var ambient = ambientlib.use(tessel.port['A']);
var wifi = require('wifi-cc3000');

//for ubidots
var id_sound = '54b6f72b762542082df7ff42';    // Your variable id
var token = 'kA8XWNQRHFrXVQakaJVY3Zg2qRU1lq'; // Your Ubidots Token
var sound = {
  value: 66,
  context: {
                lat: 6.77,
                lng: -75.74
             }
}

//for googlelocation api
var wifidata = {
    'wifiAccessPoints': [
    {
        'macAddress': '5c:f9:38:9e:3f:e8',
        'signalStrength': -65,
        'age': 0,
        'channel': 11
    }
    ]
};

data2googlelocation(data2ubidots);

//data2ubidots();

ambient.on('ready', function () {
	getlevel();
	function getlevel(){
		ambient.getSoundLevel( function(err, sdata) {
			sound.value = sdata.toFixed(8);
			console.log(sound.value);
			setTimeout(getlevel,100);
		});
	}
});


function data2ubidots(){
    var valueString = JSON.stringify(sound);
    var headers = {
        'Content-Type': 'application/json',
        'Content-Length': valueString.length,
        'X-Auth-Token': token,
        'Connection': 'keep-alive'
    };
    var options = {
        host: 'things.ubidots.com',
        port: 80,
        path: '/api/v1.6/variables/'+id_sound+'/values',
        method: 'POST',
        headers: headers
    }
    req = http.request(options, function(res){
        res.setEncoding('utf-8');
        var responseString = '';
        res.on('data', function(data){
            responseString += data;
        });
        res.on('end', function(){
            console.log('sending value to ubidots');
            var resultObject = JSON.parse(responseString);
            console.log(resultObject);
	 //setTimeout(data2Ubidots,1);
        });
        req.on('error', function(e){
            console.log('problem with request: '+ e.message);
        });
    });
    setTimeout(data2ubidots,1000);
    req.write(valueString);
    req.end();
}

function data2googlelocation(callback){
    var valueString = JSON.stringify(wifidata);
    var headers = {
        'Content-Type': 'application/json'
    };
    var options = {
        host: 'www.googleapis.com',
        port: 443,
        path: '/geolocation/v1/geolocate?key=YOUR_GOOGLE_API_KEY_HERE',
        method: 'POST',
        headers:headers
    };
    req = https.request(options,function(res){
        res.setEncoding('utf-8');
        var responseString = '';
        res.on('data',function(data){
            responseString += data;
        });
        res.on('end', function(){
            console.log('sending value to googleapi');
            var resultObject = JSON.parse(responseString);
            sound.context.lat = resultObject.location.lat;
            sound.context.lng = resultObject.location.lng;
            console.log(sound.context.lat);
            console.log(sound.context.lng);
            callback();
        });
    });
    req.write(valueString);
    req.end();
}

wifi.on('disconnect', function(err, data){
                  if (!wifi.isBusy()) {
                    connect();
                    }else {
                      console.log("is busy, trying again");
                      setTimeout(function(){connect();},1000);
                    }
                console.log("disconnect emitted", err, data);
          });

function connect(){
      wifi.connect({
        security: 'wpa2'//or wpa,unsecured,wep
        , ssid: 'Atom_Med'
        , password: 'atommed2015'
        , timeout: 30 // in seconds
      });
    }

Credits

Generic icon taoacaqyns
UbiMaker

Maker @ ubidots.com

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

Coffee Profile
  • 789
  • 7

Use Tessel and Keen.io to profile roasting coffee

Plant Analytics
  • 356
  • 3

Give your plants a voice.

Plant Analytics

Jesse Ditson, Greg Biesiadecki, Eduardo Ribeiro

Keen IO Environmental Control Dashboard
  • 473
  • 3

Tesse and Keen IO Environmental Control Dashboard

Toilet-time
  • 527
  • 2

You never have to queue for the toilet again.

Toilet-time

Ayoub Sbai, C S, Luka Strizic

Not-If-I Notify!
  • 253
  • 4

Am I afraid of loved ones dying in hots cars? Nope, Not If I Notify!

Not-If-I Notify!

Rishi Nair, Kevin Salassi, Milan Bharadwaj, David Barto

Mercedes Benz Show Me App
  • 142
  • 1

First prize at H-ack Auto @H-Farm ventures (24 hours Hackaton).

Add projectSign up / Login
Respect project