Can chainlink function read local data?

49 Views Asked by At

I try to use chainlink function to retrieve local data, but got an error of "Error: Import of module node-dht-sensor not allowed" . I'd like to know whether Chainlink Function can be used to get local live data.

const sensor = require('node-dht-sensor');

const DHT_TYPE = 11;


const DHT_PIN = 4;

function readTemperature() {
  return new Promise((resolve, reject) => {
    sensor.read(DHT_TYPE, DHT_PIN, (err, temperature, humidity) => {
      if (err) {
        reject(err);
      } else {
        resolve({ temperature, humidity });
      }
    });
  });
}

const { temperature, humidity } = await readTemperature();


const roundedfootprint = Math.round(temperature)

return Functions.encodeUint256(roundedfootprint)
2

There are 2 best solutions below

0
On BEST ANSWER

Afaik, currently, Chainlink Functions do not support local live data. To achieve this, you need to update off-chain IoT data on a cloud-hosted database service, such as AWS IoT Core.

0
On

Currently, you can not import external packages with Chainlink Functions. Only vanilla Node.js features are supported, hence the actual compile error. Check https://docs.chain.link/chainlink-functions/resources/service-limits for more info.