Bangle GPS service for Kospet ROCK and Magic 3

Posted on
  • Bangle GPS service for Kospet ROCK and Magic 3

    In a previous post I posted the image of a Bangle simulation environment for the ROCK and Magic3 watches. These watches have an NRF52840 processor and a large 240x280 screen which in the case of the ROCK is very bright.

    The image showed Wave Clock loaded directly from the BangleApp Loader as a demonstration of the Bangle emulation environment for the ROCK. However, this is very limited as many of the most interesting Bangle Apps use sensors such as GPS so following an idea suggested some time ago by @fanoush, I have implemented an App for the Bangle which provides a BLE service that makes the Bangle's GPS readings available externally.

    img

    Using this, the ROCK and Magic 3 can now run Bangle GPS apps loaded again directly from the App Loader. The Open Street Map App is shown below:

    img

    The interface to the GPS on the Bangle 1 & 2 is very narrow and that facilitates emulation. For interest, I include the full emulation code here:

    Bangle.setGPSPower = function(on){
        if (Bangle.gpsOn && on) return; //already started
        function unpack(v){
            var fix = v.getInt8(29);
            function ck(d) {return d==-1 ? NaN : d;}
            return {
              lat:ck(v.getFloat32(0)),
              lon:ck(v.getFloat32(4)),
              alt:ck(v.getFloat32(8)),
              speed:ck(v.getFloat32(12)),
              course:ck(v.getFloat32(16)),
              time:new Date(v.getFloat64(20)),
              satellites:v.getInt8(28),
              fix:fix,
              hdop:ck(v.getFloat32(30)),
            }
        }
        if (on) {
            Bangle.gpsOn=true;
            NRF.requestDevice({timeout:4000, filters: [{ name: 'gps' }] }).then(function(device) {
            //console.log("Found");
            return device.gatt.connect();
            }).then(function(g) {
                //console.log("Connected");
                Bangle.gpsgatt = g;
                return g.getPrimaryService("974e0001-1b9a-4468-a83d-7f811b3dbaff");
            }).then(function(service) {
                return service.getCharacteristic("974e0002-1b9a-4468-a83d-7f811b3dbaff");
            }).then(function (c) {
                Bangle.gpscharistic=c;
                //console.log("Got Characteristic");
                Bangle.gpsInterval = setInterval(function(){
                    Bangle.gpscharistic.readValue().then(function(d){
                        Bangle.gpsFix=unpack(d);
                        Bangle.emit("GPS",Bangle.gpsFix);
                    });
                },1000);
            }).catch(function(e){
                E.showMessage("GPS: "+e,"ERROR");
            });
        } else {
            Bangle.gpsOn=false;
            if (Bangle.gpsInterval) Bangle.gpsInterval = clearInterval(Bangle.gpsInterval);
            if(Bangle.gpsgatt) Bangle.gpsgatt.disconnect();
            delete Bangle.gpsgatt;
            delete Bangle.gpscharistic;
        }
    }
    
    Bangle.getGPSFix = function() {return Bangle.gpsFix;}
    

    The Bangle GPS server code can be found here.

    I have found the Bangle 1 GPS to be more sensitive than the Bangle 2, so it may be that if you have both Bangles, this may be of use. I have found the Bluetooth link between ROCK and Bangle really reliable and its no problem to carry the Bangle in a top pocket or a back pack.

  • Wow, great to see it working. Good candidate for running this is also the B5 fitness tracker as it is relatively cheap and small. It has same gps as bangle 2 but it appears to be more sensitive most probably because of this https://i.ibb.co/Fqf8mXZ/IMG-20201103-174322.jpg

  • The advantage of using the Bangle is that the firmware in jswrap_bangle.c and nmea.c turns the NMEA strings received from the GPS device into espruino events. To implement the server on the B5 you would need to have an NMEA parser etc - probably too slow in Javascript so it would probably need firmware hacking - although all the software is already there for the Bangle 2. A further advantage is that the Bangle has a relatively large 350maH battery. Advantage would be that the B5 is smaller to carry around:)

  • Wow! Great project! I really like the idea of emulation Bangle on other devices. And a great idea with GPS sharing!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Bangle GPS service for Kospet ROCK and Magic 3

Posted by Avatar for jeffmer @jeffmer

Actions