Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 |
We have chosen two variables to trigger music selections in a coded playlist. Temperature and light (time of day) will be sensed using the Grove light and temperature senors which are hooked up to the Intel Edison board. Corresponding results from the sensors will trigger a request to youtube with the specific songs playing on Android phone.
Some examples include; Relaxing Morning song from time of sunrise and low to mid temperatures, Fireplace crackling sounds during very cold temperatures (throughout the day), and upbeat Lindsey Stirling songs throughout mild to hot temperatures and brighter light.
This has been an attempt to capture emotion that may be present during various times of day with light, and temperature.
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*global */
/*
A simple node.js application intended to read data from Analog pins on the
Intel based development boards
such as the Intel(R) Galileo and Edison with Arduino breakout board, and
display it in a browser running on the client.
This demonstrates use of http.createServer, and fs.
MRAA - Low Level Skeleton Library for Communication on GNU/Linux platforms
Library in C/C++ to interface with Galileo & other Intel platforms, in a
structured and sane API with port nanmes/numbering that match boards &
with bindings to javascript & python.
Steps for installing MRAA & UPM Library on Intel IoT Platform with
IoTDevKit Linux* image
Using a ssh client:
1. echo "src maa-upm http://iotdk.intel.com/repos/1.1/intelgalactic" >
/etc/opkg/intel-iotdk.conf
2. opkg update
3. opkg upgrade
Article: https://software.intel.com/en-us/xdk-sample-creating-a-web-server
*/
// Set this to the ip address of your board (not 127.0.0.1)
var ipAddress = '192.168.43.121';
var mraa = require('mraa'); //require mraa
console.log('MRAA Version: ' + mraa.getVersion()); //write the mraa
version to the console
// Start by loading in some data
var fs = require('fs');
var lightSensorPage = fs.readFileSync('/node_app_slot/lightsensor.html');
// Insert the ip address in the code in the page
lightSensorPage = String(lightSensorPage).replace(/<<ipAddress>>/,
ipAddress);
var analogPin0 = new mraa.Aio(0);
var analogPin1 = new mraa.Aio(1);
/**
* Given a value, convert it to Lux
*
* This uses the table given in the documentation for the
* Grove Starter Kit Plus. We have not sought to verify these
* values with our device. That would be worth doing if you
* intend to rely on these values. In that case, it could also
* be worthwhile to improve the interpolation formula
* @param {Number} - the raw reading from the device
*/
function getLux(analogValue) {
// Values taken from Grove Starter Kit for Arduino table
var lux;
var calib = [{reading:0, lux:0},
{reading:100, lux:0.2}, // guess - not from published table
{reading:200, lux:1},
{reading:300, lux:3},
{reading:400, lux:6},
{reading:500, lux:10},
{reading:600, lux:15},
{reading:700, lux:35},
{reading:800, lux:80},
{reading:900, lux:100}];
var i = 0;
while (i < calib.length && calib[i].reading < analogValue) {
i ++;
}
if (i > 0) {
i = i - 1;
}
// simple linear interpolation
lux = (calib[i].lux *(calib[i + 1].reading - analogValue) + calib[i +
1].lux * (analogValue - calib[i].reading))/(calib[i + 1].reading -
calib[i].reading);
return lux;
}
function getTemp(reading) {
// Values taken from Grove Starter Kit for Arduino table
//var voltage = reading * 5.0;
//voltage /= 1024.0;
var B=3975;
var resistance = (1023-reading)*10000/reading; //get the resistance of
the sensor;
var temperatureC =
1/(Math.log(resistance/10000)/B+1/298.15)-273.15;//convert to temperature
via datasheet ;
// now print out the temperature
//var temperatureC = reading * 0.48828125;// (voltage - 0.5) * 100 ;
//converting from 10 mv per degree wit 500 mV offset
//to degrees ((voltage -
500mV) times 100)
// now convert to Fahrenheit
//float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
//Serial.print(temperatureF); Serial.println(" degrees F");
return temperatureC;
}
var http = require('http');
http.createServer(function (req, res) {
var value;
// This is a very quick and dirty way of detecting a request for the page
// versus a request for light values
if (req.url.indexOf('lightsensor') != -1) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(lightSensorPage);
}
if (req.url.indexOf('temp') != -1) {
value = analogPin1.read();
res.writeHead(200, {'Content-Type': 'text/json'});
res.end(JSON.stringify({tempLevel:getTemp(value), rawValue:value}));
}
if (req.url.indexOf('light') != -1) {
value = analogPin0.read();
res.writeHead(200, {'Content-Type': 'text/json'});
res.end(JSON.stringify({lightLevel:getLux(value), rawValue:value}));
}
else {
value = analogPin0.read();
res.writeHead(200, {'Content-Type': 'text/json'});
res.end(JSON.stringify({lightLevel:getLux(value), rawValue:value}));
}
}).listen(1337, ipAddress);
More
1 of 977
Android Java
Inbox
x
Charif Mahmoudi
5:28 PM (0 minutes ago)
to me
package io.hackaton.charif.hackaton2;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends AppCompatActivity{
AppCompatActivity my;
int index = 0;
String [] list = new String []{
//"http://mp3light.net/assets/songs/393000-393999/393273-love-me-like-you-do-official-audio-ellie-goulding--1422369661.mp3",
//"http://musicjustfor.me/assets/songs/393000-393999/393273-love-me-like-you-do-official-audio-ellie-goulding--1422369661.mp3",
//"http://mp3music.se/audio/files/Ellie%20Goulding%20Love%20Me%20Like%20You%20Do%20Ellie%20Goulding%20Love%20Me%20Like%20You%20Do%20-%201436367953.mp3"
"F93F8QmPTrs",
"ezD9fndbeyw",
"JxNj3yNUa0k",
"JGCsyshUU-A",
"JGCsyshUU-A",
"JGCsyshUU-A",
"JGCsyshUU-A",
"F93F8QmPTrs",
"aE2GCa-_nyU",
"RrutzRWXkKs",
"55_bV4ORRFM",
"F93F8QmPTrs",
"sf6LD2B_kDQ",
"JGCsyshUU-A",
"BgAlQuqzl8o",
"sf6LD2B_kDQ",
"aE2GCa-_nyU",
"JGCsyshUU-A",
"55_bV4ORRFM",
"0dfZ9BXaNyE",
"RrutzRWXkKs",
"LDdsmqFE4js",
"F93F8QmPTrs",
"ezD9fndbeyw",
"JxNj3yNUa0k",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"F93F8QmPTrs",
"aE2GCa-_nyU",
"RrutzRWXkKs",
"55_bV4ORRFM",
"F93F8QmPTrs",
"sf6LD2B_kDQ",
"JGCsyshUU-A",
"BgAlQuqzl8o",
"sf6LD2B_kDQ",
"aE2GCa-_nyU",
"JGCsyshUU-A",
"55_bV4ORRFM",
"0dfZ9BXaNyE",
"RrutzRWXkKs",
"LDdsmqFE4js",
"F93F8QmPTrs",
"ezD9fndbeyw",
"JxNj3yNUa0k",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"F93F8QmPTrs",
"aE2GCa-_nyU",
"RrutzRWXkKs",
"55_bV4ORRFM",
"F93F8QmPTrs",
"sf6LD2B_kDQ",
"JGCsyshUU-A",
"BgAlQuqzl8o",
"sf6LD2B_kDQ",
"aE2GCa-_nyU",
"JGCsyshUU-A",
"55_bV4ORRFM",
"0dfZ9BXaNyE",
"RrutzRWXkKs",
"LDdsmqFE4js",
"F93F8QmPTrs",
"ezD9fndbeyw",
"JxNj3yNUa0k",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"F93F8QmPTrs",
"aE2GCa-_nyU",
"RrutzRWXkKs",
"55_bV4ORRFM",
"F93F8QmPTrs",
"sf6LD2B_kDQ",
"JGCsyshUU-A",
"BgAlQuqzl8o",
"sf6LD2B_kDQ",
"aE2GCa-_nyU",
"JGCsyshUU-A",
"55_bV4ORRFM",
"0dfZ9BXaNyE",
"RrutzRWXkKs",
"LDdsmqFE4js",
"F93F8QmPTrs",
"ezD9fndbeyw",
"JxNj3yNUa0k",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"F93F8QmPTrs",
"aE2GCa-_nyU",
"RrutzRWXkKs",
"55_bV4ORRFM",
"F93F8QmPTrs",
"sf6LD2B_kDQ",
"JGCsyshUU-A",
"BgAlQuqzl8o",
"sf6LD2B_kDQ",
"aE2GCa-_nyU",
"JGCsyshUU-A",
"55_bV4ORRFM",
"0dfZ9BXaNyE",
"RrutzRWXkKs",
"LDdsmqFE4js",
"F93F8QmPTrs",
"ezD9fndbeyw",
"JxNj3yNUa0k",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"F93F8QmPTrs",
"aE2GCa-_nyU",
"RrutzRWXkKs",
"55_bV4ORRFM",
"F93F8QmPTrs",
"sf6LD2B_kDQ",
"JGCsyshUU-A",
"BgAlQuqzl8o",
"sf6LD2B_kDQ",
"aE2GCa-_nyU",
"JGCsyshUU-A",
"55_bV4ORRFM",
"0dfZ9BXaNyE",
"RrutzRWXkKs",
"LDdsmqFE4js",
"LDdsmqFE4js"
};
public Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
Log.e("CHARIF", "Running intent");
//if (index>19) index = 0;
getJson();
//getJsonTemp("http://192.168.43.121:1337/temp");
//startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(list[index++])));
//myWebView.loadData(htmlp1 + list[index++] + htmlp2,
"text/html", "utf-8");
}
void getJson(){
//String url = "http://my-json-feed";
Log.e("CHARIF", "Calling Gson method");
RequestQueue queue = Volley.newRequestQueue(my);
JsonObjectRequest jsObjRequest = new JsonObjectRequest
(Request.Method.GET,
"http://192.168.43.121:1337/light", null, new
Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.e("CHARIF" ,"Response: " +
response.toString());
try {
updateIntent(response.getInt("lightLevel"));
} catch (JSONException e) {
e.printStackTrace();
}
}
void updateIntent(int v){
if(v>10) v = v/10;
if(v != index){
Log.e("CHARIF", "updating music: " + v);
index = v;
Uri uri = Uri.parse("vnd.youtube:" +
list[v]);
Intent intent = new
Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Log.e("CHARIF" , String.format("Song is:
%d", new Integer(v)));
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("CHARIF" ,"Error: " + error.toString());
}
});
queue.add(jsObjRequest);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
//new Thread(new PlayThread(myWebView)).start();
//myWebView.loadUrl(list[index++]);
my = this;
Timer myTimer = new Timer();
myTimer.schedule(new TimerTask() {
@Override
public void run() {
mHandler.sendEmptyMessage(0);
}
}, 0, 10000);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
More
1 of 977
Android Java
Inbox
x
Charif Mahmoudi
5:28 PM (0 minutes ago)
to me
package io.hackaton.charif.hackaton2;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends AppCompatActivity{
AppCompatActivity my;
int index = 0;
String [] list = new String []{
//"http://mp3light.net/assets/songs/393000-393999/393273-love-me-like-you-do-official-audio-ellie-goulding--1422369661.mp3",
//"http://musicjustfor.me/assets/songs/393000-393999/393273-love-me-like-you-do-official-audio-ellie-goulding--1422369661.mp3",
//"http://mp3music.se/audio/files/Ellie%20Goulding%20Love%20Me%20Like%20You%20Do%20Ellie%20Goulding%20Love%20Me%20Like%20You%20Do%20-%201436367953.mp3"
"F93F8QmPTrs",
"ezD9fndbeyw",
"JxNj3yNUa0k",
"JGCsyshUU-A",
"JGCsyshUU-A",
"JGCsyshUU-A",
"JGCsyshUU-A",
"F93F8QmPTrs",
"aE2GCa-_nyU",
"RrutzRWXkKs",
"55_bV4ORRFM",
"F93F8QmPTrs",
"sf6LD2B_kDQ",
"JGCsyshUU-A",
"BgAlQuqzl8o",
"sf6LD2B_kDQ",
"aE2GCa-_nyU",
"JGCsyshUU-A",
"55_bV4ORRFM",
"0dfZ9BXaNyE",
"RrutzRWXkKs",
"LDdsmqFE4js",
"F93F8QmPTrs",
"ezD9fndbeyw",
"JxNj3yNUa0k",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"F93F8QmPTrs",
"aE2GCa-_nyU",
"RrutzRWXkKs",
"55_bV4ORRFM",
"F93F8QmPTrs",
"sf6LD2B_kDQ",
"JGCsyshUU-A",
"BgAlQuqzl8o",
"sf6LD2B_kDQ",
"aE2GCa-_nyU",
"JGCsyshUU-A",
"55_bV4ORRFM",
"0dfZ9BXaNyE",
"RrutzRWXkKs",
"LDdsmqFE4js",
"F93F8QmPTrs",
"ezD9fndbeyw",
"JxNj3yNUa0k",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"F93F8QmPTrs",
"aE2GCa-_nyU",
"RrutzRWXkKs",
"55_bV4ORRFM",
"F93F8QmPTrs",
"sf6LD2B_kDQ",
"JGCsyshUU-A",
"BgAlQuqzl8o",
"sf6LD2B_kDQ",
"aE2GCa-_nyU",
"JGCsyshUU-A",
"55_bV4ORRFM",
"0dfZ9BXaNyE",
"RrutzRWXkKs",
"LDdsmqFE4js",
"F93F8QmPTrs",
"ezD9fndbeyw",
"JxNj3yNUa0k",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"F93F8QmPTrs",
"aE2GCa-_nyU",
"RrutzRWXkKs",
"55_bV4ORRFM",
"F93F8QmPTrs",
"sf6LD2B_kDQ",
"JGCsyshUU-A",
"BgAlQuqzl8o",
"sf6LD2B_kDQ",
"aE2GCa-_nyU",
"JGCsyshUU-A",
"55_bV4ORRFM",
"0dfZ9BXaNyE",
"RrutzRWXkKs",
"LDdsmqFE4js",
"F93F8QmPTrs",
"ezD9fndbeyw",
"JxNj3yNUa0k",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"F93F8QmPTrs",
"aE2GCa-_nyU",
"RrutzRWXkKs",
"55_bV4ORRFM",
"F93F8QmPTrs",
"sf6LD2B_kDQ",
"JGCsyshUU-A",
"BgAlQuqzl8o",
"sf6LD2B_kDQ",
"aE2GCa-_nyU",
"JGCsyshUU-A",
"55_bV4ORRFM",
"0dfZ9BXaNyE",
"RrutzRWXkKs",
"LDdsmqFE4js",
"F93F8QmPTrs",
"ezD9fndbeyw",
"JxNj3yNUa0k",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"eyU3bRy2x44",
"F93F8QmPTrs",
"aE2GCa-_nyU",
"RrutzRWXkKs",
"55_bV4ORRFM",
"F93F8QmPTrs",
"sf6LD2B_kDQ",
"JGCsyshUU-A",
"BgAlQuqzl8o",
"sf6LD2B_kDQ",
"aE2GCa-_nyU",
"JGCsyshUU-A",
"55_bV4ORRFM",
"0dfZ9BXaNyE",
"RrutzRWXkKs",
"LDdsmqFE4js",
"LDdsmqFE4js"
};
public Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
Log.e("CHARIF", "Running intent");
//if (index>19) index = 0;
getJson();
//getJsonTemp("http://192.168.43.121:1337/temp");
//startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(list[index++])));
//myWebView.loadData(htmlp1 + list[index++] + htmlp2,
"text/html", "utf-8");
}
void getJson(){
//String url = "http://my-json-feed";
Log.e("CHARIF", "Calling Gson method");
RequestQueue queue = Volley.newRequestQueue(my);
JsonObjectRequest jsObjRequest = new JsonObjectRequest
(Request.Method.GET,
"http://192.168.43.121:1337/light", null, new
Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.e("CHARIF" ,"Response: " +
response.toString());
try {
updateIntent(response.getInt("lightLevel"));
} catch (JSONException e) {
e.printStackTrace();
}
}
void updateIntent(int v){
if(v>10) v = v/10;
if(v != index){
Log.e("CHARIF", "updating music: " + v);
index = v;
Uri uri = Uri.parse("vnd.youtube:" +
list[v]);
Intent intent = new
Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Log.e("CHARIF" , String.format("Song is:
%d", new Integer(v)));
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("CHARIF" ,"Error: " + error.toString());
}
});
queue.add(jsObjRequest);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
//new Thread(new PlayThread(myWebView)).start();
//myWebView.loadUrl(list[index++]);
my = this;
Timer myTimer = new Timer();
myTimer.schedule(new TimerTask() {
@Override
public void run() {
mHandler.sendEmptyMessage(0);
}
}, 0, 10000);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Dr. Charif Mahmoudi
13 projects • 127 followers
PhD, Actually PostDoc. My areas of research are on distributed systems, cloud-computing, mobile computing, and IoT.
Joshua Odumosu
1 project • 0 followers
I'm an Electrical and Computer Engineer graduate student with specialization in Signal intelligence. I'm presently researching on network penetration & security
Comments