app.LoadPlugin( "BluetoothLE" );
function OnStart()
{
//Create a text control to show debug log.
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
txt = app.CreateText( "", 1, 1, "Log" );
lay.AddChild( txt );
app.AddLayout( lay );
//Create Bluetooth LE object.
ble = app.CreateBluetoothLE();
ble.SetOnDevice( OnDevice );
//Check for Puck button presses every 3 seconds
setInterval( CheckForButtonPress, 3000 );
txt.Log( "ready" );
calling = false;
}
function CheckForButtonPress()
{
//Do a brief scan to check for puck button press.
ble.StartScan();
setTimeout( function(){ble.StopScan()}, 1000 );
}
//Called when any BLE device is found by the scan.
function OnDevice( name, address, bonded, rssi, data )
{
txt.Log( name + ": " + data.url );
if( data.url=="https://call.true" ) MakeCall();
}
//Make the call (limit to one every 5 seconds).
function MakeCall()
{
if( calling ) return;
txt.Log( "calling", "red" );
calling = true;
app.Call( "01359555222" );
setTimeout( function(){calling=false;}, 5000 )
}
You could optionally put the DroidScript code inside a DroidScript service and have it always running in the background on your phone too :)
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi Guys, You can easily do this in DroidScript with the BLE plugin
Here is the Puck.js code:-
And Here is the DroidScript code:-
You could optionally put the DroidScript code inside a DroidScript service and have it always running in the background on your phone too :)