Node.js SDK與Things Network的Lorawan Network Server(LNS)無縫集成,使開發人員可以輕鬆連接和管理IoT設備。通過廣泛的API支持,此軟件包簡化了與TTN的Lorawan生態系統的應用程序交互,從而啟用設備提供,數據傳輸和設備狀態監控。利用用戶友好的Node.js SDK來提高事物網絡的Lorawan基礎架構中的連接和數據管理。
該SDK還可以與“ The Things Industries”一起使用,並私有託管“ Things stack實例”。
準備開始使用SDK了嗎?讓我們開始吧!
文檔: ttn-node-sdk.fuota.io
github : the-things-network-nodejs-sdk
對於終端設備相關的方法:端迪維克
對於應用相關的方法:應用程序
對於網關相關方法:網關
對於用戶相關的方法:用戶
對於組織相關方法:組織
要在本地NPM上安裝最新版本,然後將其保存在軟件包的包裝中。
npm安裝the-things網絡 - 保存
安裝特定版本:
NPM安裝the-things-network@版本-Save
假設您要創建一個應用程序,可以為用戶和組織創建它...
有關更多信息,請參閱以下信息:為用戶創建應用程序
import { User } from 'the-things-network';
//just an example of config
const config = {
IDENTITY_SERVER: 'eu1.cloud.thethings.network',
NETWORK_SERVER: 'nam1.cloud.thethings.network',
APPLICATION_SERVER: 'nam1.cloud.thethings.network',
JOIN_SERVER: 'nam1.cloud.thethings.network',
API_KEY: 'xxxxxapi_keyxxxxxx',
};
//just an example of payload
const payload = {
application_id: 'test',
name: 'demo',
description: 'for testing',
};
const user = User('userId', config);
const result = async () => {
try {
const resp = await user.createApplication(payload);
console.log(resp);
} catch (err) {
console.log(err);
}
}
result();
有關更多信息,請參閱以下信息:為組織創建應用程序
import { Organization } from 'the-things-network';
//just an example of config
const config = {
IDENTITY_SERVER: 'eu1.cloud.thethings.network',
NETWORK_SERVER: 'nam1.cloud.thethings.network',
APPLICATION_SERVER: 'nam1.cloud.thethings.network',
JOIN_SERVER: 'nam1.cloud.thethings.network',
API_KEY: 'xxxxxapi_keyxxxxxx',
};
//just an example of payload
const payload = {
application_id: 'test',
name: 'demo',
description: 'for testing',
};
const org = new Organization('organizationId', config);
const result = async () => {
try {
const resp = await org.createApplication(payload);
console.log(resp);
} catch (err) {
console.log(err);
}
}
result();
import { Application } from 'the-things-network';
//just an example of config
const config = {
IDENTITY_SERVER: 'eu1.cloud.thethings.network',
NETWORK_SERVER: 'nam1.cloud.thethings.network',
APPLICATION_SERVER: 'nam1.cloud.thethings.network',
JOIN_SERVER: 'nam1.cloud.thethings.network',
API_KEY: 'xxxxxapi_keyxxxxxx',
};
const app = new Application('', config);
const result = async () => {
try {
const resp = await app.getApplicationList();
console.log(resp);
} catch (err) {
console.log(err);
}
}
result();
import { EndDevice } from 'the-things-network';
//just an example of config
const config = {
IDENTITY_SERVER: 'eu1.cloud.thethings.network',
NETWORK_SERVER: 'nam1.cloud.thethings.network',
APPLICATION_SERVER: 'nam1.cloud.thethings.network',
JOIN_SERVER: 'nam1.cloud.thethings.network',
API_KEY: 'xxxxxapi_keyxxxxxx',
};
//just an example of payload
const payload = {
end_device: {
ids: {
join_eui: 'DDFFDDFDFFDFDFDF',
dev_eui: '70B3D57ED005B59E',
device_id: 'eui-70b3d57ed005b59e',
application_ids: {
application_id: 'appId',
},
},
version_ids: {
brand_id: 'moko',
model_id: 'lw003',
hardware_version: '2.1',
firmware_version: '2.0',
band_id: 'AS_923',
},
network_server_address: 'nam1.cloud.thethings.network',
application_server_address: 'nam1.cloud.thethings.network',
join_server_address: 'nam1.cloud.thethings.network',
},
};
const device = new EndDevice('appId', config);
const result = async () => {
try {
const resp = await device.createEndDeviceIS(payload);
console.log(resp);
} catch (err) {
console.log(err);
}
}
result();
import { User } from 'the-things-network';
//just an example of config
const config = {
IDENTITY_SERVER: 'eu1.cloud.thethings.network',
NETWORK_SERVER: 'nam1.cloud.thethings.network',
APPLICATION_SERVER: 'nam1.cloud.thethings.network',
JOIN_SERVER: 'nam1.cloud.thethings.network',
API_KEY: 'xxxxxapi_keyxxxxxx',
};
//just an example of payload
const payload = {
gateway: {
ids: { gateway_id: 'eui-ee34634e6ada3425', eui: 'EE34634E6ADA3425' },
name: 'gateway',
description: 'testing',
gateway_server_address: 'nam1.cloud.thethings.network',
frequency_plan_id: 'US_902_928_FSB_3',
status_public: true,
location_public: true,
enforce_duty_cycle: true,
schedule_anytime_delay: '0.530s',
require_authenticated_connection: true,
},
};
const gateway = new User('userId', config);
const result = async () => {
try {
const resp = await gateway.createGateway(payload);
console.log(resp);
} catch (err) {
console.log(err);
}
}
result();
import { EndDevice } from 'the-things-network';
//just an example of config
const config = {
IDENTITY_SERVER: 'eu1.cloud.thethings.network',
NETWORK_SERVER: 'nam1.cloud.thethings.network',
APPLICATION_SERVER: 'nam1.cloud.thethings.network',
JOIN_SERVER: 'nam1.cloud.thethings.network',
API_KEY: 'xxxxxapi_keyxxxxxx',
TENANT_ID: 'xxxxxxxxxx',
};
//just an example of payload
const payload = {
device_id: 'deviceId',
down_type: '#',
host: 'nam1.cloud.thethings.industries',
port: 1883,
username: 'user@tenant',
callback_uplink_event: (data) => {
console.log('upEvent', data.toString('utf8'));
},
callback_subscribe_error: (data) => {
console.log('upEvent', data.toString('utf8'));
},
callback_subscribe_disconnect: (data) => {
console.log('upEvent', data.toString('utf8'));
}
};
const device = new EndDevice('appId', config);
const result = async () => {
try {
const resp = await device.subscribeUpLinkEvent(payload);
console.log(resp);
} catch (err) {
console.log(err);
}
}
result();
import { EndDevice } from 'the-things-network';
//just an example of config
const config = {
IDENTITY_SERVER: 'eu1.cloud.thethings.network',
NETWORK_SERVER: 'nam1.cloud.thethings.network',
APPLICATION_SERVER: 'nam1.cloud.thethings.network',
JOIN_SERVER: 'nam1.cloud.thethings.network',
API_KEY: 'xxxxxapi_keyxxxxxx',
TENANT_ID: 'xxxxxxxxxx',
};
//just an example of payload
const payload = {
device_id: 'deviceId',
down_type: '#',
host: 'nam1.cloud.thethings.industries',
port: 1883,
username: 'user@example',
callback_uplink_event: (data) => {
console.log('upEvent', data.toString('utf8'));
},
callback_subscribe_error: (data) => {
console.log('upEvent', data.toString('utf8'));
},
callback_subscribe_disconnect: (data) => {
console.log('upEvent', data.toString('utf8'));
}
};
const device = new EndDevice('appId', config);
const result = async () => {
try {
const upevent = await device.subscribeUpLinkEvent(payload);
console.log(upevent);
const resp = await device.unsubscribeEvent(upevent.client, upevent.topic);
console.log(resp);
} catch (err) {
console.log(err);
}
}
result();
創建特定類的實例並設置所需的參數後,您可以探索所有屬於該類的方法,這很容易...
import { Application } from 'the-things-network';
//just an example of config
const config = {
IDENTITY_SERVER: 'eu1.cloud.thethings.network',
NETWORK_SERVER: 'nam1.cloud.thethings.network',
APPLICATION_SERVER: 'nam1.cloud.thethings.network',
JOIN_SERVER: 'nam1.cloud.thethings.network',
API_KEY: 'xxxxxapi_keyxxxxxx',
};
//just an example of payload
const payload = {
name: 'test',
description: 'For testing',
attributes: { 'key1': 'value1', 'key2': 'value2' },
};
const app = new Application('appId', config);
const result = async () => {
try {
const resp1 = await app.getApplicationList();
console.log(resp1);
const resp2 = await app.updateApplication(payload);
console.log(resp2);
const resp3 = await app.deleteApplication();
console.log(resp3);
const resp4 = await app.restoreApplication();
console.log(resp4);
} catch (err) {
console.log(err);
}
}
result();
我們歡迎對The-Things網絡的貢獻!如果您有興趣為此軟件包做出貢獻,則有很多方法可以與The-Things網絡聯繫在一起:
報告問題:如果您發現任何錯誤,錯誤或增強功能,請隨時在GitHub上打開問題。
提交拉請請求:如果您可以自己解決問題或想添加新功能,我們很樂意查看您的拉請請求。
改進文檔:無論您找到了錯字,不清楚的文檔,還是您有改進我們的文檔的想法,我們都希望收到您的來信!
分享反饋:關於您對我們的包裝的經驗的任何反饋將不勝感激。您的輸入有助於我們為每個人提供更好的包裹。
請注意,該項目已使用貢獻者的行為準則發布。通過參加該項目,您同意遵守其條款。
我們期待與您合作!
fuota.io
該SDK由@fuota.io團隊維護
fuota.io是使用Things Network和許多其他受歡迎的Lorawan Network服務器的Lorawan設備輕鬆固件更新和全面設備管理的多合一平台。
在連接設備的快速發展的景觀中,保持設備最新的最新固件是最佳性能,增強安全性和功能豐富功能的關鍵因素。因此,如果您正在尋找現成的解決方案,以進行固件更新部署解決方案。加入我們的fuota.io,並解鎖您連接的Lorawan設備的全部潛力,使其保持更新,安全和無縫集成。
訪問我們: fuota.io
麻省理工學院