I have an express endpoint that is intended to send a message down to my IoT device at the click of a button on the front-end. It works, but dies pretty quickly... the messages appear to be getting enqueued, but stop sending pretty quickly if I hit the button 5 or 6 times within 20 seconds or so. I sometimes get this error:MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 disconnect listeners added. Use emitter.setMaxListeners() to increase limit And sometimes this error:DeviceMaximumQueueDepthExceededError: AMQP transport: could not send message However, it usually just seems to fail silently. The messages usually (but not always) get through eventually, but sometimes significantly late. I'm looking for live control with hopefully immediate feedback. The IoT device seems to respond to commands just fine from the Azure portal's "Send message to device" feature.Here is the code, largely based on this: https://github.com/Azure/azure-iot-sdk-node/blob/master/service/samples/send_c2d_message.js ... that sample works fine for me, but I don't want to send messages on an interval, but rather from button press. For some reason stuffing it in an endpoint seems to have broken things.const express = require('express'); const app = express(); var Client = require('azure-iothub').Client; var Message = require('azure-iot-common').Message; var connectionString = ''my_connection_string"; var targetDevice = 'LTE-Dev1'; var serviceClient = Client.fromConnectionString(connectionString); app.post('/endpoint', function (req, res) { serviceClient.open(function (err) { if (err) { console.error('Could not connect: ' + err.message); } else { console.log('Client connected'); try { var message = new Message("hi"); message.ack = 'full'; message.messageId = "id"; console.log('Sending message: ' + message.getData()); serviceClient.send(targetDevice, message, printResultFor('send')); } catch (error) { console.log(error); } } }); }); Any ideas would be very welcome!
Submitted February 13, 2019 at 10:14PM by custardthegopher
No comments:
Post a Comment