Code Monkey home page Code Monkey logo

ros_azure_iothub's Introduction

Azure IoT Hub for ROS

This ROS package works with the Microsoft Azure IoT Hub service to relay telemetry messages from the Robot to Azure IoT Hub or reflect properties from the Digital Twin to the robot using dynamic reconfigure.

Prerequisites

To use this ROS node on your Robot, you will need:

How to Build (ROS on Windows)

Here is an example how to build it for ROS on Windows.

:: source ROS environment
c:\opt\ros\noetic\x64\setup.bat

:: create catkin workspace folders
mkdir catkin_ws\src
pushd catkin_ws

:: checkout required ROS package sources
pushd src
git clone https://github.com/ms-iot/abseil-cpp -b init_windows
git clone https://github.com/facontidavide/ros_type_introspection
git clone -b noetic-devel --recursive https://github.com/Microsoft/ros_azure_iothub
popd

:: install system dependencies
rosdep update
rosdep install --from-paths src --ignore-src -r -y

:: build it and source install environment
catkin_make_isolated --only-pkg-with-deps roscpp_azure_iothub --install
install_isolated\setup.bat

How to Build (Ubuntu Linux install)

Here is an example how to build it for Ubuntu ROS Linux install.

# source ROS environment
source /opt/ros/melodic/setup.bash

# create catkin workspace folders
mkdir catkin_ws/src -p
pushd catkin_ws
catkin_init_workspace src

# checkout required ROS package sources
pushd src
git clone --recursive https://github.com/Microsoft/ros_azure_iothub
popd

# install Azure IoT SDK as Debian
sudo add-apt-repository ppa:aziotsdklinux/ppa-azureiot

# update apt to refresh package registries
sudo apt update
sudo apt install -y azure-iot-sdk-c-dev

# install system dependencies
rosdep update
rosdep install --from-paths src --ignore-src -r -y

# build it and source install environment
chmod a+x src/ros_azure_iothub/dynamic_tutorials/cfg/tutorials.cfg
catkin_make install
source /install/setup.bash

Deployment (IoT Hub for telemetry reporting or reported properties channel)

Azure IoT Hub maintains a device twin for each device that you connect to IoT Hub. Device twins are JSON documents that store device state information including metadata, configurations, and conditions. We are using desired properties as a channel to ask our ROS node what ROS topics to report. The messages received from these ROS topics can either be reported through the telemetry channel or through the reported property channel on the device twin. The telemetry channel is designed for high bandwidth data and the history of messages sent over this channel are stored. The reported property channel is designed for low bandwidth data and it advertises only the latest message for each topic the device twin subscribes to.

Here is a JSON example to report /rosout via telemetry and /initialpose via reported properties:

{
    "deviceId": "devA",
    "properties": {
        "desired": {
            "ros_relays": {
                "1": {
                    "topic": "/rosout",
                    "relay_method": "telemetry"
                },
                "2": {
                    "topic": "/initialpose",
                    "relay_method": "reported"
                }
            }
        }
    }
}

Add the ros_relays block to the device twin. Use the client side deployment step to connect to your device. You can run the following Azure PowerShell cmdlet to wait for events from IoT Hub.

az iot hub monitor-events --hub-name <YourIoTHubName> --output table

Step by step tutorial: Viewing messages through the reported properties channel

Step 1:

Create a new device twin on the Azure Portal and copy the connection string.

create device

Step 2:

Populate the device twin with the desired properties tag, adding in the topics you want to subscribe to and the method with which you wish to receive the published messages. In this example, we are subscribing to the /hello topic and we will receive the messages through the reported properties channel.

desired properties

Step 4:

Locally, deploy any ROS nodes you wish. As an example we will be publishing to the topic /hello as the device twin will be subscribing to it.

publish topic

Step 5:

Launch the Azure Iot Hub ROS node and provide the connection string you just copied.

launch node

Step 6:

Back in the Azure portal your device twin should be updated with the latest published messages for each topic it is subscribed to.

Deployment (IoT Hub for dynamic configuration)

Dynamic Reconfiguration provides a way to change the node parameters during runtime without restarting the node. Similar as the telemetry reporting, we are using the device twin desired properties as a channel to ask our ROS node what dynamic parameters to reconfigure.

Here is a JSON example to reconfigure the parameters of /dynamic_tutorials_node with the new value:

{
    "deviceId": "devA",
    "properties": {
        "desired": {
            "ros_dynamic_configurations": {
                "0": {
                        "node": "/dynamic_tutorials_node", 
                        "param": "str_param",
                        "type":  "string",
                        "value": "HelloWorld!"
                },
                "1": {
                        "node": "/dynamic_tutorials_node",
                        "param": "int_param",
                        "type":  "int",
                        "value": "33"
                     },
                "2": {
                        "node": "/dynamic_tutorials_node",
                        "param": "double_param",
                        "type":  "double",
                        "value": "0.55"
                     },
                "3": {
                        "node": "/dynamic_tutorials_node",
                        "param": "bool_param",
                        "type":  "bool",
                        "value": "1"
                     }
        }
    }
}

Currently 4 types of parameters can be dynamically reconfigured, they are "string", "int", "double" and "bool".

Deployment (Client side)

This node can be run using roslaunch (replacing the value for connection_string with the value given by Azure IoT Hub):

roslaunch roscpp_azure_iothub sample.launch connection_string:="HostName=sample.azure-devices.net;DeviceId=rosbot;SharedAccessKey=sampleKey"

This value can also be set in the ROS Parameter Server at /roscpp_azure_iothub_node/connection_string.

Now you can run some other ROS scenarios and see the /rosout being reported back to IoT Hub or the node parameters being dynamically reconfigured.

X.509 Certificate Authentication

By default, the ROS node will use SAS (Shared Access Signatures) to communicate with IoT Hub. Follow the instructions below to use X.509 certificates instead.

First, set up X.509 security in your Azure IoT hub. Complete the steps until you reach "Authenticate your X.509 device with the X.509 certificates". Instead, the ROS node will be used to connect using the X.509 certificates.

After successfully creating, generating or puchasing the X.509 certificates, you should have a public key/certificate and a private key. If the keys were created for test purposes using these instructions, they should be stored in two files:myDevice-private.pem and myDevice-public.pem

Set the DEVICE_PRIVATE_KEY and DEVICE_PUBLIC_KEY environment variables to the full file name for the X.509 keys. For example, on Windows run (replacing 'myCertPath/myDevice' with the path and file name):

set DEVICE_PRIVATE_KEY="C:/myCertPath/myDevice-private.pem"
set DEVICE_PUBLIC_KEY="C:/myCertPath/myDevice-public.pem"

To deploy, run the following. (replacing the value for connection_string with the value given by Azure IoT Hub)

::Launch the node using the X.509 sample launch file
roslaunch roscpp_azure_iothub sample_x509.launch  connection_string:="HostName=
HostName=sample.azure-devices.net;DeviceId=x509ca-test2;x509=true"

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

ros_azure_iothub's People

Contributors

amelhassan avatar anthturner avatar jiabaoxi avatar jsimard-cegeptr avatar kartben avatar lilustga avatar microsoft-github-policy-service[bot] avatar microsoftopensource avatar msftgits avatar ooeygui avatar pranavdhulipala avatar seanyen avatar vtam-msft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ros_azure_iothub's Issues

Package not building for ROS noetic in Ubuntu 20.04

Hi all,

I'd love to use this package to send some telemetry data but I'm not able to build it. I've tried following the instructions and tips I saw in other issues (e.g. #36 ).

Simply following the instructions on the Readme will not work. For starters, sudo add-apt-repository ppa:aziotsdklinux/ppa-azureiot there is no release version for Ubuntu 20.04. Also it looks like it depends on parsons and for some reason it was removed on noetic-devel branch #34 . Below I'll list the steps that I took and also a file with the output of catkin_make.

First I downloaded and installed azure-iot-sdk-c following this instructions

git clone https://github.com/Azure/azure-iot-sdk-c.git
cd azure-iot-sdk-c/
git submodule update --init
mkdir cmake
cd cmake
cmake -DCMAKE_INSTALL_PREFIX=/usr .. # installing it to /usr because CMakeLists will look there and not in the default install location /usr/local
cmake --build .
sudo make install

Then:

git clone --recursive https://github.com/Microsoft/ros_azure_iothub
git revert 264c73d # Reverted this commit so that I have parsons lib
rosdep update
rosdep install --from-paths src --ignore-src -r -y
catkin_make

I uploaded the output of catkin_make output_catkin_make.txt but basically it looks that there is a linker problem. All errors are of the kind:

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libhsm_security_client.a(hsm_client_tpm.c.o): in function `GetEkTemplate':
hsm_client_tpm.c:(.text+0xe): undefined reference to `ToTpmaObject'

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libhsm_security_client.a(hsm_client_tpm.c.o): in function `unmarshal_array':
hsm_client_tpm.c:(.text+0x1f3): undefined reference to `UINT32_Unmarshal'

I'd really appreciate it if someone could tell me how to fix it, or what other steps to follow,

Thanks,

Namespacing is not respected by rosparam loading

When using ROS_NAMESPACE option, the roslaunch rosparams are loaded into the correct namespace, but the rosparam config file for relays is loaded under the global namespace. This is an issue for needing to run multiple relay instances (such as one per device) on the same ROS master.

rospy_azure_iothub Demo on Windows 10 using Visual Studio Code

Hi,

I'm trying to make rospy_azure_iothub works using Visual Studio Code. Not able to launch, since not able to find rosbridge_library.

Traceback (most recent call last):
  File "D:\CATKIN_WORKSPACE\src\rospy_azure_iothub\ros_azure_iothub", line 63, in <module>
    from rosbridge_library.internal import message_conversion
ImportError: No module named rosbridge_library.internal 

Also tryied rosdep (rosdep install --from-paths src --ignore-src --rosdistro melodic -r -y), but without success too :

ERROR: the following packages/stacks could not have their rosdep keys resolved to system dependencies: rospy_azure_iothub: No definition of [rosbridge_library] for OS [windows]

I have installed both azure-iot-device and azure-iot-hub.

Is it supposed to work?

Thanks!

Connection Fails within ROS

Hello everyone,

we are trying to use this ROS Package to connect with our Azure IoT Hub. After starting the launch file, we receive the following error:

[ INFO] [1694792380.948178700]: Creating IoTHub Device handle
[ INFO] [1694792380.951205800]: connection_string: SetAnonymusByMyself
[ INFO] [1694792380.952589500]: Using Shared Access Signatures authentication.
Error: Time:Fri Sep 15 17:40:02 2023 File:D:\bld\azure-c-shared-utility\src\305becb8b4-13d51db0dd.clean\adapters\socketio_win32.c Func:connect_socket Line:190 Failure: connect failure 10060.
Error: Time:Fri Sep 15 17:40:02 2023 File:D:\bld\azure-c-shared-utility\src\305becb8b4-13d51db0dd.clean\adapters\socketio_win32.c Func:initiate_socket_connection Line:228 connect_socket failed
Error: Time:Fri Sep 15 17:40:02 2023 File:D:\bld\azure-c-shared-utility\src\305becb8b4-13d51db0dd.clean\adapters\socketio_win32.c Func:socketio_open Line:475 initiate_socket_connection failed
Error: Time:Fri Sep 15 17:40:02 2023 File:D:\bld\azure-umqtt-c\src\6589726cd0-9f313f3693.clean\src\mqtt_client.c Func:onOpenComplete Line:454 Error: failure opening connection to endpoint
Error: Time:Fri Sep 15 17:40:02 2023 File:D:\bld\azure-c-shared-utility\src\305becb8b4-13d51db0dd.clean\adapters\tlsio_schannel.c Func:tlsio_schannel_open Line:1238 xio_open failed
Error: Time:Fri Sep 15 17:40:02 2023 File:D:\bld\azure-umqtt-c\src\6589726cd0-9f313f3693.clean\src\mqtt_client.c Func:mqtt_client_connect Line:1042 Error: io_open failed
Error: Time:Fri Sep 15 17:40:02 2023 File:D:\bld\azure-iot-sdk-c\src\22e1b375fe-0b7b930b40.clean\iothub_client\src\iothubtransport_mqtt_common.c Func:SendMqttConnectMsg Line:2329 failure connecting to address facpremiumhub.azure-devices.net.
[ INFO] [1694792402.066324300]: The device client has been disconnected

Within /rosout, we receive the following message:


header:
seq: 87
stamp:
secs: 1694791855
nsecs: 961817300
frame_id: ''
level: 2
name: "/roscpp_azure_iothub_node"
msg: "The device client has been disconnected"
file: "C:\catkin_ws\src\ros_azure_iothub\roscpp_azure_iothub\src\ros_azure_iothub_cpp_node.cpp"
function: "__cdecl connection_status_callback"
line: 163
topics:

  • /rosout

I already changed the connection string to something completly random and afterwards, the connection error is something completly different. So I assume, that the connection string is correct. Could there be any problem, with some network settings?

Does anyone have an idea, where does that come from or what could be the issue?
Any help is highly appreciated. Thanks :)

Kindly regards

ROS Melodic How to monitor data on azure iot hub

I am using the melodic-devel branch for sending /rosout and /odom data to the azure iot hub. Now how could I read the data sent on IOT Hub. As shown in figure the configuration for azure iot hub device twin is mentioned.
image

As shown in the noetic branch I am not able to read the data in the reported properties.

linux build fails

catkin_make install

with this error

-- Could NOT find ros_type_introspection (missing: ros_type_introspection_DIR)
-- Could not find the required component 'ros_type_introspection'. The following CMake error indicates that you either need to install the package with the same name or change your environment so that it can be found.
CMake Error at /opt/ros/melodic/share/catkin/cmake/catkinConfig.cmake:83 (find_package):
Could not find a package configuration file provided by
"ros_type_introspection" with any of the following names:

ros_type_introspectionConfig.cmake
ros_type_introspection-config.cmake

after adding this foloowing error:

CMake Error at ros_azure_iothub/roscpp_azure_iothub/CMakeLists.txt:25 (find_package):
Could not find a package configuration file provided by "azure_iot_sdks"
with any of the following names:

azure_iot_sdksConfig.cmake
azure_iot_sdks-config.cmake

Add the installation prefix of "azure_iot_sdks" to CMAKE_PREFIX_PATH or set
"azure_iot_sdks_DIR" to a directory containing one of the above files. If
"azure_iot_sdks" provides a separate development package or SDK, be sure it

Could not resolve rosdep keys

Hi all,

I'm trying to follow in the installation for ROS foxy but run into an error while doing the rosdep install step.

I get this error:
roscpp_azure_iothub: cannot locate rosdep definition for [rosunit]

already tried a lot, like cloning the specific branch for foxy, looking into the package XML, etc. but nothing seems to solve the issue.

Any ideas?

Thanks

Install failing with ROS Melodic

Thank you for your interesting work!

I'm trying the How to Build (Ubuntu Linux Melodic install).

My environment is ubuntu18.04 on WSL2 and ROS Melodic.

I have an error when installing system dependencies like

$ rosdep install --from-paths src --ignore-src -r -y
ERROR: the following packages/stacks could not have their rosdep keys resolved
to system dependencies:
roscpp_azure_iothub: Cannot locate rosdep definition for [libazure-iot-sdk-c]
Continuing to install resolvable dependencies...
#All required rosdeps installed successfully

As a result, I failed to catkin_make

$ catkin_make install
Base path: /home/shmpwk/catkin_ws
Source space: /home/shmpwk/catkin_ws/src
Build space: /home/shmpwk/catkin_ws/build
Devel space: /home/shmpwk/catkin_ws/devel
Install space: /home/shmpwk/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/shmpwk/catkin_ws/build"
####
####
#### Running command: "make install -j8 -l8" in "/home/shmpwk/catkin_ws/build"
####
[ 20%] Built target dynamic_tutorials_gencfg
[ 40%] Building CXX object ros_azure_iothub/roscpp_azure_iothub/CMakeFiles/roscpp_azure_iothub_node.dir/src/ros_azure_iothub_cpp_node.cpp.o
Scanning dependencies of target dynamic_tutorials_node
[ 60%] Building CXX object ros_azure_iothub/dynamic_tutorials/CMakeFiles/dynamic_tutorials_node.dir/src/server.cpp.o
/home/shmpwk/catkin_ws/src/ros_azure_iothub/roscpp_azure_iothub/src/ros_azure_iothub_cpp_node.cpp:14:10: fatal error: azure_c_shared_utility/threadapi.h: No such file or directory
 #include <azure_c_shared_utility/threadapi.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
ros_azure_iothub/roscpp_azure_iothub/CMakeFiles/roscpp_azure_iothub_node.dir/build.make:62: recipe for target 'ros_azure_iothub/roscpp_azure_iothub/CMakeFiles/roscpp_azure_iothub_node.dir/src/ros_azure_iothub_cpp_node.cpp.o' failed
make[2]: *** [ros_azure_iothub/roscpp_azure_iothub/CMakeFiles/roscpp_azure_iothub_node.dir/src/ros_azure_iothub_cpp_node.cpp.o] Error 1
CMakeFiles/Makefile2:1350: recipe for target 'ros_azure_iothub/roscpp_azure_iothub/CMakeFiles/roscpp_azure_iothub_node.dir/all' failed
make[1]: *** [ros_azure_iothub/roscpp_azure_iothub/CMakeFiles/roscpp_azure_iothub_node.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 80%] Linking CXX executable /home/shmpwk/catkin_ws/devel/lib/dynamic_tutorials/dynamic_tutorials_node
[ 80%] Built target dynamic_tutorials_node
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make install -j8 -l8" failed

Relay should construct the topic message as a proper JSON string

Ideally the topic messages received by relay should be a proper JSON string.

For example, if the subscribed topic is /acml_pose, and then the message can be:

"/amcl_pose": {
  "amcl_pose": {
    "header": {
	  "seq": "placeholder",
	  "stamp": "placeholder",
	  "frame_id": "placeholder" 
	},
	"pose": {
	  "pose": {
	    "position": {
		  "x": "placeholder",
		  "y": "placeholder",
		  "z": "placeholder"
		},
        "orientation": {
		  "x": "placeholder",
		  "y": "placeholder",
		  "z": "placeholder",
		  "w": "placeholder"
		}
	  },
	  "covariance": ["placeholder"]
	}
  }
}

Here are existing implementations which does the JSON conversion:

Relay configuration is overwritten each run

Each time the node is run, the persisted relays file is overwritten with an empty array. It looks like the self._relays is never populated, but it is used to save and dump to the file each time save_relays is called.

I am planning to make a PR on this soon.

Support to use the node under ROS Melodic

I was able to install the package, but I really can't understand how to use this node!

When I launch the sample.launch, I get:
setting /run_id to 5147197a-ad11-11eb-b370-001ee5df51a0
process[rosout-1]: started with pid [25615]
started core service [/rosout]
process[roscpp_azure_iothub_node-2]: started with pid [25618]
[ INFO] [1620157546.523456436]: Creating IoTHub Device handle
[ INFO] [1620157546.524714272]: connection_string: HostName=xxxxxxxx
[ INFO] [1620157546.525063374]: authentication_type:
[ INFO] [1620157546.525165938]: Using Shared Access Signatures authentication.
[ INFO] [1620157546.756376459]: The device client is connected to iothub

and nothing else happens.
How can I specify the topic that I want to send to my HUB?
There is nothing in the README file about that so I cannot understand how to proceed.

Can you please provide some instructions on how to use this node?

Thank you!
P.S. I use Ubuntu 18.04 and ROS Melodic

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.