コード例 #1
0
def iothub_client_sample_run():
    try:
        client = iothub_client_init()
        if client.protocol == IoTHubTransportProvider.MQTT:
            print ( "IoTHubClient is reporting state" )
            reported_state = "{\"newState\":\"standBy\"}"
            client.send_reported_state(reported_state, len(reported_state), send_reported_state_callback, SEND_REPORTED_STATE_CONTEXT)
            filename = "vidforblob159FirstRam.h264"
            f = open('/dp/log/firstFile.h264', "rb+")
            # f = open("C:/Users/cliff/OneDrive/pyProjects/feb28/bffl28.h264", "rb+")
            content = f.read()
            print("CONTENT LEN", len(content))
            client.upload_blob_async(filename,content, len(content), blob_upload_conf_callback,1001)
        while True:
            # send a few messages every minute
            print ( "IoTHubClient sending %d messages" % SEND_CALLBACKS )
            for message_counter in range(0, MESSAGE_COUNT):
                msg_txt_formatted = MSGLane4_TXT % message_counter
                message = IoTHubMessage((msg_txt_formatted))
                print(msg_txt_formatted, message)
                message.ContentEncoding = "utf-8"; 
                message.ContentType = "application/json"; 
                client.send_event_async(message, send_confirmation_callback, message_counter)
                print ( "IoTHubClient.send_event_async accepted message [%d] for transmission to IoT Hub." % message_counter )

            # Wait for Commands or exit
            print ( "IoTHubClient waiting for commands, press Ctrl-C to exit" )

            status_counter = 0
            while status_counter <= MESSAGE_COUNT:
                status = 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" )

    print_last_message_time(client)
コード例 #2
0
def iothub_client_sample_run():
   
    try:

        client = iothub_client_init()

        if client.protocol == IoTHubTransportProvider.MQTT:
            print ( "IoTHubClient is reporting state" )
            reported_state = "{\"newState\":\"standBy\"}"
            client.send_reported_state(reported_state, len(reported_state), send_reported_state_callback, SEND_REPORTED_STATE_CONTEXT)
            filename = "imageforblob159.jpg"
            f = open("/home/pi/Shared/videos/AAA/video5dFrame91.jpg", "rb+")
            content = f.read()
            print("CONTENT LEN", len(content))
            client.upload_blob_async(filename,content, len(content), blob_upload_conf_callback,1001)

        while True:
            # send a few messages every minute
            print ( "IoTHubClient sending %d messages" % SEND_CALLBACKS )

            for message_counter in range(0, MESSAGE_COUNT):
                # temperature = MIN_TEMPERATURE + (random.random() * 10)
                # humidity = MIN_HUMIDITY + (random.random() * 20)
                # msg_txt_formatted = MSG_TXT % (
                #     AVG_WIND_SPEED + (random.random() * 4 + 2),
                #     temperature,
                #     humidity)
                # # messages can be encoded as string or bytearray
                # if (message_counter & 1) == 1:
                #     message = IoTHubMessage(bytearray(msg_txt_formatted, 'utf8'))
                # else:
                #     message = IoTHubMessage(msg_txt_formatted)
                # # optional: assign ids
                # message.message_id = "message_%d" % message_counter
                # message.correlation_id = "correlation_%d" % message_counter
                # # optional: assign properties
                # prop_map = message.properties()
                # prop_map.add("temperatureAlert", 'true' if temperature > 28 else 'false')
        
                msg_txt_formatted = MSGLane4_TXT % MESSAGE_COUNT
                message = IoTHubMessage((msg_txt_formatted))
                message.ContentEncoding = "utf-8"; 
                message.ContentType = "application/json"; 
                client.send_event_async(message, send_confirmation_callback, message_counter)
                # client.upload_blob_async(filenamea,content, len(content), blob_upload_conf_callback,1001)
                print ( "IoTHubClient.send_event_async accepted message [%d] for transmission to IoT Hub." % message_counter )

            # Wait for Commands or exit
            print ( "IoTHubClient waiting for commands, press Ctrl-C to exit" )

            status_counter = 0
            while status_counter <= MESSAGE_COUNT:
                status = 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" )

    print_last_message_time(client)
コード例 #3
0
                # # optional: assign properties
                # prop_map = message.properties()
                # prop_map.add("temperatureAlert", 'true' if temperature > 28 else 'false')
<<<<<<< HEAD

                msg_txt_formatted = MSGLane4_TXT % (randint(0,1023))
                message = IoTHubMessage((msg_txt_formatted))

                client.send_event_async(message, send_confirmation_callback, message_counter)
                client.upload_blob_async(filenamea,content, len(content), blob_upload_conf_callback,1001)
=======
        
                msg_txt_formatted = MSGLane4_TXT % MESSAGE_COUNT
                message = IoTHubMessage((msg_txt_formatted))
                message.ContentEncoding = "utf-8"; 
                message.ContentType = "application/json"; 
                client.send_event_async(message, send_confirmation_callback, message_counter)
                # client.upload_blob_async(filenamea,content, len(content), blob_upload_conf_callback,1001)
>>>>>>> d3a9dd430d8bd214772ee110708226bd2f03c41b
                print ( "IoTHubClient.send_event_async accepted message [%d] for transmission to IoT Hub." % message_counter )

            # Wait for Commands or exit
            print ( "IoTHubClient waiting for commands, press Ctrl-C to exit" )

            status_counter = 0
            while status_counter <= MESSAGE_COUNT:
                status = client.get_send_status()
                print ( "Send status: %s" % status )
                time.sleep(10)
                status_counter += 1