英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论