-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nrplus): trigger scan message periodically
- Loading branch information
1 parent
60e257c
commit eadeae7
Showing
4 changed files
with
106 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { IoTClient, ListThingsCommand } from '@aws-sdk/client-iot' | ||
import { | ||
IoTDataPlaneClient, | ||
PublishCommand, | ||
} from '@aws-sdk/client-iot-data-plane' | ||
|
||
const iot = new IoTClient({}) | ||
const iotData = new IoTDataPlaneClient({}) | ||
|
||
/** | ||
* Periodically trigger scan in sink to sync with relay, | ||
* required to communicate reliably with relay and relay-connected clients | ||
*/ | ||
export const handler = async (): Promise<void> => { | ||
const { things: gateways } = await iot.send( | ||
new ListThingsCommand({ | ||
thingTypeName: 'nrplus-gateway', | ||
}), | ||
) | ||
|
||
await Promise.all( | ||
(gateways ?? []).map(async ({ thingName }) => { | ||
const topic = `${thingName}/nrplus-ctrl` | ||
const payload = `dect beacon_scan -c 1667 -f -t 2` | ||
console.log(`>`, topic, JSON.stringify(payload)) | ||
return iotData.send( | ||
new PublishCommand({ | ||
topic, | ||
payload: Buffer.from(payload, 'hex'), | ||
qos: 1, | ||
}), | ||
) | ||
}), | ||
) | ||
} |