{ "info": { "author": "Philipp Steinr\u00f6tter", "author_email": "philipp.steinroetter@sap.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "**Table of Contents**\n\n- [Description](#description)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [How to obtain support](#how-to-obtain-support)\n- [License](#license)\n- [Usage](#usage)\n- [Test](#test)\n- [Build Docs](#build-docs)\n\n\n## Description\nThis package wraps the SAP IoT Services, Cloud Foundry Edition Device Management APIs as well as the REST and the MQTT Cloud Gateway APIs in easy-to-use Python code. You can find more information on the APIs [here](https://help.sap.com/viewer/643f531cbf50462c8cc45139ba2dd051/Cloud/en-US) and [here](https://help.sap.com/viewer/6040fec3f22e4f9b8bf495f3789d66b5/Cloud/en-US#).\n\nFeatures include:\n+ Wrapper around every functionality of the Device Management API\n+ Better error feedback\n+ Wrapper around both Cloud Gateways\n+ Both clients, REST and MQTT, are extended so that they work directly with the encrypted keys in the pem file\n+ Better error handling and error feedback for REST and MQTT\n + The MQTT client has an on_error and an on_command callback which directly return the parsed message\n + The REST client parses the error for batched and single uploads and throws an error with the respective message\n + Both clients return the failed message to enable the user to retry easily\n\n## Requirements\nYou will need an instance of IoT Services, Cloud Foundry to use this SDK. You can find more information on how to activate the service [here](https://cloudplatform.sap.com/capabilities/product-info.SAP-Cloud-Platform-Internet-of-Things.48b79cfa-3d49-4a42-9249-e589696691ae.html).\n\n## Installation\nThe package will be available at pip:\n\n`pip install iot-services-sdk`\n\nIf you want to download it manually, please make sure to install `paho-mqtt` and `requests` into your Python environment.\n\n## How to obtain support\nPlease use [GitHub Issues](https://github.com/SAP/iot-services-sdk/issues) to file a bug.\n\n## License\nCopyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved.\nThis file is licensed under the SAP Sample Code License except as noted otherwise in the [LICENSE file](LICENSE).\n\n## Usage\nPlease refer to the API documentation in the PDF file for details. You can check the tests for sample code.\n\nHere is a small example displaying the following functionality:\n\n+ Creating capabilities, a sensor type, a sensor and a device.\n+ Downloading the certificate and creating a MQTT client.\n+ Publishing valid and invalid measures as well as publishing and receiving commands.\n+ Deleting every entity which was created.\n\n```python\nimport os\n\nfrom iot_services_sdk import CapabilityService\nfrom iot_services_sdk import DeviceService\nfrom iot_services_sdk import GatewayService\nfrom iot_services_sdk import SensorTypeService\nfrom iot_services_sdk import SensorService\n\nfrom iot_services_sdk import MQTTClient\n\n# Initialize services\ndevice_service = DeviceService(instance = myinstance.eu10.cp.iot.sap, user = myuser, password = mypassword)\ncapability_service = CapabilityService(instance = myinstance.eu10.cp.iot.sap, user = myuser, password = mypassword)\ngateway_service = GatewayService(instance = myinstance.eu10.cp.iot.sap, user = myuser, password = mypassword)\nsensor_type_service = SensorTypeService(instance = myinstance.eu10.cp.iot.sap, user = myuser, password = mypassword)\nsensor_service = SensorService(instance = myinstance.eu10.cp.iot.sap, user = myuser, password = mypassword)\n\n# Turn requests debug functionality on\ncapability_service.debug_requests_on()\ndevice_service.debug_requests_on()\ngateway_service.debug_requests_on()\nsensor_type_service.debug_requests_on()\nsensor_service.debug_requests_on()\n\n# Get Gateway\nfilters = [\"status eq 'online'\"]\ngateways_response = gateway_service.get_gateways(filters=filters)\ngateways = gateways_response.get_result()\nmqtt_gateway = next(gateway for gateway in gateways if gateway['protocolId'] == 'mqtt')\n\n# Create Measure Capability\nproperties = [\n {\"name\": \"sdk_test_temp\", \"dataType\": \"double\", \"unitOfMeasure\": \"Celcius\"}\n]\ncreate_response = capability_service.create_capability('sdk_test_measure_id', 'sdk_test_measure_cap', properties)\n\ncapability_measure_id = create_response.get_result().get('id')\ncapability_measure_alternate_id = create_response.get_result().get('alternateId')\n\n# Create Command Capability\nproperties = [\n {\"name\": \"sdk_test_cmd\", \"dataType\": \"string\"}\n]\ncreate_response = capability_service.create_capability('sdk_test_cmd_id', 'sdk_test_cmd_cap', properties)\n\ncapability_cmd_id = create_response.get_result().get('id')\ncapability_cmd_alternate_id = create_response.get_result().get('alternateId')\n\n# Create Device\ncreate_response = device_service.create_device(mqtt_gateway['id'], 'sdk_device')\n\ndevice = create_response.get_result()\ndevice_id = device['id']\ndevice_alternate_id = device['alternateId']\n\n# Create Sensor Type\ncapabilities = [\n {'id': capability_measure_id, 'type': 'measure'},\n {'id': capability_cmd_id, 'type': 'command'}\n]\ncreate_response = sensor_type_service.create_sensor_type('123456', 'sdk_mqtt_test_type', capabilities)\n\nsensor_type_id = create_response.get_result().get('id')\nsensor_type_alternate_id = create_response.get_result().get('alternateId')\n\n# Create Sensor\ncreate_response = sensor_service.create_sensor(device_id, 'sdk-test-mqtt-sensor-id', 'sdk-test-mqtt-sensor-name', sensor_type_id)\n\nsensor_id = create_response.get_result()['id']\nsensor_alternate_id = create_response.get_result()['alternateId']\n\n# Download Certificate\nres = device_service.get_device_pem(device_id).get_result()\n\npem = res.get('pem')\nsecret = res.get('secret')\npem_filepath = 'cert.pem'\n\n# Write Certificate to PEM file\npem_file = open(pem_filepath, 'w')\npem_file.write(pem)\npem_file.close()\n\n# Get MQTT Client for Device\nmqtt_client = device_service.get_mqtt_client(device_alternate_id, pem_filepath, secret)\nmqtt_client.connect()\nmqtt_client.loop_start()\n\n# Publish a measure\nmeasures = [\n {'sdk_test_temp': 30}\n]\nmessage_info_measures = mqtt_client.publish(capability_measure_alternate_id, sensor_alternate_id, measures, device_alternate_id)\n\n# Read measures\nget_measures_response = device_service.get_measures(device_id)\nmeasures = get_measures_response.get_result()\n\n# Publish invalid measure and receive error\ndef on_error(client, userdata, report):\n print('ERROR RECEIVED: ')\n print(report)\n\nmqtt_client.on_error = on_error\n\nmeasures = [\n {'i_am_invalid': 30}\n]\nmessage_info_measures = mqtt_client.publish(capability_measure_alternate_id, sensor_alternate_id, measures, device_alternate_id)\n\n# Publish and receive command\ndef on_command(client, userdata, command):\n print('COMMAND RECEIVED: ')\n print(command)\n\nmqtt_client.on_command = on_command\n\nmqtt_client.subscribe(device_alternate_id)\n\ncommand = {'sdk_test_cmd': 'I am a SDK!'}\n\nsend_command_res = device_service.send_command_to_device(device_id, capability_cmd_id, sensor_id, command)\n\n# Stop MQTT loop\nmqtt_client.loop_stop()\n\n# Delete Sensor\ndelete_sensor_res = sensor_service.delete_sensor(sensor_id)\n\n# Delete Device\ndelete_response = device_service.delete_device(device_id)\n\n# Delete SensorType\ndelete_sensor_type_response = sensor_type_service.delete_sensor_type(sensor_type_id)\n\n# Delete Measure Capability\ndelete_response = capability_service.delete_capability(capability_measure_id)\n\n# Delete Command Capability\ndelete_response = capability_service.delete_capability(capability_cmd_id)\n\n# Delete Certfile\ntry:\n os.remove(pem_filepath)\nexcept OSError:\n pass\n```\n\n## Test\nTo run the tests, you have to place a config.ini in the root directory. It has to contain the following information:\n```\n[IOTS]\nINSTANCE=myinstance.eu10.cp.iot.sap\nBASE_URI=/iot/core/api/v1\nGATEWAY_URI=/iot/gateway\nUSER=myuser\nPASSWORD=mypassword\n```\nThen, run \n\n`nosetests`\n\nin the root directory. The tests will clean up after themselves - there is no need to check your system afterwards.\n\n## Build Docs\nUse Sphinx to build the documentation directly from the docstrings:\n\n`cd docs`\n\n`sphinx-apidoc -f -o source/ ../sap_iot_services_sdk`\n\n`make latexpdf`\n\nCopy the SAPIoTServicesSDK.pdf file into the root directory.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "https://github.com/SAP/iot-services-sdk/archive/1.0.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/SAP/iot-services-sdk", "keywords": "SAP IoT Services CF SDK MQTT REST Device Management Internet of Things", "license": "SAP Sample Code License", "maintainer": "", "maintainer_email": "", "name": "iot-services-sdk", "package_url": "https://pypi.org/project/iot-services-sdk/", "platform": "", "project_url": "https://pypi.org/project/iot-services-sdk/", "project_urls": { "Download": "https://github.com/SAP/iot-services-sdk/archive/1.0.tar.gz", "Homepage": "https://github.com/SAP/iot-services-sdk" }, "release_url": "https://pypi.org/project/iot-services-sdk/1.4/", "requires_dist": null, "requires_python": ">=3", "summary": "SDK for SAP IoT Services on Cloud Foundry. Wraps all Device Management APIs as well as both Cloud Gateways.", "version": "1.4" }, "last_serial": 5827268, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "568c017bc5df9ae0aff4e51f906b3c08", "sha256": "de264c8dbdcd779cfd59fd9fecf55adb224af3174abe44f42bd680aab273d4f1" }, "downloads": -1, "filename": "iot_services_sdk-1.0.tar.gz", "has_sig": false, "md5_digest": "568c017bc5df9ae0aff4e51f906b3c08", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 19257, "upload_time": "2019-05-02T06:46:37", "url": "https://files.pythonhosted.org/packages/a7/ba/1a13d8bbed34152afa135adfb67c98fb84e23a800928ec216638eeba4539/iot_services_sdk-1.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "a225a908afcefecc04cfb237c2a405d8", "sha256": "cd1da6975557f35ddf6f020711711da6797de4475691544e147e96b1cf23c040" }, "downloads": -1, "filename": "iot_services_sdk-1.1.tar.gz", "has_sig": false, "md5_digest": "a225a908afcefecc04cfb237c2a405d8", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 19091, "upload_time": "2019-09-02T09:47:48", "url": "https://files.pythonhosted.org/packages/28/b4/9d85882eae60c267b85fcb9c8a19a5bd1b63f1250db6697d42371388c17b/iot_services_sdk-1.1.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "f6e4b7ac32612d090b2a05d26ae9752f", "sha256": "b25f01dc754fe3656b0f0a2845d72ed441e47c7b704d039f337c12dd8d7efd72" }, "downloads": -1, "filename": "iot_services_sdk-1.2.tar.gz", "has_sig": false, "md5_digest": "f6e4b7ac32612d090b2a05d26ae9752f", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 18453, "upload_time": "2019-09-04T06:01:54", "url": "https://files.pythonhosted.org/packages/a1/10/26cd8c77755b753f11178ebee567fbf8bbd208bf3f292696d5af8b6d96cb/iot_services_sdk-1.2.tar.gz" } ], "1.3": [ { "comment_text": "", "digests": { "md5": "c2ef9c7d27eee0fe16256813d88eedcd", "sha256": "5069f73f3e473a79f02e0373617d81ac59e20f82e625fd26b9bfd5c4dddb837a" }, "downloads": -1, "filename": "iot_services_sdk-1.3.tar.gz", "has_sig": false, "md5_digest": "c2ef9c7d27eee0fe16256813d88eedcd", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 18493, "upload_time": "2019-09-13T17:47:33", "url": "https://files.pythonhosted.org/packages/30/70/aa587c98469709ca5cd7a128c6cb7bb682fb04576b66715b02f335331312/iot_services_sdk-1.3.tar.gz" } ], "1.4": [ { "comment_text": "", "digests": { "md5": "616a11ebefa77988ac3ff2489cb44474", "sha256": "14c2a1ea682a5b12c1534aa48adff9ab89fda27fa64610d13e64b1a5871d4287" }, "downloads": -1, "filename": "iot_services_sdk-1.4.tar.gz", "has_sig": false, "md5_digest": "616a11ebefa77988ac3ff2489cb44474", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 18486, "upload_time": "2019-09-13T18:49:13", "url": "https://files.pythonhosted.org/packages/56/41/6a5396584c8631e70d556853a1244d11f82ab5cf2fc87bd01a85689f274a/iot_services_sdk-1.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "616a11ebefa77988ac3ff2489cb44474", "sha256": "14c2a1ea682a5b12c1534aa48adff9ab89fda27fa64610d13e64b1a5871d4287" }, "downloads": -1, "filename": "iot_services_sdk-1.4.tar.gz", "has_sig": false, "md5_digest": "616a11ebefa77988ac3ff2489cb44474", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 18486, "upload_time": "2019-09-13T18:49:13", "url": "https://files.pythonhosted.org/packages/56/41/6a5396584c8631e70d556853a1244d11f82ab5cf2fc87bd01a85689f274a/iot_services_sdk-1.4.tar.gz" } ] }