Apps Home
|
Create an App
Tip Controlled Philips Hue Light
Author:
freshtop
Description
Source Code
Launch App
Current Users
Created by:
Freshtop
// vars var last_tip_username = null; var last_tip_amount = 0; //ip of light bridge var ip = '192.168.2.4'; //Password to talk to the light bridge var key = 'JVurqBCOmxBsGUCKFrtqSZpNw8CgUSsAiDPtTiGs'; var id = 1; var state = 1; cb.settings_choices = [ ]; // handlers cb.onTip(function(tip) { //input last_tip_amount = tip['amount'] last_tip_username = tip['from_user'] //process tip SendValue(last_tip_amount); //output cb.drawPanel(); }); cb.onDrawPanel(function(user) { return { 'template': '3_rows_of_labels', 'row1_label': 'Last Tip:', 'row1_value': format_username(last_tip_username) + ' (' + last_tip_amount + ')' }; }); function format_username(val) { if (val === null) { return "--"; } else { return val.substring(0, 12); } } function SendValue(power) { var randomColor = getRandomInt(1, 65280); //ajaxreq = new XMLHttpRequest(); //ajaxreq.open("PUT",'http://' + ip + '/api/' + key +'/lights/' + id + '/state'); //ajaxreq.onreadystatechange = readystatechange_parsejson; //if (state == 1) // ajaxreq.send('{"on": true}'); //if (state == 0) // ajaxreq.send('{"on": false}'); //MakeRequest("PUT", 'http://' + ip + '/api/' + key +'/lights/' + id + '/state', '{"on": false}'); //post('http://' + ip + '/api/' + key +'/lights/' + id + '/state', {on: 'false'},'PUT'); //post('http://' + ip + '/api/' + key +'/lights/' + id + '/state', '{"on": false}'); //var url = 'http://' + ip + '/api/' + key +'/lights/' + id + '/state'; //document.body.innerHTML += '<form id="dynForm" action="http://www.google.com" //method="put"><input type="hidden" name="q" value="a"></form>'; //document.getElementById("dynForm").submit(); //var url = 'http://' + ip + '/api/' + key +'/lights/' + id + '/state'; //httpobj.open("POST", url, true); //httpobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded; //charset=UTF-8'); //httpobj.onreadystatechange=handler; //httpobj.send(post); } function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } //function post(path, params, method) { // method = method || "post"; // Set method to post by default if not specified. // // The rest of this code assumes you are not using a library. // It can be made less wordy if you use one. //var form = document.createElement("form"); //form.setAttribute("method", method); // form.setAttribute("action", path); // //for(var key in params) { // if(params.hasOwnProperty(key)) { // var hiddenField = document.createElement("input"); // hiddenField.setAttribute("type", "hidden"); // hiddenField.setAttribute("name", key); // hiddenField.setAttribute("value", params[key]); // // form.appendChild(hiddenField); // } // } // // document.body.appendChild(form); // form.submit(); //} function post(path, parameters) { var form = $('<form></form>'); form.attr("method", "PUT"); form.attr("action", path); $.each(parameters, function(key, value) { var field = $('<input></input>'); field.attr("type", "hidden"); field.attr("name", key); field.attr("value", value); form.append(field); }); // The form needs to be a part of the document in // order for us to be able to submit it. $(document.body).append(form); form.submit(); }
© Copyright Chaturbate 2011- 2025. All Rights Reserved.