kmamykin / aws-mqtt

Serverless PubSub using AWS IoT message broker
MIT License
105 stars 30 forks source link

Error when publishing msg. #4

Open phongyu opened 7 years ago

phongyu commented 7 years ago

I just tried to send a simple msg to AWSIoT

const publish = AWSMqtt.publisher({ WebSocket: WebSocket, region: AWS.config.region, credentials: AWS.config.credentials, endpoint: 'xxxxxxxxx.iot.eu-west-1.amazonaws.com' })

publish('/myTopic', 'Hello World').then(() => console.log('Success'), console.error)

Error: MQTT went offline at Client. (/var/app/current/node_modules/aws-mqtt/lib/publisher.js:32:16) at Client.g (events.js:291:16) at emitNone (events.js:86:13) at Client.emit (events.js:185:7) at Client.MqttClient._setupReconnect (/var/app/current/node_modules/mqtt/lib/client.js:590:12) at emitOne (events.js:101:20) at Client.emit (events.js:188:7) at WebSocketStream.f (/var/app/current/node_modules/once/once.js:25:25) at emitOne (events.js:101:20) at WebSocketStream.emit (events.js:188:7)

Please advice me.

tqhoughton commented 7 years ago

I also have this issue

EDIT: I think it may be an issue with the publisher, because it worked fine when I used the normal AWSMqtt.connect() function. Also make sure that your message is in JSON! I forgot about that when I did my request and it didn't work (I also got no error messages).

kmamykin commented 6 years ago

Can anyone provide a minimum example that shows this problem?

garethmcc commented 6 years ago

Is this still an issue for you guys? I am currently struggling with this issue and all parameters seem to be correct as far as I can tell.

For my publisher I use AWS credentials created from the Access Key ID and Secret Access Key of a user that has worked in the past but currently refuses to connect.

AWS.config.region = 'eu-west-1';
      let credentials = new AWS.Credentials(process.env.AWS_ACCESS_KEY_ID, process.env.AWS_SECRET_ACCESS_KEY);
      AWS.config.credentials = credentials;

const publish = AWSMqtt.publisher({
        WebSocket: WebSocket,
        region: AWS.config.region,
        credentials: AWS.config.credentials,
        endpoint: "aruqcmgwyzan3.iot.eu-west-1.amazonaws.com"
      });
kmamykin commented 5 years ago

Just released 1.0.0 - could you please verify this version works for you?

Previously published version was broken due to dependencies (mqtt and aws-signature-v4) releases that broke this package. I now pinned those to the versions that I tested to work.