# print_last_message_time(client) def usage(): print ( "Usage: iothub_client_sample.py -p <protocol> -c <connectionstring>" ) print ( " protocol : <amqp, amqp_ws, http, mqtt, mqtt_ws>" ) print ( " connectionstring: <HostName=<host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>>" ) print ( "\nPython %s" % sys.version ) print ( "IoT Hub Client for Python" ) try: (CONNECTION_STRING_WAREHOUSE, PROTOCOL) = get_iothub_opt(sys.argv[1:], CONNECTION_STRING_WAREHOUSE, PROTOCOL) (CONNECTION_STRING_ENVIRONMENT, PROTOCOL) = get_iothub_opt(sys.argv[1:], CONNECTION_STRING_ENVIRONMENT, PROTOCOL) (CONNECTION_STRING_INDUSTRIAL, PROTOCOL) = get_iothub_opt(sys.argv[1:], CONNECTION_STRING_INDUSTRIAL, PROTOCOL) (CONNECTION_STRING_AIR_COMPRESSOR, PROTOCOL) = get_iothub_opt(sys.argv[1:], CONNECTION_STRING_AIR_COMPRESSOR, PROTOCOL) except OptionError as option_error: print ( option_error ) usage() sys.exit(1) print ( "Starting the IoT Hub Python sample..." ) print ( " Protocol %s" % PROTOCOL ) # print ( " Connection string=%s" % CONNECTION_STRING ) main_loop()
print ( "IoTHubClient waiting for commands, press Ctrl-C to exit" ) status_counter = 0 while status_counter < 6: status = hub_manager.client.get_send_status() print ( "Send status: %s" % status ) time.sleep(10) status_counter += 1 except IoTHubError as iothub_error: print ( "Unexpected error %s from IoTHub" % iothub_error ) return except KeyboardInterrupt: print ( "IoTHubClient sample stopped" ) def usage(): print ( "Usage: iothub_client_sample_class.py -p <protocol> -c <connectionstring>" ) print ( " protocol : <amqp, http, mqtt>" ) print ( " connectionstring: <HostName=<host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>>" ) if __name__ == '__main__': try: (CONNECTION_STRING, PROTOCOL) = get_iothub_opt(sys.argv[1:], CONNECTION_STRING) except OptionError as option_error: print ( option_error ) usage() sys.exit(1) main(CONNECTION_STRING, PROTOCOL)
print ( "Unexpected error %s from IoTHub" % iothub_error ) return except KeyboardInterrupt: print ( "IoTHubClient sample stopped" ) print_last_message_time(client) def usage(): print ( "Usage: iothub_client_sample.py -p <protocol> -c <connectionstring>" ) print ( " protocol : <amqp, amqp_ws, http, mqtt, mqtt_ws>" ) print ( " connectionstring: <HostName=<host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>>" ) if __name__ == '__main__': print ( "\nPython %s" % sys.version ) print ( "IoT Hub Client for Python" ) try: (CONNECTION_STRING, PROTOCOL) = get_iothub_opt(sys.argv[1:], CONNECTION_STRING, PROTOCOL) except OptionError as option_error: print ( option_error ) usage() sys.exit(1) print ( "Starting the IoT Hub Python sample..." ) print ( " Protocol %s" % PROTOCOL ) print ( " Connection string=%s" % CONNECTION_STRING ) iothub_client_sample_run()