Open terrencebarr opened 1 week ago
Update: After updating nrfDevice.ts
in the following way
...
await apiConn
.get(`v1/devices/${deviceId}`)
.then(async (res: AxiosResponse) => {
if (res?.data?.tenantId === tenantId) {
log.success(
`confirmed that "${deviceId}" has been onboarded with account "${tenantId}"!`,
);
deviceAssociated = true;
// subscribe to c2d messages
const c2dtopic = `${mqttMessagesPrefix}d/${deviceId}/c2d/r`;
await device.subscribe(c2dtopic);
device.registerListener(c2dtopic, (message: { topic: string; payload: object}) =>
{
console.log(`listener called for ${message.topic}`);
});
...
the c2d listener is now called when c2d messages are published in the nRF Cloud.
May I suggest to update the repo to either:
or preferably
Thanks for the device-simulator-v2 in general, it's a great starting point!
Thanks, -- Terrence
Hi @terrencebarr! Thanks for your issue. We're glad you've gotten some benefit from our simulator. I have fixed the issue with https://github.com/nRFCloud/device-simulator-v2/pull/19/commits/22efd89b9fa51aecd115fd55181737ab57ec7e11. That PR is still in code review and testing, but feel free to try running the simulator using that branch. Please note, that PR is a major overhaul of simulator, so read the CLI options carefully, b/c things have changed.
Please don't hesitate to reach out with any suggestions for improvement, or questions. Thanks!
@savvyintegrations ok, will do, thanks!
Hi,
I am using the device simulator to send
d2c
messages to nRF Cloud and have added my own service type. Works fine.Now I am trying to receive
c2d
messages from nRF Cloud. According to the device simulatorREADME.md
, once the simulator displayssubscribed to "dev/<your_tenant_id>/<your_device_id>/jobs/rcv"
it should be "onboarded and ready to start sending and receiving device messages".However, receiving is not working for me, or maybe I am misunderstanding how it is supposed to work.
I am using the nRF Cloud API with curl to send messages to topic
d/<device_id>/c2d
as well asd/<device_id>/c2d/r
and I can verify that messages for thedevice_id
have been published in nRF Cloud by subscribing with a MQTT tool.I would expect the device simulator to subscribe to the
c2d
topic(s) and log these incoming messages via theclient.on('message', ...)
callback, but I don't see that happening.While investigating, I realized I am not seeing a subscription message for
c2d
topic(s) during the device simulator startup, so I added ac2d
topic in classNrfDevice.ts
, likebut the
c2d
topic is still not subscribed during device simulator startup.Is there an issue with the device simulator code with regard to receiving
c2d
messages? Or am I misunderstanding something?Thanks, -- Terrence