Skip to Content
D J

Connection loop with MQTT

Hi, I have a problem with the connection of the MQTT Client to the SAP IoT cockpit broker in a secured environment. (node.js / mqtt Skript, see below)

At home it's working fine. But if I try the skript in the company environment it's stuck in a connection loop.

Client offline
Client close
Client reconnect
Client close
Client reconnect

How can I catch the error? We opend the MQTT TCP Port 8883 but was that even necessary?

example.js:

const mqtt = require("mqtt");
[...]
var connectOptions = {
  keepalive: 10,
  clientId: deviceAlternateId,
  clean: true,
  reconnectPeriod: 2000,
  connectTimeout: 2000,
  cert: fs.readFileSync(certFile),
  key: fs.readFileSync(certFile),
  passphrase: fs.readFileSync(secretPasswordFile).toString(),
  rejectUnauthorized: false
};

var Client = mqtt.connect("mqtts://<SAP-IoT AE Service>:8883", connectOptions);

Client.on("connect", function () {
  console.log("Client connect");
});

Client.on("error", function (err) {
  console.log("Client ERROR : ");
  console.log(err);
});

Client.on("offline", function () {
  console.log("Client offline");
});

Client.on("reconnect", function () {
  console.log("Client reconnect");
});

Client.on("close", function () {
  console.log("Client close");
});

[...]

Thank you for any help

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Oct 10, 2018 at 09:58 AM

    I suggest you add this tag: SAP Cloud Platform Internet of Things for the Cloud Foundry environment as this is about the device connectivity.

    I would guess that in your secured network the router might be configured to not let traffic on the port 8883 pass. Or you might have a proxy configured and the proxy does not let this traffic through. I suggest you check with the people who operate this secure network. Workaround 1 would be to use REST instead (especially for the blocked port). Workaround 2 is to use a mobile phone hotspot (if its just for demo or prototyping).

    At SAP our IT has setup additional network segments called SAP-Guest/SAP-Internet that allow a direct internet connection without proxy, do not allow reaching the Intranet and also allow ports required for MQTT. IoT devices are whitelisted based on their MAC address.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.