Light Sensor Calibration - JRInge/Tasmota GitHub Wiki

I have fitted a Light Dependent Resistor (LDR) to the analogue input of a ESP8266 D1 Mini clone to act as a light sensor. This is supported by Tasmota, but needs calibration. I set up a web-based script to let me automatically take illuminance readings from the light sensor on a mobile phone and log the corresponding value from the ESP.

To make this work, the device loading the web page needs to support the W3C Generic Sensor APIs, have them enabled in the browser, and potentially also get permission from the user. Google Chrome supports the APIs, but currently (v99) needs them to be manually enabled via chrome://flags. The APIs also require a secure browsing context, so have to be loaded over HTTPS rather than HTTP.

On the Tasmota side, the device has to have Cross-Origin-Scripting (CORS) enabled, to allow a remote web-page to request data. Again, this is supported by Tasmota, but needs to be enabled at compile-time via #define USE_CORS. Note that CORS is a security risk and should probably only be enabled temporarily, as it makes it easier for malicious websites to control your local devices. See this pull request for details. Once CORS is compiled in to Tasmota, it can be enabled with the command CORS * and disabled with CORS 0.

References: