Avatar for Dave_Smart

Dave_Smart

Member since Dec 2016 • Last active Oct 2017
  • 3 conversations
  • 13 comments

Most recent activity

  • in News
    Avatar for Dave_Smart

    Hi Guys,

    I thought that you might be interested to know that the latest beta version of DroidScript now lets you target Espruino as a project type.

    This allows programming of Espruino micro-controller boards directly from your Android Phone/Tablet using an OTG cable. It works completely off-line (even with Espruino modules), so you can use DroidScript as an in-the-field programming device even when you have no mobile signal. A USB serial terminal will popup when you run this type of project and allow debugging and testing etc too :)

    This version of DroidScript is currently in beta and the APK can be directly downloaded here:-
    http://androidscript.org/beta/DroidScrip­t_157b1

    (If you join the beta program then it will be available to you through Google Play too)

    I would be grateful for feedback on the current functionality before I do a public release. If you would like to join the DroidScript beta forum, then please send a request to david@droidscript.org

    Thanks
    David

  • in Puck.js
    Avatar for Dave_Smart

    You could probably combine NFC and BLE to do it. I've already implemented BLE payments with DroidScript and Paypal on an Android tablet acting as a BLE server/advertiser... but I used a Puck as my test server before I got hold of the tablet. You might be able to trigger off the BLE comms process using the NFC and then authorise a payment using PayPal or Stripe after some handshaking over BLE

  • in Puck.js
    Avatar for Dave_Smart

    Just use this code on DroidScript (make sure you install the Puck.js plugin on DroidScript first)

    app.LoadPlugin( "PuckJS" );
    
    function OnStart()
    {
      lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
      txt = app.CreateText( "Press your puck" );
      lay.AddChild( txt );
      app.AddLayout( lay );
      puck = app.CreatePuckJS();
      puck.SetOnConnect( OnConnect );
      puck.SetOnButton( OnButton );
      puck.Scan( "Puck" );
    }
    function OnConnect()
    {
      puck.WatchButton( true );
    }
    function OnButton( state )
    {
      txt.SetText( "Hello World" );
    }
    
  • in Puck.js
    Avatar for Dave_Smart

    Actually the easiest way is to use free coding tool DroidScript with the free Puck.js plugin.
    Here is the code (taken from the Puck.js plugin docs)

    app.LoadPlugin( "PuckJS" );
    
    function OnStart()
    {
      lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
    
      var code = "digitalWrite( LED1, 1 )"; 
    
      txt = app.CreateTextEdit( code, 0.9, 0.8, "MultiLine" );
      lay.AddChild( txt );
      app.AddLayout( lay );
    
      layHoriz = app.CreateLayout( "Linear", "Horizontal" );
      lay.AddChild( layHoriz );
    
      btnSend = app.CreateButton( "Send", 0.3, 0.1 );
      btnSend.SetOnTouch( btnSend_OnTouch );
      layHoriz.AddChild( btnSend );
    
      btnSave = app.CreateButton( "Save", 0.3, 0.1 );
      btnSave.SetOnTouch( btnSave_OnTouch );
      layHoriz.AddChild( btnSave );
    
      btnReset = app.CreateButton( "Reset", 0.3, 0.1 );
      btnReset.SetOnTouch( btnReset_OnTouch );
      layHoriz.AddChild( btnReset );
    
      microbit = app.CreatePuckJS();
      microbit.Scan( "Puck" );
    }
    
    function btnSend_OnTouch()
    {
      microbit.SendCode( txt.GetText() );
    }
    
    function btnSave_OnTouch()
    {
      microbit.Save();
    }
    
    function btnReset_OnTouch()
    {
      microbit.Reset();
    }
    
  • in Puck.js
    Avatar for Dave_Smart

    Here is a more sophisticated solution that does not require a constant (battery draining) connection:-

    http://forum.espruino.com/conversations/­298102/#comment13448826

  • in Puck.js
    Avatar for Dave_Smart

    Hi Guys, You can easily do this in DroidScript with the BLE plugin

    Here is the Puck.js code:-

    function advertise(url) {
      var d = [0x03, 0x03, 0xAA, 0xFE, 0x13, 0x16,  0xAA, 0xFE, 0x10,  0xF8, 0x03 ];
      d.push.apply(d,url.toString().split(""))­;
      d[4] = d.length-5;
      NRF.setAdvertising(d, {interval:100});
    }
    
    advertise( "call.false");
    
    function makeCall( call ) {
        advertise( "call."+call  );
        digitalWrite( LED3, call?1:0 );
    }
    
    setWatch(function() {
       makeCall( true );
       setTimeout( function() { makeCall(false) }, 5000 );
    }, BTN, {edge:"rising", debounce:50, repeat:true});
    
    
    

    And Here is the DroidScript code:-

    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 :)

  • in Puck.js
    Avatar for Dave_Smart

    FYI: The ASUS ZenPad Z380M works as a GATT Server. The best app to test BLE server capability is the Nordics "nRF Connect" app on Google Play. You need devices with Android 5 or higher and hardware support included.

    Worth mentioning that DroidScript has a BLE Beacon/Server plugin in beta (if you ask on the forum then you can probably get hold of it)

    https://groups.google.com/forum/#!forum/­androidscript

    These devices supposedly also support BLE advertising:-

    Phones and tablets
    Google Pixel [XL], Pixel C, Nexus 6P, 6, 5X, 9, patched Nexus 5
    Alcatel One Touch Idol 3 [Dual SIM], Fierce XL
    Asus Zenfone 2 [Laser], Zenpad 8
    Blackberry Priv
    HTC 10, One M9, Desire (530/626s/820)
    Huawei Ascend Y550, Honor 5X, Union
    Lenovo K3 Note, Vibe P1m, Vibe K4 Note
    LG:
    G5, G4 [Stylus], G3, G Flex2, G Vista 2
    V10, K10, L Bello, Lancet, Leon, Magna, Optimus Zone 3, Spirit, Tribute 5
    Moto X Play, X Style, X2, G2, G3, G4, Z Droid, Droid Turbo 2
    Nextbit Robin
    OnePlus 2, 3
    OPPO A33f
    Samsung Galaxy:
    S7 [Edge] - up to 8 concurrent running BLE advertisers
    S6 [Active/Edge/Edge Plus], S5 [Active/Neo]
    Note 5, Note Edge, Note 4
    Tab S2 (8.0/9.7), Tab S (8.4/10.5), Note Pro, Tab A 9.7, Tab E
    A5 2016 [Duos]
    J5, J3 Duos
    Alpha, Core Prime, Grand Prime, On7
    Sony Xperia E5, X, Z5 [Compact/Premium], C5 Ultra, C3, M4 Aqua [Dual]
    Xiaomi Redmi 3, Note 2, Note 3, Mi 4, Mi 4i, Mi 5, Mi Max
    ZTE Maven, ZMAX 2, Zmax Pro, Warp Elite
    Android TVs
    Sony Bravia 2015

  • in Puck.js
    Avatar for Dave_Smart

    You could also build a DroidScript service which stays always running in the background and watches for the button presses.

  • in Puck.js
    Avatar for Dave_Smart

    OK, I was wrong. It took 2 minutes :)

    Here is the code:-

    app.LoadPlugin( "PuckJS" );
    
    function OnStart()
    {
      lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
      txt = app.CreateText( "Press your puck" );
      lay.AddChild( txt );
      app.AddLayout( lay );
    
      puck = app.CreatePuckJS();
      puck.SetOnConnect( OnConnect );
      puck.SetOnButton( OnButton );
      puck.Scan( "Puck" );
    }
    
    function OnConnect()
    {
      puck.WatchButton( true );
    }
    
    function OnButton( state )
    {
      app.Call( "01359555555" );
    }
    
Actions