This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Someone have a example of reading orientation sensor in javascript/HTML of the Thingy:52 equal of the github Nordic Example? https://github.com/NordicPlayground/Nordic-Thingy52-Thingyjs#absolute-orientation

Someone have a example of reading orientation sensor in javascript/HTML of the Thingy:52 equal of the github Nordic Example? github.com/.../Nordic-Thingy52-Thingyjs

  • Hi Daniel

    Is this example not what you are looking for? If not, please be more specific.

    Best regards,

    Simon

  • Ok, i want to try reading the caracteristics of the Thingy Motion Service in my Javascript application, like quartenation characteristic, Euler Characteristic, Thingy Heading Characteristic, Thingy Gravity Characteristic and etc. In this example i trying to read the gravity sensor unsuccessfully.

    <!doctype html>
    <html>
      <head>
        <title>Thingy:52 Web Bluetooth Gravity</title>
      </head>
      <body>
        <h1>Thingy:52 Gravity reading example</h1>
        <button id="connectBtn">Connect</button>
        <div id="gravityvector"></div>
        <script type="module">
          
          import Thingy from "../index.js";
    
          const thingy = new Thingy({logEnabled: true});
          
    
          async function start(device) {
            await device.connect();
            await device.formatedData.start();
            await device.addEventListener("gravityvector", logData);
          }
    
          function logData(data) {
            const el = document.querySelector("#gravityvector");
            el.innerHTML = `Gravity: ${data.detail.value}`;
          }
          
          document.querySelector("#connectBtn").addEventListener("click", async () => {
              start(thingy);
          });
        </script>
      </body>
    </html>
    
    import FeatureOperations from "./FeatureOperations.js";
    
    class GravityVectorSensor extends FeatureOperations {
      constructor(device) {
        super(device, "gravityvector");
    
        // gatt service and characteristic used to communicate with Thingy's gravity vector sensor
        this.service = {
          uuid: this.device.TMS_UUID,
        };
    
        this.characteristic = {
          uuid: this.device.TMS_GRAVITY_UUID,
          decoder: this.decodeGravityVectorData.bind(this),
        };
      }
    
      decodeGravityVectorData(data) {
        try {
          const x = data.getFloat32(0, true);
          const y = data.getFloat32(4, true);
          const z = data.getFloat32(8, true);
    
          const formattedData = {
            value: {x: x, y: y, z: z},
          };
    
          return formattedData;
        } catch (error) {
          throw error;
        }
      }
    }
    
    export default GravityVectorSensor;
    

  • Hi Daniel

    If you take a look at the supported operations, you can see that gravityvector read and write functions are not supported in this repo. Same goes for quaterion, Euler, Heading and absolute orientation. To read and write these operation I suggest you take a look at the user guide and how it is done in for example the Android version, and try to convert that to js. 

    Best regards,

    Simon

  • Do you have a link of the android Example in the user guide, please?

Related