链链接功能能读取本地数据吗?

huangapple go评论46阅读模式
英文:

Can chainlink function read local data?

问题

我尝试使用Chainlink函数来获取本地数据,但出现了一个错误:"Error: Import of module node-dht-sensor not allowed"。我想知道Chainlink函数是否可以用于获取本地实时数据。

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)
英文:

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)

答案1

得分: 0

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.

英文:

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.

答案2

得分: 0

目前,您无法在Chainlink Functions中导入外部包。仅支持基本的Node.js功能,因此才会出现实际的编译错误。请查看https://docs.chain.link/chainlink-functions/resources/service-limits了解更多信息。

英文:

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.

huangapple
  • 本文由 发表于 2023年7月28日 01:14:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76782079.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定