I am trying to achieve a simple task. I would like to send the temperature from sense hat to the IBM Watson and receive it back. I am able to send the temperature from the sense hat to the IBM Watson but I am unable to receive it back. Although it shows connected but the debug does not print anything. Let me know if I am missing something.
A Device connected to Watson IoT Platform is restricted in what topics it can publish and subscribe to.
The messages it sends to the platform are 'events' and must be published on an event topic of the form iot-2/evt/event_id/fmt/format_string.
It can also subscribe to 'commands' from the platform, using a command topic of the form iot-2/cmd/command_id/fmt/format_string.
This means a device cannot subscribe to its own events - it can only subscribe to its commands.
For more information about the MQTT connectivity for the platform, the documentation is here.
Related
I couldn't find any documents on how to connect to Google Cloud IoT MQTT bridge from Swift-based applications. Is it possible to connect? Any references or links or samples would be appreciated.
Edited answer responding to comment: To connect using the MQTT bridge to IoT Core, check out the code here.
We don't have an IOS/Swift code example there, but you should be able to see the various pieces you need from the Node or Python examples. The URL/endpoint for IoT Core is mqtt.googleapis.com:8883. The MQTT client's user/pass is going to be blank for the user (unused) and the encoded JWT for the password. The same code has what it looks like, and should be enough to get you started hopefully.
To communicate with IoT Core, the MQTT topics are devices/<device_id>/events/ for telemetry from device to Cloud, and if you want to report state of the device to be stored by IoT Core, it's devices/<device_id>/state/ and if you want to send messages from IoT Core back down to the device, it's either devices/<device_id>/config/ for persistent messages that will be delivered on connect if the device isn't actively connected, or devices/<device_id>/command/ if it's more of a fire and forget, lower latency type message.
Original answer: We don't have any documentation around this particular use case yet, but I found this:
https://github.com/emqtt/CocoaMQTT
Which enables MQTT client connections from IOS and is written in Swift, so that should work. In addition to this, you'll need a library to encode a JWT (Json Web Token) for the auth side of things.
Having said that, you could ditch MQTT entirely and just use the HTTP bridge in IoT Core, as that might be easier? You can see the docs for doing that here: https://cloud.google.com/iot/docs/how-tos/http-bridge. You'll still need the JWT piece for the auth, but it would keep you from having to implement MQTT in the app.
We are able to create device and gateway using Watson IOT platform service but there is no option to attach device under a gateway. We know there is an API to manually register device under the gateway . But is there a way to simulate auto register of a new device under the gateway in node red flow editor?
Also, need clarification on this,
1.Able to simulate event for device and gateway separately but is there a way to simulate event for a device which is attached to the gateway ? also how can we identify the event is from device or gateway.
2.How can simulate and differentiate QoS of messages published on a topic? I've set MQTT nodes with different priorities like 0,1,2 but unable to differentiate?
3.Can we publish commands to device or gateway using MQTT node? I read many tutorials they were using Watson IOT node.
I try to do the POC on IBM Watson IoT platform. I have followed the document in this link for creating the device simulator.
https://console.ng.bluemix.net/docs/services/IoT/nodereddevice_sample.html#devices
It can connect and send the MQTT message event to IoT platform but when I try to get the historical data from REST API, it always returns empty.
https://os9c6l.internetofthings.ibmcloud.com/api/v0002/historian
Not sure what when wrong.
Go to the IoT Watson IoT Platform dashboard connected to your BlueMix app, go to settings and there is a setting for Time Series DB which defaults to Off. When you turn it on you also get to choose the storage duration.
if the Time Series DB was off and the device was added, you might not be able to see it even if you set the historian on on. Try and re-add the device.
Came across the interesting service (Experimental) on Bluemix - Driver Behavior. Curious to know how it actually works, how does the data get to Bluemix from the car and is there a need to have an external app/device in the car to collect and post data to Bluemix something similar to Aviva's Rate my Drive app?
One simple example is to use IoT Platform and Node-RED to receive car probe data via MQTT and send the received data into Driver Behavior service in the Node-RED workflow. You can have MQTT client in each driver's smart phone.
I am not familiar with the Aviva's Rate my Drive app, but as far as I searched, you might be able to develop similar kind of application which can analyze driving behavior from car probe data with the Driver Behavior service.
For a Node-RED application, I am using MQTT to talk with the device. Do I need to use two "topics"?:
One topic for the device to publish information to be subscribed by the Node-Red application.
One topic for the Node-RED application to publish (and the device to subscribe to).
Alternatively, can both the device and Node-RED application post different information (both publishing and subscribing) to the same topic?
For example: If the device is both publishing temperature data and also subscribing to the same topic to get information from Node-RED in Bluemix, will that cause issues? There are two types of data I want to exchange:
The Device would be publishing temperatures.
The Node-RED application would be publishing "user request" information that would tell the device when to report temperatures.
You should use two different topics.
Applications (such as Node-RED) that connect to the IoT Foundation service publish commands to devices and subscribe to device events.
The device would subscribe to the command topic, and the application (Node-RED) to the event topic.
Your device will be publishing events – such as temperature. So the device should publish that event to a topic in the format iot-2/evt/event_id/fmt/format_string and your Node-RED application will be publishing a command to a different topic.
For example...
You could publish temperatures like this:
iot-2/evt/temperature/fmt/json { d: { temp: 25 } }
and publish commands to the device like this: iot-2/cmd/sendTemperature/fmt/json
The device would subscribe to the command topic, and the application (Node-RED) to the event topic. Specifically, when you are publishing events, you publish to topic iot-2/evt/event_id/fmt/format_string and devices subscribe to commands by subscribing to topic iot-2/cmd/command_id/fmt/format_string
See the online documentation for MQTT and IoT.