Node red and mqtt on ibm cloud (bluemix)?

Is it possible to use node red and mqtt on a bluemix instance without using the ibm "Managed devices" framework/environment?

I am trying to set up a flow like this to send arbitraty messages but can't get the mqtt nodes to work. I think I am not understanding the URL security settings and several apikey/authtokens in IBM dashboards/app/services/connections.

[{"id":"6789aac7.ae4fb4","type":"inject","z":"fb19899.5845a78","name":"","topic":"hello","payload":"this is the msg","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":140,"wires":[["fb6272af.4b74c","a649b47d.668408"]]},{"id":"fb6272af.4b74c","type":"mqtt out","z":"fb19899.5845a78","name":"mqtt hello","topic":"hello","qos":"","retain":"","broker":"f98794d8.8d00c8","x":540,"y":140,"wires":[]},{"id":"eaca990c.d96658","type":"debug","z":"fb19899.5845a78","name":"Msg Received by MQTT Node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":430,"y":300,"wires":[]},{"id":"a649b47d.668408","type":"debug","z":"fb19899.5845a78","name":"Attempted Send to MQTT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":410,"y":220,"wires":[]},{"id":"768d5d50.a63994","type":"mqtt in","z":"fb19899.5845a78","name":"","topic":"hello/#","qos":"0","broker":"f98794d8.8d00c8","x":150,"y":280,"wires":[["eaca990c.d96658"]]},{"id":"f98794d8.8d00c8","type":"mqtt-broker","z":"","name":"MyMqtt","broker":"6ykzkv.messaging.internetofthings.ibmcloud.com","port":"8883","tls":"","clientid":"a:6ykzkv:1","usetls":true,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Almost all the docs I find talk about it from the "managed device" (IBM framework) perspective, so before I plow further into it, I'm asking if what I'm trying to do is even possible.

Thanks,
John

Are you asking if you can use NR & Bluemix with your own MQTT broker? If so, the answer is yes - that's what I'm doing using Mosquitto on my network. I assume your current code is using Watson IOT, which I have not used.

Thanks, but no, I am wanting to connect clients to the mqtt broker which is running on (my instance of) bluemix. (e.g. 6xyZzy.messaging.internetofthings.ibmcloud.com:1883 )
And then send/receive messages on arbitrary topics like topic="greet msg"="hello world" (NOT the IBM-device-managed format like topic="iot-2/type/myDeviceType/id/myDeviceID/cmd/command/fmt/text").

I will post also on developer.ibm.com...

No, you cannot use the IoT Platform as a generic mqtt broker. You need to register your devices and follow the topic name requirements of the platform.

Hmm, I was afraid of that. Thanks.

you can run your own broker of course - either via a separate machine - eg a softlayer instance - or inside Node-RED using https://www.npmjs.com/package/node-red-contrib-mqtt-broker - but you'll have to ensure you secure it yourself of course.

@michaelblight Can you tell me what IP address did you use to connect your NR to MQTT?
What I did was first use NR on my RasPI and then connect it to ESP32 to pass sensor data and control LED using my localhost IP.
Now, I copied the same flow onto my Bluemix Node-Red starter pack but my MQTT Broker fails to connect. Can you please help me?

If you're wanting to connect Bluemix to your local MQTT broker, it will need to be visible to the Internet and accessed via your public IP address. Tread carefully here, because you don't want to accidentally make your whole home network available to anybody on the Internet.

@michaelblight I had given the same IP address of my RasPI on which my MQTT Broker is installed. This previously worked when my NR was running on RasPI but I could not view sensor data without connecting to the same WiFi network. Now, when I tried using IBM cloud and uploading the same flow on NR, it fails to connect to the same MQTT Broker installed on my RasPI.
Security is not a concern for me as of yet, because I am uploading just sensor data (i.e. using DHT22).
I am aiming to create a webpage that I can share with anyone, and he/she can view the sensor data on their on device sitting at their home. Can you please guide me how could I do so?

@michaelblight Also for some reason I cannot install node-red-contrib-mqtt package on my Node-red-starter pack on IBM cloud. Is that might be the reason this connection fails?

Sorry, security is a concern as soon as you allow access from the internet onto any computer. After 20 seconds your computer will already have been scanned. You need to ensure you understand what you are doing (also the risks of doing this) and have secured the pi BEFORE you allow access from the internet to any machine.

But going back to your challenge...

You had the sensors connected to your local MQTT broker?
The sensors are on your local network?
You then want to view the sensor data outside of your network?
Where are you thinking of hosting the webpages to do this?

@ukmoose I am sorry, I never thought of security that way. I will definately look into it. As of the problems I am facing, my sensor (DHT22) is connected to ESP32 which has been given the MQTT Broker IP address installed on Raspberry Pi 3. These both are connected to the same WiFi network. If I run Node-red from my RasPI, it works fine and my MQTT Broker widget also connects on the MQTT Broker IP (192.168.137.130:1883) and then I can view my sensor data on 192.168.137.130:1883/ui.
Now, I tried running same flow on IBM cloud but my MQTT Broker fails to connect to the MQTT Broker running on RasPI. Can you please help me? Are there any other way I can provide others to view my sensor data without connecting to the same link? Any webpage I can use to show the sensor data online?

You could use Node-RED on your Pi to redirect data to IBM Cloud

So
[sensor]--[MQTT Broker]--[Node-red on Pi]--[IBM Cloud]

see https://developer.ibm.com/recipes/tutorials/simulating-a-device-and-publishing-034messages034-to-ibm-iot-platform-from-a-nodered-034watson-iot034-platform-node/

@ukmoose Thank you, I will look into it and get back to you asap!

@ukmoose Hey, thanks for the link. I tried running that and it worked fine. I wanted to ask you is there a way I can have GUI view for the sensors similar to one we get on node-red because using Watson IoT platform we get only sensor values as integer.
Here is an image of how my sensor data looks like, can you suggest any way I can view the same or similar GUI view for sensors without connecting to the same network?

57%20AM

Try googling “IBM cloud node-red” :upside_down_face:

@ukmoose Hey, I don't need to google about it cause I have already tried it. That was my very first query, as I was not able to connect my MQTT broker when using node-red on IBM cloud.
Can you help me with this or I need to google that too? Thanks anyway :thinking:

If you have data sending from your local devices to the Watson IoT platform, then you can run an instance of Node-RED in the IBM Cloud, connect it to the IoT platform and get your data.

The main issue all along has been where your broker is. If it is running on your local network, then applications running in the cloud cannot see it unless you open up your home network and take all the necessary security precautions.

If you run the broker in the cloud (or use a publicly hosted service like IBM IoT) then you can connect to it from both your home network and other applications running in the cloud.

There are lots of examples of running Node-RED in IBM Cloud here: https://developer.ibm.com/components/node-red/

Found on the front page of the search.

https://www.rs-online.com/designspark/put-your-thing-on-the-internet-using

@knolleary I tried finding a way to install mqtt broker on ibm cloud, but I have not found anything usable. Do you know some way I can install MQTT broker and run NR on IBM cloud? My MQTT broker fails to connect every time I deploy my flow.