Skip to content

Instantly share code, notes, and snippets.

@walterhiggins
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterhiggins/d0d432688dcda8c54eda to your computer and use it in GitHub Desktop.
Save walterhiggins/d0d432688dcda8c54eda to your computer and use it in GitHub Desktop.
Updated arduino-light code
var mqtt = require('sc-mqtt'),
slash = require('slash'),
client = mqtt.client('tcp://localhost:1883','sc-ard-light'),
preDawn = 22000,
JavaString = java.lang.String;
client.connect();
client.subscribe('arduino-light');
var max = 0;
function updateTime(topic, message){
var val = +(new JavaString(message.payload));
if (val > max && (val - max < 10)){
max = val;
}
var rawTime = preDawn + (val * (8000/max));
var time = Math.floor(rawTime % 24000);
slash('time set ' + time , server);
}
client.onMessageArrived(updateTime);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment