SlideServe
Menu
Préférences
© SlideServe · v2026

MQTT

nolan-house avatar
11 diapositives · 1.5K Views · Oct 29, 2014

MQTT. Documentation and Downloads. See: http://www.eclipse.org/paho/ Libraries for a variety of languages including: C++ Java JavaScript Python Go. General Flow. Create a client instance Connect to a broker using one of the connect*() functions

MQTT - slide 1
01 / 11MQTT
1 / 17

Télécharger la présentation

MQTT
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. MQTT

  2. Documentation and Downloads • See: http://www.eclipse.org/paho/ • Libraries for a variety of languages including: • C++ • Java • JavaScript • Python • Go

  3. General Flow • Create a client instance • Connect to a broker using one of the connect*() functions • Call one of the loop*() functions to maintain network traffic flow with the broker • Use subscribe() to subscribe to a topic and receive messages • Use publish() to publish messages to the broker • Use disconnect() to disconnect from the broker • Callbacks are called to allow the application to process events as necessary

  4. IoT-2 Details • Two types of clients • Devices • Send messages • Receive commands • Applications • Receive messages • Send commands

  5. Device Protocol DEVICE_TYPE = 'v' DEVICE_ORG = 'edg1f' IOT_SERVER = DEVICE_ORG + '.messaging.internetofthings.ibmcloud.com' IOT_PORT = 1883 deviceId = ‘LUCAS77’ device_username = "use-token-auth" device_password = ‘NML?jTHhmSGLlr58!u’ device_clientid = "d:" + DEVICE_ORG + ":"+DEVICE_TYPE+":" + deviceId; deviceClient = mqtt.Client(device_clientid, True) deviceClient.username_pw_set(device_username, device_password) # Publish string ############### telemetryTopic='iot-2/evt/telemetry/fmt/json'

  6. Device Message Handlers # mqtt client event handlers ############################ defdevice_on_publish(client, userdata, mid): print "device_on_publish has fired" print 'device_on_publish: Message ID: ' +str(mid) + ' has been published successfully' defdevice_on_connect(client, userdata, flags, rc): print 'device_on_connect has fired' print 'device_on_connect '+mqtt.connack_string(rc)+ '[message ID: '+str(rc)+']' if rc == 0: print 'Device Connection Success!' client.on_publish=device_on_publish print '---- .on_publish: ' + str(client.on_publish) defdevice_on_disconnect(client, userdata, rc): print "device_on_disconnect has fired" print 'device_on_disconnect: ' + mqtt.connack_string(rc) deviceClient.on_disconnect=device_on_disconnect deviceClient.on_connect=device_on_connect

  7. Device Connect and Publish # Connect the device client res = self.mqttclient.connect(IOT_SERVER, IOT_PORT) self.mqttclient.loop_start() # Publish a message to MQTT row=self.fileReader.next() data = self.cvt2json(row) response = self.mqttclient.publish(telemetryTopic,data)

  8. Application Protocol app_username ='a:edg1f:prizvzry3k' app_password='?OHZ6zc4K74)ReawyT' app_client_id = 'a:edg1f:tedstestapp1011' appClient = mqtt.Client(app_client_id, True) appClient.username_pw_set(app_username, app_password) #Subscribe propertyTopic='iot-2/type/v/id/+/evt/telemetry/fmt/json’

  9. App Message Handlers def app_on_message(client, userdata, message): print "app_on_message has fired" print 'app_on_message received an TOPIC: '+message.topic +' MESSAGE: ' + str(message.payload) #This is where we would call a processing routine to actually handle the message def app_on_connect(client, userdata, flags, rc): print 'app_on_connect has fired' print 'app_on_connect '+mqtt.connack_string(rc)+ '[message ID: '+str(rc)+']' if rc == 0: #client.on_message = app_on_message print '---- .message: ' + str(client.on_message) resp=client.subscribe(propertyTopic) print 'app_on-connect ' print 'app_on_connect.subscribe: ' + mqtt.error_string(resp[0]) print ’---- Message ID: ['+ str(resp[1])+']' def app_on_disconnect(client, userdata, rc): print "app_on_disconnect has fired" print 'app_on_disconnect: ' + mqtt.connack_string(rc) appClient.on_connect=app_on_connect appClient.on_disconnect=app_on_disconnect appClient.on_message=app_on_message

  10. App Connect & Loop self.mqttc.connect(IOT_SERVER, IOT_PORT) mqttc.loop_start()

  11. Tools Etc • Handy IoT test tool • http://mqtt-helper.mybluemix.net • IoT Cloud Dashboard • https://internetofthings.ibmcloud.com/dashboard • PAHO Getting started page • http://www.eclipse.org/paho/#getting-started • IoT documentation page (RESTful API) • https://developer.ibm.com/iot/recipes/api-documentation/ • NOT real time – historical data access only