Giter Site home page Giter Site logo

ailuropoda0 / deviot_python_sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tingxin/deviot_python_sdk

0.0 1.0 0.0 17 KB

Quickly help user develop a DevIot Gateway

Home Page: https://developer.cisco.com/site/devnetlabs/deviot/

License: Other

Python 100.00%

deviot_python_sdk's Introduction

DevIoT Gateway Python SDK

THIS REPOSITORY IS DEPRECATED. THE NEW VERSION IS gateway-python-sdk.

This is DevIoT gateway service SDK and sample codes. You can use this SDK to register sensors to DevIoT, and sync up data and actions between the sensors and DevIoT.

You can try it from https://deviot.cisco.com/ quickly

Table of contents

What in this code

  1. DevIotGateway folder: The SDK python source code

  2. Sample_Code_for_GrovePi_Sensor.py : A simple sample to show how to use this SDK, which sync up grove light sensor data to DevIot, it also let DevIo trigger grove Led sensor

  3. Sample_Code_for_Simulated_Sensor.py: A simple sample to show how to use this SDK, which sync up some virtual sensor data to DevIot, it also let DevIot can trigger some virtual action sensor

Prerequisite

  1. Python 2.7:This SDK base on the Python 2.7.10

  2. paho-mqtt: this SDK use this to build a simple MQTT client

Usage:

  1. You can use sample code to register GrovePi sensors and simulated sensors to DevIoT.

  2. You can also use SDK to register other sensors and systems to DevIoT.

SDK API

Gateway

This class allow your instance a Gateway app, hepe you register sensors to DevIot, sync up data and action to DevIot.

Constructor

  • app name: the gateway name, DevIot use it differentiates gateways

  • deviot address: the address of DevIot, should include the port

  • mq server: gateway use mqtt protocol to communicate with DevIot, you can ask the your DevIot administrator to get it, it also should include the port

  • DevIot account: you DevIot account, you also can use empty string, it will let all account get the data of your gateway

      # the parameters are: app name, deviot address, mq server address, deviot account
      app = Gateway("grovepi_test", "10.140.92.25:9000", "10.140.92.25:1883", "[email protected]")
    

Register Data Sensors

  • sensor kind: the kind of sensor, it describes your sensor's function

  • sensor id: the unique id of sensor

  • sensor name: the display name in DevIot of the sensor

      # the parameters are: sensor kind, sensor id, sensor display name, action call back function
      app.register_action("led", "groveled", "GroveLed", trigger_grove_led)
    

Register Action Sensors

  • sensor kind: the kind of sensor, it describes your sensor's function

  • sensor id: the unique id of sensor

  • sensor name: the display name in DevIot of the sensor

  • action callback function: when DevIot trigger this action sensor, this function will be call

      # turn on/off the led when receive action from DevIot
      # action name will be 'on' or 'off'
      def trigger_grove_led(action):
          print('led get action:' + action.name)
          if action.name == 'on':
              grovepi.digitalWrite(led, 1)
          else:
              grovepi.digitalWrite(led, 0)
              
      # the parameters are: sensor kind, sensor id, sensor display name, action call back function
      app.register_action("led", "groveled", "GroveLed", trigger_grove_led)
    

Start the Gateway

    # run service
    app.run()

The run method will let gateway start a background thread to register sensors and sync up data and action

Update the Sensor Data

  • sensor id: the unique id of sensor

  • sensor value: the new value of data sensor

      app.set_value("grovelight", 50.0f)
    

How to run Sample_Code_for_GrovePi_Sensor.py

Build the hardware

1.Prepare your RaspberryPi os environment in your SD card

  • Download the OS for RaspberryPi form hereRASPBIAN JESSIE

  • Format you SD card

  • Use window install the OS image to the SD card. you can use Win32 Disk Manager do this I strongly recommend you do this use windows, i have met many issues when i installed it by mac os

  • Attach the SD card to the RaspberryPi

You also can do this follow here

2.Join the GrovePi with RaspberryPi. if you correct, it should be like this

3.Connect RaspberryPi with the power and network.

4.Connect RaspberryPi with Display use the HDMI cables.

Build the software environment

5.Install the Python 2.7. Check the python version of RaspberryPi os. this sample code base on python2.7.3 or later. in most time, the RaspberryPi os have installed the python2.7.3 or later, if not, you can install the python follow here

6.Install GrovePi SDK.

Your SD card now has what it needs to start using the GrovePi! Here is info more about install GrovePi SDK

Run Grove Pi sample

  • Cd to your work space in terminal window

  • Type follow command:

      python Sample_Code_for_GrovePi_Sensor.py
    

Getting help

If you have questions, concerns, bug reports, etc, please file an issue in this repository's Issue Tracker

Getting involved

For general instructions on how to contribute, please visit CONTRIBUTING

Open source licensing info

  1. LICENSE

Credits and references

None

deviot_python_sdk's People

Contributors

changjun-cisco avatar tingxin avatar tingxinxu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.