Methods and systems for detecting a gas or liquid in an environment include measuring a reference signal at each of a set of wavelengths by passing a signal at each wavelength through a reference cell having a gas or liquid to be detected. A sensing signal is measured at each of the plurality of wavelengths by coupling each wavelength to a ring resonator in the environment. A set of wavelengths that correspond to an absorption curve of the gas or liquid to be detected is determined. A concentration of the gas or liquid to be detected in the environment is determined based on amplitudes of the sensing signal at each of the set of wavelengths.