Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic Sensor API not working on localhost

I'm trying to use Generic Sensor API(Gyroscope) in my project I've looked up for documentation on W3C and Intel Github and https://mobiforge.com/design-development/the-generic-sensor-api I've created/copied https://mobiforge.gitlab.io/sensors/gyroscope.html this HTML page to reference javascript it works fine when i open with this link or my github link: Screen Shot of my github page nishanksisodiya.github.io/gyro

But when i open it with a flask server running on my laptop it gives Gyroscope not supported error Screen Shot my localhost page

    let status = document.getElementById('status');
    if ( 'Gyroscope' in window ) {
        let sensor = new Gyroscope();
        sensor.addEventListener('reading', function(e) {
            status.innerHTML = 'x: ' + e.target.x + '<br> y: ' + e.target.y + '<br> z: ' + e.target.z;
        });
        sensor.start();
    }
    else status.innerHTML = 'Gyroscope not supported';

here's the javascript i used. Any help would be appreciated.

like image 656
Nishank Sisodiya Avatar asked Oct 03 '19 05:10

Nishank Sisodiya


1 Answers

I myself had a ton of difficulty with the generic sensor api and discovered that one of the rarely mentioned requirements for it to work is that it has to be used within a secure context. Which means an SSL certificate for the hosting domain. Which... would make local development pretty difficult, right?

Well, I've found a way around that with localtunnel.

Deployment, however... is another story. I've had some issues for some time now moving it beyond my webpack dev server on this react application I've been working on for ages. Any and all help with that is VERY much appreciated.

PS: Biggest weird thing I've found, its supposed to only be supported by Chrome version 67+. But go ahead and click on this link with any other mobile browser and it works. Just. Fine. ???

like image 125
cofuente Avatar answered Oct 22 '22 01:10

cofuente