Child pages
  • Python SDK for Labeeb IoT Devices

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Getting started with Python SDK for Labeeb IoT Devices


The main purpose of this SDK is to provide the simplest way to connect your device to Labeeb IoT Platform.With this Python SDK ,connecting to Labeeb will be simply functions calls. 

What can be done with Labeeb IoT Python SDK for devices


Using this SDK ,you will be able to communicate and publish data to LAbeeb IoT through MQTT , COAP protocols ,or booth at the same time!     

  1. MQTT connectivity : 

    1. Client initialization : where you can specify the server address and access credentials.

    2. Connect to Labeeb IoT server: where you can establish the connection with Labeeb IoT.

    3. Publish data to Labeeb IoT platform: where you can send your data to Labeeb IoT. 

    4. Close the MQTT connection: to close the connection,when you finish sending you data.

  2. CoAP protocol : 

    1. Client initialization: where you can specify the server address and access credentials.

    2. Put data to Labeeb IoT: where you can send your data to Labeeb IoT. 

    3. Close the connection: to close the connection,when you finish sending you data. 

SDK download and import : 

 

Tip
titlePre-Requirement

Before you start using this SDK you need to install :

1)Download SDK rar file , you can find it here( python_SDK.rar ) .

2) extract compressed file and execute the following command to run (python_sdk_install.sh ) script , it's inside SDK folder. that will automatically install required dependencies :

Code Block
languagebash
titledependencies install
./SDK/python_sdk_install.sh

 *you may be asked to enter root password.

  1. SDK files :  

    Extract the compressed file, you will find a folder called SDK, create new empty .py file inside it,for example  : (PushToLAbeeb.py).

  2. Importing the SDK : 

    Start the code by importing the python library , use the following line :

    Code Block
    languagepy
    themeEclipse
    firstline1
    titleProgram Language Code 1
    linenumberstrue
    import labeebDevice


  3.  Creat an object instance from labeebDevice , like : 

    Code Block
    languagepy
    themeEclipse
    firstline1
    titleProgram Language Code 1
    linenumberstrue
    connection = labeebDevice.labeebDevice()
    
    

     

     

Hands on Using the SDK to push data to Labeeb through MQTT 


 

  1. Initialize the MQTT connection :

    You need to have credentials so you can connect to Labeeb IoT , don't have ? Get one now!
    Use the following code line to connect : 

    Code Block
    languagepy
    themeEclipse
    firstline1
    titleProgram Language Code 1
    linenumberstrue
    connection.mqtt_client("demomea.labeeb-iot.com","enterprise","deviceUserName","devicePassword")


  2. Establish the connection: 

    Call mqtt_connect function to establish the connection with Labeeb IoT using the credentials provided in the Initialization step :

    Code Block
    languagepy
    themeEclipse
    firstline1
    titleProgram Language Code 1
    linenumberstrue
    connection.mqtt_connect()


  3. Put your data in (key:value)  pairs : 

    follow the format , you can add all your key:value pairs at the same object : 

    Code Block
    languagepy
    themeEclipse
    firstline1
    titleProgram Language Code 1
    linenumberstrue
    D = {'temp': "23","humidity" :"46"}


  4. Publish the data to a specific topic : 

    Use the topic of the device , data model name to publish data : 

    Code Block
    languagepy
    themeEclipse
    firstline1
    titleProgram Language Code 1
    linenumberstrue
    connection.mqtt_publish ("/topic/of/device/to/publish","DataModelName" , D )
    
    


  5. Publish a file to a specific topic : 

    Use the topic of the device,data model name to publish a file,the file will be converted to base64 encryption before publishing : 

    Code Block
    languagepy
    themeEclipse
    firstline1
    titleProgram Language Code 1
    linenumberstrue
    connection.mqtt_publish_file ("/topic/of/device/to/publish","DataModelName" , "FileName" )
    
    


  6. Close the the connection : 

    you can close the connection with Labeeb IoT by calling : 

    Code Block
    languagepy
    themeEclipse
    firstline1
    titleProgram Language Code 1
    linenumberstrue
    connection.mqtt_disconnect()
    
    


 

Hands on Using the SDK to push data to Labeeb through CoAP


  1. Initialize the CoAP connection :

    You need to have credentials so you can connect to Labeeb IoT , don't have ? Get one now!
    Use the following code line to connect : 

    Code Block
    languagepy
    themeEclipse
    firstline1
    titleProgram Language Code 1
    linenumberstrue
    connection.coap_client ("demo.labeeb-iot.com","enterprise","deviceUserName","device password")
    
    


  2. Put your data in (key:value)  pairs : 

    follow the format , you can add all your key:value pairs at the same object : 

    Code Block
    languagepy
    themeEclipse
    firstline1
    titleProgram Language Code 1
    linenumberstrue
    D = {'temp': "23","humidity" :"46"}


  3.  Put data to labeeb IoT :

    Use Template name ,Data Model name , Device name  to send data data over CoAP : 

    Code Block
    languagepy
    themeEclipse
    firstline1
    titleProgram Language Code 1
    linenumberstrue
    connection.coap_put ( "deviceTemplate","datamodel","deviceName",D)
    

     

     

What's next ?


After you push data to your Labeeb IoT account , now you can check the Data on the portal , retrieve it through our  Labeeb IoT APIs and Web Services and then use this data in your mobile apps.Check one of our Getting Started.