print ( "Unexpected error {0}".format(iothub_error) ) return except KeyboardInterrupt: print ( "" ) print ( "IoTHubDeviceMethod sample stopped" ) def usage(): print ( "Usage: iothub_devicemethod_sample.py -c <connectionstring> -d <device_id>" ) print ( " connectionstring: <HostName=<host_name>;SharedAccessKeyName=<SharedAccessKeyName>;SharedAccessKey=<SharedAccessKey>>" ) print ( " deviceid : <Existing device ID to call a method on>" ) if __name__ == '__main__': print ( "" ) print ( "Python {0}".format(sys.version) ) print ( "IoT Hub Service Client for Python" ) print ( "" ) try: (CONNECTION_STRING, DEVICE_ID) = get_iothub_opt(sys.argv[1:], CONNECTION_STRING, DEVICE_ID) except OptionError as option_error: print ( option_error ) usage() sys.exit(1) print ( "Starting the IoT Hub Service Client DeviceMethod Python sample..." ) print ( " Connection string = {0}".format(CONNECTION_STRING) ) print ( " Device ID = {0}".format(DEVICE_ID) ) iothub_devicemethod_sample_run()
print ( "Unexpected error {0}" % iothub_error ) return except KeyboardInterrupt: print ( "IoTHubMessaging sample stopped" ) def usage(): print ( "Usage: iothub_messaging_sample.py -c <connectionstring> -d <device_id>" ) print ( " connectionstring: <HostName=<host_name>;SharedAccessKeyName=<SharedAccessKeyName>;SharedAccessKey=<SharedAccessKey>>" ) print ( " deviceid : <Existing device ID to to send a message to>" ) if __name__ == '__main__': print ( "" ) print ( "Python {0}".format(sys.version) ) print ( "IoT Hub Service Client for Python" ) print ( "" ) try: (CONNECTION_STRING, DEVICE_ID) = get_iothub_opt(sys.argv[1:], CONNECTION_STRING, DEVICE_ID) except OptionError as option_error: print ( option_error ) usage() sys.exit(1) print ( "Starting the IoT Hub Service Client Messaging Python sample..." ) print ( " Connection string = {0}".format(CONNECTION_STRING) ) print ( " Device ID = {0}".format(DEVICE_ID) ) iothub_messaging_sample_run()