0
# LoRa Device Management
1
2
LoRa device management and frequency plan configuration for Low Power Wide Area Network (LPWAN) IoT deployments. Arduino IoT Cloud provides specialized APIs for managing LoRaWAN devices and their frequency plans.
3
4
## Capabilities
5
6
### LoRa Device Operations
7
8
Create and manage LoRaWAN devices with specialized configuration parameters.
9
10
```javascript { .api }
11
class LoraDevicesV1Api {
12
/**
13
* Create a new LoRa device with LoRaWAN-specific configuration
14
* @param createLoraDevicesV1Payload - LoRa device creation parameters including device EUI and keys
15
* @param opts - Optional parameters including organization ID
16
* @returns Promise<ArduinoLoradevicev1> - Created LoRa device object
17
*/
18
loraDevicesV1Create(createLoraDevicesV1Payload: CreateLoraDevicesV1Payload, opts?: any): Promise<ArduinoLoradevicev1>;
19
}
20
```
21
22
### LoRa Frequency Plan Management
23
24
Manage available LoRa frequency plans for different regions and regulatory requirements.
25
26
```javascript { .api }
27
class LoraFreqPlanV1Api {
28
/**
29
* List all available LoRa frequency plans for device configuration
30
* @param opts - Optional parameters including organization ID and region filtering
31
* @returns Promise<ArduinoLorafreqplansv1> - Collection of available frequency plans
32
*/
33
loraFreqPlanV1List(opts?: any): Promise<ArduinoLorafreqplansv1>;
34
}
35
```
36
37
## Data Models
38
39
```javascript { .api }
40
interface ArduinoLoradevicev1 {
41
applicationEui?: string;
42
applicationKey?: string;
43
createdAt?: Date;
44
deviceEui?: string;
45
deviceId?: string;
46
frequencyPlan?: string;
47
href?: string;
48
id?: string;
49
name?: string;
50
organizationId?: string;
51
type?: string;
52
updatedAt?: Date;
53
userId?: string;
54
}
55
56
interface CreateLoraDevicesV1Payload {
57
applicationEui?: string;
58
applicationKey?: string;
59
deviceEui: string;
60
frequencyPlan: string;
61
name: string;
62
type?: string;
63
}
64
65
interface ArduinoLorafreqplansv1 {
66
freqPlans?: ArduinoLorafreqplanv1[];
67
}
68
69
interface ArduinoLorafreqplanv1 {
70
id?: string;
71
name?: string;
72
region?: string;
73
}
74
```
75
76
**LoRa Device Management Examples:**
77
78
```javascript
79
import ArduinoIotClient from '@arduino/arduino-iot-client';
80
81
const loraDevicesApi = new ArduinoIotClient.LoraDevicesV1Api();
82
const loraFreqPlanApi = new ArduinoIotClient.LoraFreqPlanV1Api();
83
84
// List available frequency plans
85
async function listFrequencyPlans() {
86
try {
87
const freqPlans = await loraFreqPlanApi.loraFreqPlanV1List();
88
89
console.log('Available LoRa Frequency Plans:');
90
freqPlans.freqPlans?.forEach(plan => {
91
console.log(`- ${plan.name} (${plan.region}): ${plan.id}`);
92
});
93
94
return freqPlans.freqPlans || [];
95
} catch (error) {
96
console.error('Failed to list frequency plans:', error);
97
throw error;
98
}
99
}
100
101
// Create a LoRa device
102
async function createLoRaDevice() {
103
try {
104
// First, get available frequency plans
105
const freqPlans = await listFrequencyPlans();
106
107
// Select appropriate frequency plan (e.g., EU868 for Europe)
108
const euFreqPlan = freqPlans.find(plan => plan.region === 'EU');
109
110
if (!euFreqPlan) {
111
throw new Error('EU frequency plan not available');
112
}
113
114
// Create LoRa device
115
const loraDevice = await loraDevicesApi.loraDevicesV1Create({
116
name: "Environmental Sensor LoRa Node",
117
deviceEui: "70B3D57ED005B4C8", // 8-byte device EUI in hex
118
applicationEui: "70B3D57ED005B4C0", // 8-byte application EUI in hex
119
applicationKey: "A665A45920422F9D417E4867EFDC4FB8B04A1F3FFF1FA07E998E86F7F7A27AE3", // 32-byte key
120
frequencyPlan: euFreqPlan.id,
121
type: "MKRWAN1310"
122
});
123
124
console.log(`Created LoRa device: ${loraDevice.id}`);
125
console.log(`Device EUI: ${loraDevice.deviceEui}`);
126
console.log(`Application EUI: ${loraDevice.applicationEui}`);
127
console.log(`Frequency Plan: ${loraDevice.frequencyPlan}`);
128
129
return loraDevice;
130
} catch (error) {
131
console.error('Failed to create LoRa device:', error);
132
throw error;
133
}
134
}
135
136
// Complete LoRa setup workflow
137
async function setupLoRaDeviceWorkflow() {
138
try {
139
console.log('Setting up LoRa device workflow...');
140
141
// 1. List available frequency plans for user selection
142
const freqPlans = await listFrequencyPlans();
143
console.log(`Found ${freqPlans.length} frequency plans`);
144
145
// 2. Create LoRa device with appropriate configuration
146
const device = await createLoRaDevice();
147
148
// 3. Device is now ready for LoRaWAN network joining
149
console.log('LoRa device setup completed successfully');
150
console.log('Next steps:');
151
console.log('1. Configure the physical device with the provided keys');
152
console.log('2. Power on the device to join the LoRaWAN network');
153
console.log('3. Monitor device connectivity in the Arduino IoT Cloud');
154
155
return device;
156
157
} catch (error) {
158
if (error.status === 400) {
159
console.error('Bad request - check device configuration parameters');
160
} else if (error.status === 409) {
161
console.error('Conflict - device EUI may already be registered');
162
} else {
163
console.error('LoRa setup error:', error.detail || error.message);
164
}
165
}
166
}
167
168
// Regional frequency plan selection helper
169
async function selectFrequencyPlanByRegion(region) {
170
try {
171
const freqPlans = await loraFreqPlanApi.loraFreqPlanV1List();
172
173
const regionalPlans = freqPlans.freqPlans?.filter(plan =>
174
plan.region?.toUpperCase() === region.toUpperCase()
175
) || [];
176
177
if (regionalPlans.length === 0) {
178
console.warn(`No frequency plans available for region: ${region}`);
179
return null;
180
}
181
182
console.log(`Available plans for ${region}:`);
183
regionalPlans.forEach(plan => {
184
console.log(`- ${plan.name}: ${plan.id}`);
185
});
186
187
return regionalPlans[0]; // Return first available plan for the region
188
} catch (error) {
189
console.error('Failed to select frequency plan:', error);
190
return null;
191
}
192
}
193
194
// Bulk LoRa device creation for fleet deployment
195
async function createLoRaDeviceFleet(deviceConfigs) {
196
try {
197
const createdDevices = [];
198
199
for (const config of deviceConfigs) {
200
try {
201
const device = await loraDevicesApi.loraDevicesV1Create({
202
name: config.name,
203
deviceEui: config.deviceEui,
204
applicationEui: config.applicationEui,
205
applicationKey: config.applicationKey,
206
frequencyPlan: config.frequencyPlan,
207
type: config.type || "MKRWAN1310"
208
});
209
210
createdDevices.push(device);
211
console.log(`✅ Created device: ${config.name} (${device.id})`);
212
} catch (error) {
213
console.error(`❌ Failed to create device: ${config.name} - ${error.message}`);
214
}
215
}
216
217
console.log(`Successfully created ${createdDevices.length}/${deviceConfigs.length} LoRa devices`);
218
return createdDevices;
219
220
} catch (error) {
221
console.error('Bulk LoRa device creation failed:', error);
222
throw error;
223
}
224
}
225
```