Shop OBEX P1 Docs P2 Docs Learn Events
Puck.js - the ground-breaking bluetooth beacon — Parallax Forums

Puck.js - the ground-breaking bluetooth beacon

Heater.Heater. Posts: 21,230
edited 2016-08-03 10:11 in General Discussion
Get your Bluetooth Low Energy adapter now: https://www.kickstarter.com/projects/gfw/puckjs-the-ground-breaking-bluetooth-beacon

I try not to advertise other peoples products here but this is usable with the Propeller. And it is by Gordon Williams who brought us the Espruino Javascript engine that may well run on the P2 one day.

Gordon just needs a few more pledges in to meet the last stretch goal then he has promised to work on IPv6 over BLE for the Puck. Which would be great.

Only 56 hours to go!
«1

Comments

  • Can we pledge negative dollars to help prevent the creation of new JavaScript based technology?
  • Heater.Heater. Posts: 21,230
    edited 2016-08-03 10:51
    Grrr....

    You mean you want to spell "Puck.js" with a "F" ?

    OK, how about a positive value pledge and you just program the thing in C++ using the tool chain that Gordon will provide. There will be a lot of support functionality in there you can reuse :)


  • Okay, I did my bit. I'm really beginning to like JavaScript. I was just reading about promises the other day and of course closures have been there for some time. It's really beginning to remind me of my Lisp programming days...
  • David Betz wrote: »
    Okay, I did my bit. I'm really beginning to like JavaScript. I was just reading about promises the other day and of course closures have been there for some time. It's really beginning to remind me of my Lisp programming days...

    I picked up Function Programming in JavaScript recently as part of Packt's Free Learning offer. While I think the book could have used better proofreading, the content itself was very good! For $10 (eBook version), you'll get a decent introduction to functional programming (if you don't already know it) and an excellent explanation of how to get functional with JavaScript.
  • Heater.Heater. Posts: 21,230
    edited 2016-08-03 13:06
    The Functional Programming book looks like a good read. I really have not got by head around functional programming except that I use react.js and immutable.js which is basically a functional, stateless, system. Unless you mess it up of course.

    Just now I have been getting back to my old favorite methodology, Communicating Sequential Processes (CSP). See below. Note how there are two "processes" running there exchanging messages in a do forever loop in there. Normally not a good idea in JS.

    Sadly this won't work on Espruino as it does not support ES6 generators.

    CSP would be a great thing to have on the P2 what with all the COGs it has.
    var csp = require("js-csp");
    
    // A ping-pong player
    class Player {
        constructor(name, tableChannel) {
            this.name = name;
            this.tableChannel = tableChannel;
    
            // We start the player playing as soon as he is constructed
            csp.go(this.run.bind(this), ['parm1', 'param2']);
        }
    
        // Run method is a generator so we can do csp stuff 
        * run (param1, param2) {
    
            // 'ping' is first to go and hits the ball to the table
            if (this.name === 'ping') {
                let ball = {hits: 0};
                yield csp.put(this.tableChannel, ball);
            }
    
            // Loop forever playing ping pong
            for (;;) {
                // Wait for ball to arrive from table
                var ball = yield csp.take(this.tableChannel);
    
                // Check if the table had gone away
                if (ball === csp.CLOSED) {
                    console.log(this.name + ": table's gone");
                    // Can't continue so just return
                    return;
                }
    
                // Hit the ball back to the table            
                ball.hits += 1;
                console.log(`${this.name} ${ball.hits}`);
                yield csp.timeout(100);
                yield csp.put(this.tableChannel, ball);
            }
        }
    }
    
    // We put our main line code in a generator only because it uses csp.timeout()
    csp.go(function* () {
    
        // Create a "ping pong table", actually just a csp channel
        var tableChannel = csp.chan();
    
        // Create two players giving them names and a table to play on
        let player1 = new Player('ping', tableChannel);
        let player2 = new Player('pong', tableChannel);
    
        // Wait one second 
        yield csp.timeout(1000);
    
        // And take the table away!
        tableChannel.close();
    });
    
  • Heater. wrote: »
    ... Concurrent Sequential Processes (CSP) ...

    Communicating Sequential Processes?

    Interesting use of generators and message-passing. It all generally makes sense, except the run parameters. Are those necessary, or were you just showing how parameter values are be passed?
  • Heater.Heater. Posts: 21,230
    edited 2016-08-03 13:28
    Searith,

    Well spotted. Yes, I meant "Communicating Sequential Processes", no idea how my fingers typed totally the wrong thing.

    Yes, the "[ 'parm1', 'param2' ]" thing is just there to show how parameters can be passed to the process to be run. Not used here.

    Actually I'm not so happy with the "this.run.bind(this)" thing. This is an experiment in using CSP with ES6 class. And here I am having to mess around with 'bind' to get 'this' to work. I'd rather have "this.run". I'm not sure why csp.go can't run the given function with the current 'this''. If you see what I mean.

  • Heater:

    I see your example contains this:
    class Player {
    
    When was the "class" keyword added?
  • Heater.Heater. Posts: 21,230
    edited 2016-08-03 14:29
    "class" is an ES6 thing. Or is it ES2015? http://es6-features.org/

    I'm not sure I like it much. Object oriented programming can get silly. Especially with inheritance. Anyway it was easy enough to make such classes in JS before.

    I suspect the ECMAScript standards committee has become infested with Java programmers who think that JS is a broken Java that needs fixing rather than a totally different language. We can expect them to shoehorn junk like types, public this, private that etc into the standard in the coming years. And JS will be bastardized into a horrible mess.

    On the bright side, a lot of those ES6 features, some of which are pretty neat, are already implemented in the main browsers, Firefox, Chrome, Edge. So I just use them. If someone can't get it to work in some old IE I have no sympathy.

    http://kangax.github.io/compat-table/es6/

  • Ugh. Looks like JavaScript is a fast moving target. What hope is there that it might stabilize sometime soon?
  • Heater.Heater. Posts: 21,230
    Ugh, Javascript has been, and is, one of the most stable languages ever. On a par with C++. For example the standard did not change from 1999 (ES3) to 2009 (ES5). The ES4 update was abandoned. Now we have ES6 in 2015. The gory history is here: https://en.wikipedia.org/wiki/ECMAScript

    The changes are always backwards compatible. They do not break your old code. Unlike some other languages, cough, python.

    But, you have a point. What if I want to use new ES6 features but I want my code to work in older browsers?

    No problem. Just run your ES6 source through a transpiler. Notably babel.js https://babeljs.io/ and serve that up as ES5.

    Of course that is a bit silly, the new browsers already have a lot of the new features. Users have a choice of at least two open source browsers. Those incarcerated in Windows have the Edge. I have the luxury of not having to support old junk :)

  • David Betz wrote: »
    Ugh. Looks like JavaScript is a fast moving target. What hope is there that it might stabilize sometime soon?

    Tempting as it is to blame JavaScript, this seems to be an issue with the libraries surrounding JS. Those change by the minute it seems. I doubt it'll calm down soon.
  • Do you have any suggestions for a good introduction to modern JavaScript? I have a copy of Eloquent JavaScript but it seems to already be out of date. The version I have uses ES3 and the 2nd edition uses ES5.
  • Heater.Heater. Posts: 21,230
    Oh yeah. JS libraries and "frameworks" grow like weeds. In node.js land the growth of modules has been a big bang! It can drive one nuts trying to sort the wheat from the chaff. Let alone what might fit ones application nicely.



  • David BetzDavid Betz Posts: 14,511
    edited 2016-08-03 16:37
    Heater. wrote: »
    Oh yeah. JS libraries and "frameworks" grow like weeds. In node.js land the growth of modules has been a big bang! It can drive one nuts trying to sort the wheat from the chaff. Let alone what might fit ones application nicely.


    Do you have any suggestions for a node.js Bluetooth module or library? I've been looking at noble and bleno.

  • PublisonPublison Posts: 12,366
    edited 2016-08-03 16:44
    Heater. wrote: »

    But...it's already funded. It's going to happen.


  • Heater.Heater. Posts: 21,230
    No idea David. Never played with bluetooth.

    I notice the Bluetooth minders have a Bluetooth "gateway" that is supposed to work with node and on a Raspi even. Of course they want you to register bla, bla to try it. So I don't.

    Hence wanting to encourage Gordon Williams to provide such a gateway, that is free, open source, and usable anywhere.

  • Heater.Heater. Posts: 21,230
    Hmm...so I downloaded the Bluetooth minders gateway package "Gateway Smart Starter Kit". It uses "noble". I have no idea what all this does.
  • Heater.Heater. Posts: 21,230
    I might have to take that back. The Bluetooth minders starter kit seems to also be open source and usable anywhere. Might have to give it a spin.
  • Heater.Heater. Posts: 21,230
    Publison,

    What I'm talking about is the £100,000 stretch goal which gets us:

    "Add support for IPv6 over Bluetooth to Puck.js, as well as Raspberry Pi hub software (this would be a firmware update after shipping, to avoid any delays)"

    Which would be nice.
  • Heater. wrote: »
    Publison,

    What I'm talking about is the £100,000 stretch goal which gets us:

    "Add support for IPv6 over Bluetooth to Puck.js, as well as Raspberry Pi hub software (this would be a firmware update after shipping, to avoid any delays)"

    Which would be nice.

    I did not see the stretch goal on the link:

    https://www.kickstarter.com/projects/gfw/puckjs-the-ground-breaking-bluetooth-beacon

    Looks like it's about 4000 pounds short.

  • Heater.Heater. Posts: 21,230
    Yep. Got any beer money to throw into the pot?
  • Heater.Heater. Posts: 21,230
    Bingo!

    Puck.js just made it's 100,000 stretch goal. With only 36 hours to go. https://www.kickstarter.com/projects/gfw/puckjs-the-ground-breaking-bluetooth-beacon/posts/1643002

    More Javascript goodness coming to the world.

    Now the long wait till delivery in December.

    Should be just in time to hook up to a P2 chip right?
  • Heater.Heater. Posts: 21,230
    Oh yeah, Omega 2 Plus is next on the list. That's crazy they came to Kickstarter asking for 15 thousand and are now up to nearly 230 thousand !
  • Can you tell what chipset the Omega 2 is using?
  • Heater.Heater. Posts: 21,230
    No idea. Seems to be some kind of secret.

    I'm guessing its some version of a Qualcomm/Atheros MIPS system-on-chip. As used in many cheap home WIFI routers. And used in this board:
    http://hackerboards.com/tiny-wifi-loaded-openwrt-com-starts-at-12/
  • I just received my Puck.js. Anyone else here have one?

    It's smaller than I thought it would be. The PCB is about 28.5mm across.

    I'm off to figure out what I'm supposed to do with it now.



  • I got mine today. I have no idea what I'm going to do with it but it sounded cool. :-)
Sign In or Register to comment.