Skip to content

Commit 11083bf

Browse files
committed
feat(simulator): update shadow
1 parent b016f3d commit 11083bf

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

cli/commands/simulate-device.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ export const simulateDeviceCommand = ({
143143
reject(err)
144144
})
145145

146+
mqttClient.subscribe(`$aws/things/${deviceId}/shadow/update/rejected`)
147+
146148
const deltaTopic = `$aws/things/${deviceId}/shadow/update/delta`
147149
mqttClient.subscribe(deltaTopic)
148150
mqttClient.on('message', (topic, payload) => {
@@ -202,22 +204,44 @@ export const simulateDeviceCommand = ({
202204
ueMode: 2,
203205
cellID: 84187657,
204206
networkMode: 'LTE-M',
205-
eest: 8,
207+
eest: 5 + Math.floor(Math.random() * 5),
206208
},
207209
},
208210
}
209211

212+
const shadowUpdateTopic = `$aws/things/${deviceId}/shadow/update`
213+
210214
connection.onDelta((message) => {
211215
reported = merge(reported, message)
212-
connection.publish(`$aws/things/${deviceId}/shadow/update`, {
216+
connection.publish(shadowUpdateTopic, {
213217
state: { reported },
214218
})
215219
})
216220

217-
connection.publish(`$aws/things/${deviceId}/shadow/update`, {
221+
connection.publish(shadowUpdateTopic, {
218222
state: { reported },
219223
})
220224

225+
const eestReadings = dataGenerator({
226+
min: 5,
227+
max: 9,
228+
step: 1,
229+
})
230+
setInterval(() => {
231+
reported.device.networkInfo.eest = eestReadings.next().value
232+
connection.publish(shadowUpdateTopic, {
233+
state: {
234+
reported: {
235+
device: {
236+
networkInfo: {
237+
eest: reported.device.networkInfo.eest,
238+
},
239+
},
240+
},
241+
},
242+
})
243+
}, 60 * 1000)
244+
221245
// Publish location
222246
connection.publish(
223247
`${accountInfo.account.mqttTopicPrefix}m/d/${deviceId}/d2c`,

0 commit comments

Comments
 (0)