{ "info": { "author": "yansongda", "author_email": "me@yansongda.cn", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# aliyun-iot-device-python\n\n\u975e\u5b98\u65b9\uff0c\u963f\u91cc\u4e91 IOT \u5957\u4ef6\u8bbe\u5907\u7aef Python \u5f00\u53d1 SDK\n\n\n## \u652f\u6301\u7684\u534f\u8bae\n\n- [x] MQTT\n- [x] HTTP\n- [ ] CoAP\n\n\n## \u73af\u5883\n\n- Python3\n\n\n## \u5b89\u88c5\n\n`pip3 install yansongda-aliyun-iot-device`\n\n\n## \u4f7f\u7528\n\n### MQTT\n\n```Python\nfrom aliyun_iot_device.mqtt import Client as IOT\nimport time\n\n\ndef on_connect(client, userdata, flags, rc):\n print('subscribe')\n client.subscribe(qos=1)\n\n\ndef on_message(client, userdata, msg):\n print('receive message')\n print(str(msg.payload))\n\n\nPRODUCE_KEY = \"b1VzFx30hEm\"\nDEVICE_NAME = \"iot_device_01\"\nDEVICE_SECRET = \"3TSqd6sfzjSkSwEmLmcAdZnI0oGlmRZ8\"\n\niot = IOT((PRODUCE_KEY, DEVICE_NAME, DEVICE_SECRET))\n\niot.on_connect = on_connect\niot.on_message = on_message\n\niot.connect()\n\niot.loop_start()\nwhile True:\n iot.publish(payload=\"success\", qos=1)\n time.sleep(5)\n```\n\n#### \u56de\u8c03\n\n- on_connect\n\n \u5b9a\u4e49\u8fde\u63a5\u6210\u529f\u540e\u7684\u56de\u8c03\u51fd\u6570\n\n \u56de\u8c03\u51fd\u6570\u683c\u5f0f:\n\n `connect_callback(client, userdata, flags, rc)`\n\n client: the client instance for this callback\n\n userdata: the private user data as set in Client() or userdata_set()\n\n flags: response flags sent by the broker\n\n rc: the connection result\n\n- on_subscribe\n\n \u5b9a\u4e49\u8ba2\u9605\u6210\u529f\u540e\u7684\u56de\u8c03\u51fd\u6570\n\n \u56de\u8c03\u51fd\u6570\u683c\u5f0f:\n\n `subscribe_callback(client, userdata, mid, granted_qos)`\n\n client: the client instance for this callback\n\n userdata: the private user data as set in Client() or userdata_set()\n\n mid: matches the mid variable returned from the corresponding\n subscribe() call.\n\n granted_qos: list of integers that give the QoS level the broker has\n granted for each of the different subscription requests.\n\n- on_message\n\n \u5b9a\u4e49\u6536\u5230\u6d88\u606f\u65f6\u7684\u56de\u8c03\u51fd\u6570.\n\n \u56de\u8c03\u51fd\u6570\u683c\u5f0f:\n\n `on_message_callback(client, userdata, message)`\n\n client: the client instance for this callback\n\n userdata: the private user data as set in Client() or userdata_set()\n\n message: an instance of MQTTMessage.This is a class with members topic, payload, qos, retain.\n\n\n- on_publish\n\n \u5b9a\u4e49 publish() \u65b9\u6cd5\u6210\u529f\u53d1\u9001\u6d88\u606f\u65f6\u7684\u56de\u8c03\u51fd\u6570.\n\n \u683c\u5f0f:\n\n `on_publish_callback(client, userdata, mid)`\n\n client: the client instance for this callback\n\n userdata: the private user data as set in Client() or userdata_set()\n\n mid: matches the mid variable returned from the corresponding publish() call, to allow outgoing messages to be tracked.\n\n- on_unsubscribe\n\n \u5b9a\u4e49\u53d6\u6d88\u8ba2\u9605\u67d0\u6761 topic \u65f6\u7684\u56de\u8c03\u51fd\u6570.\n\n \u683c\u5f0f:\n\n `unsubscribe_callback(client, userdata, mid)`\n\n client: the client instance for this callback\n\n userdata: the private user data as set in Client() or userdata_set()\n\n mid: matches the mid variable returned from the corresponding\n unsubscribe() call.\n\n- on_disconnect\n\n \u5b9a\u4e49\u8fde\u63a5\u65ad\u5f00\u65f6\u7684\u56de\u8c03\u51fd\u6570.\n\n \u683c\u5f0f:\n\n `disconnect_callback(client, userdata, self)`\n\n client: the client instance for this callback\n\n userdata: the private user data as set in Client() or userdata_set()\n\n rc: the disconnection result.\n\n#### \u8bf4\u660e\n\n- \u57df\u540d\u76f4\u8fde\u4e0e HTTPS \u8ba4\u8bc1\n\n SDK \u9ed8\u8ba4\u4f7f\u7528\u57df\u540d\u76f4\u8fde\u540c\u65f6\u542f\u7528 TLS \u52a0\u5bc6\u3002\n\n \u5982\u679c\u60a8\u4e0d\u60f3\u4f7f\u7528 TLS \u52a0\u5bc6\uff0c\u53ef\u5728\u521d\u59cb\u5316\u65f6\u4f20\u5165 `tls=False` \u53c2\u6570\uff1b\n\n \u5982\u679c\u60a8\u60f3\u4f7f\u7528 HTTPS \u8ba4\u8bc1\uff0c\u53ef\u5728\u521d\u59cb\u5316\u65f6\u4f20\u5165 `domain_direct=False` \u53c2\u6570\uff0cHTTPS \u8ba4\u8bc1\u5c06\u5f3a\u5236\u4f7f\u7528 TLS \u8ba4\u8bc1\u52a0\u5bc6\n\n- TLS \u8ba4\u8bc1 CA \u8bc1\u4e66\n\n SDK \u9ed8\u8ba4\u4f7f\u7528\u4e86\u963f\u91cc\u4e91 IOT \u6839\u8bc1\u4e66\uff0c\u4e00\u822c\u60c5\u51b5\u65e0\u9700\u4fee\u6539\u3002\n\n \u5982\u4e00\u5b9a\u8981\u4fee\u6539\uff0c\u8bf7\u4f20\u5165 `ca_certs=\"/path/to/cert/root.cer\"` \n\n- websocket \u901a\u9053\n\n SDK \u9ed8\u8ba4\u4f7f\u7528 TCP \u901a\u9053\u3002\n\n \u5982\u679c\u9700\u8981\u4f7f\u7528 websocket\uff0c\u8bf7\u4f20\u5165 `transport=\"websockets\"`\u3002\n\n \u5f53\u4f7f\u7528 websocket \u65f6\uff0c\u9ed8\u8ba4\u542f\u7528 TLS\uff0c\u5373\u4f7f\u7528\u7684\u662f wss \u534f\u8bae\uff0c\u5982\u679c\u4e0d\u60f3\u4f7f\u7528 wss\uff0c\u8bf7\u540c\u65f6\u4f20\u5165 `tls=False`\n\n### HTTP\n\n```Python\nfrom aliyun_iot_device.http import Client as IOT\nimport time\n\nPRODUCE_KEY = \"b1VzFx30hEm\"\nDEVICE_NAME = \"iot_device_01\"\nDEVICE_SECRET = \"3TSqd6sfzjSkSwEmLmcAdZnI0oGlmRZ8\"\n\niot = IOT((PRODUCE_KEY, DEVICE_NAME, DEVICE_SECRET))\n\nwhile True:\n iot.publish('success')\n time.sleep(5)\n```\n\n#### \u6ce8\u610f\n\n- \u4f7f\u7528 http \u534f\u8bae\u8fdb\u884c\u901a\u8baf\u65f6\uff0c\u9700\u8981 token \u8fdb\u884c\u8ba4\u8bc1\uff0cSDK \u9ed8\u8ba4\u4f7f\u7528\u5185\u5b58\u578b\u7f13\u5b58\uff08cachetools \u65b9\u6848\uff09\u8fdb\u884c token \u7684\u4fdd\u5b58\u3002\n\n- \u5982\u679c\u60a8\u9700\u8981\u81ea\u884c\u8fdb\u884c\u5176\u4ed6\u65b9\u6848\u8fdb\u884c\u4fdd\u5b58\uff08file/memcached/redis\uff09\uff0c\u53ef\u4ee5 `iot.get_token(cache=False)` \u83b7\u53d6 token\uff0c\u518d publish \u6d88\u606f\u65f6\uff0c\u8bf7 `iot.publish(payload=payload, token=token)`\n\n\n## \u8bbe\u5907\u5f71\u5b50\u7cfb\u7edf\n\n```Python\n# \u8bbe\u5907\u4e3b\u52a8\u4e0a\u62a5\u72b6\u6001\niot.publish(payload={\"method\": \"update\",\n \"version\": i,\n \"reported\": {\"online\": True}},\n topic=\"shadow\",\n qos=1)\n\n# \u8bbe\u5907\u4e3b\u52a8\u83b7\u53d6\u8bbe\u5907\u5f71\u5b50\u5185\u5bb9\niot.publish(payload={\"method\": \"get\"},\n topic=\"shadow\",\n qos=1)\n\n# \u8bbe\u5907\u7aef\u5220\u9664\u5f71\u5b50\u5c5e\u6027\niot.publish(payload={\"method\": \"delete\", \"reported\": \"null\"},\n topic=\"shadow\",\n qos=1)\n```\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/yansongda/aliyun-iot-device-python", "keywords": "yansongda aliyun iot device", "license": "", "maintainer": "", "maintainer_email": "", "name": "yansongda-aliyun-iot-device", "package_url": "https://pypi.org/project/yansongda-aliyun-iot-device/", "platform": "", "project_url": "https://pypi.org/project/yansongda-aliyun-iot-device/", "project_urls": { "Homepage": "https://github.com/yansongda/aliyun-iot-device-python", "Source": "https://github.com/yansongda/aliyun-iot-device-python", "Tracker": "https://github.com/yansongda/aliyun-iot-device-python/issues" }, "release_url": "https://pypi.org/project/yansongda-aliyun-iot-device/0.6.0/", "requires_dist": [ "paho-mqtt (>=1.3.1)", "requests (>=2.18.4)", "cachetools (>=2.1.0)" ], "requires_python": ">=3.0, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "summary": "aliyun iot device sdk", "version": "0.6.0", "yanked": false, "yanked_reason": null }, "last_serial": 6026936, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "617b57667af37c7681e7bf3960b27f61", "sha256": "48c6204bef8e55e8639c5e5f1ae9856eeed3d7f00f68184ec38d09848da47a43" }, "downloads": -1, "filename": "yansongda_aliyun_iot_device-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "617b57667af37c7681e7bf3960b27f61", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.0, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 5855, "upload_time": "2018-05-31T06:27:28", "upload_time_iso_8601": "2018-05-31T06:27:28.447370Z", "url": "https://files.pythonhosted.org/packages/40/43/d385f3e268d6bb22fc95ddae9bd4f85250a4e6c5659b97d6f025176ea137/yansongda_aliyun_iot_device-0.1.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "daa4daf12829b5dbfbef36d6fab168b4", "sha256": "05f1cd806210a79c2a0ee54aac638df1af1325cdde710d657396c102f3d3aaef" }, "downloads": -1, "filename": "yansongda-aliyun-iot-device-0.1.1.tar.gz", "has_sig": false, "md5_digest": "daa4daf12829b5dbfbef36d6fab168b4", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.0, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 5114, "upload_time": "2018-05-31T06:27:29", "upload_time_iso_8601": "2018-05-31T06:27:29.683896Z", "url": "https://files.pythonhosted.org/packages/00/80/e748cf9cf883dc008265378450e441a2e98a7decabd6b0a54f51fd9f2b53/yansongda-aliyun-iot-device-0.1.1.tar.gz", "yanked": false, "yanked_reason": null } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "0fd5f68250b1b05ef87dc88a089a3b24", "sha256": "b83091ef582f5cb5fef39ba6d346ed90da6ad3199994c592a356ba9d67c27ebe" }, "downloads": -1, "filename": "yansongda_aliyun_iot_device-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "0fd5f68250b1b05ef87dc88a089a3b24", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.0, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 8608, "upload_time": "2018-06-04T07:19:15", "upload_time_iso_8601": "2018-06-04T07:19:15.820714Z", "url": "https://files.pythonhosted.org/packages/9c/57/9062c8c498aa8c67d808be757c5a457853d441d8bdf6c0fe3c6f94094d26/yansongda_aliyun_iot_device-0.2.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "38b16ba30f761c24e2aa6a57992258b3", "sha256": "9ea2097fb9f535fec9760e080c5b1e39c8564fafa0380abd1d3e455a7d7791fa" }, "downloads": -1, "filename": "yansongda-aliyun-iot-device-0.2.0.tar.gz", "has_sig": false, "md5_digest": "38b16ba30f761c24e2aa6a57992258b3", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.0, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 6654, "upload_time": "2018-06-04T07:19:18", "upload_time_iso_8601": "2018-06-04T07:19:18.183857Z", "url": "https://files.pythonhosted.org/packages/80/e2/463dfe8a5f0305c7ba24580104fa86fc95e6652a0c94fede3561e6e48add/yansongda-aliyun-iot-device-0.2.0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.5.0": [ { "comment_text": "", "digests": { "md5": "02afaec5213087d7a406165fea03ee81", "sha256": "fd03e9b9f00870158c29c1b192a08ffa537f88b24fe4a99086cb1e738c25056c" }, "downloads": -1, "filename": "yansongda_aliyun_iot_device-0.5.0-py3-none-any.whl", "has_sig": false, "md5_digest": "02afaec5213087d7a406165fea03ee81", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.0, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 9755, "upload_time": "2018-06-15T01:42:26", "upload_time_iso_8601": "2018-06-15T01:42:26.982785Z", "url": "https://files.pythonhosted.org/packages/55/57/ebed49d04042e20491d5328077683eba9f31e6b92fcfcc4de39bd4a6d823/yansongda_aliyun_iot_device-0.5.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "add86be077a92a8a2445970fb77ca0e5", "sha256": "7d1f6c495911c428e0d70f83f75c140ba84317c3c32959abebfdea8f0a359430" }, "downloads": -1, "filename": "yansongda-aliyun-iot-device-0.5.0.tar.gz", "has_sig": false, "md5_digest": "add86be077a92a8a2445970fb77ca0e5", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.0, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 8032, "upload_time": "2018-06-15T01:42:28", "upload_time_iso_8601": "2018-06-15T01:42:28.709918Z", "url": "https://files.pythonhosted.org/packages/51/94/61d48cf90160c473afaaedb1f0ae1b9d33d028f3a14e18fec20d0b540890/yansongda-aliyun-iot-device-0.5.0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.5.1": [ { "comment_text": "", "digests": { "md5": "336e8cab420cc8279b751adc2ed3780e", "sha256": "0b50b3c74cdd01dcc395c4795e99bbf6cae1ea17983b4c53fa726ee7d53ebc94" }, "downloads": -1, "filename": "yansongda_aliyun_iot_device-0.5.1-py3-none-any.whl", "has_sig": false, "md5_digest": "336e8cab420cc8279b751adc2ed3780e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.0, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 9751, "upload_time": "2018-06-15T01:55:30", "upload_time_iso_8601": "2018-06-15T01:55:30.240556Z", "url": "https://files.pythonhosted.org/packages/31/1e/c36bbbe3e0e86fb82285d81d2db8036759b3b52544c61e280b70c2c3c8fe/yansongda_aliyun_iot_device-0.5.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "a4201ca6a67376f74a86936b7439ab98", "sha256": "bd1131a6345e23f413e9f927d02179306d5abe5b9b0a12559eb7f27c3f25d92c" }, "downloads": -1, "filename": "yansongda-aliyun-iot-device-0.5.1.tar.gz", "has_sig": false, "md5_digest": "a4201ca6a67376f74a86936b7439ab98", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.0, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 8027, "upload_time": "2018-06-15T01:55:31", "upload_time_iso_8601": "2018-06-15T01:55:31.582414Z", "url": "https://files.pythonhosted.org/packages/f5/bf/b66478a1be72b4a4216412d475eccd500d11bb589342184a98a3c0212d96/yansongda-aliyun-iot-device-0.5.1.tar.gz", "yanked": false, "yanked_reason": null } ], "0.6.0": [ { "comment_text": "", "digests": { "md5": "8e571b36905ade1556abe8d039fe4967", "sha256": "40c64bb30d01bb7e67b975b70d1b8c6365e069bda0bcc5a7604862c6d8982340" }, "downloads": -1, "filename": "yansongda_aliyun_iot_device-0.6.0-py3-none-any.whl", "has_sig": false, "md5_digest": "8e571b36905ade1556abe8d039fe4967", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.0, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 10603, "upload_time": "2019-10-25T01:50:56", "upload_time_iso_8601": "2019-10-25T01:50:56.715713Z", "url": "https://files.pythonhosted.org/packages/58/74/38df9d5f011131113349faab3b7570925dfc94a7a6d436812704d36d114b/yansongda_aliyun_iot_device-0.6.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "100d39cdf3827b1446a1895a8401ea92", "sha256": "e851e6ea4c7fd278fb0358a0949d406825dc0afeb7a20f736c4a27914f122d7f" }, "downloads": -1, "filename": "yansongda-aliyun-iot-device-0.6.0.tar.gz", "has_sig": false, "md5_digest": "100d39cdf3827b1446a1895a8401ea92", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.0, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 9171, "upload_time": "2019-10-25T01:50:58", "upload_time_iso_8601": "2019-10-25T01:50:58.633252Z", "url": "https://files.pythonhosted.org/packages/0e/75/d7a16a08752f3315b6af607c7af9eea02273ae117a06b78882ea31c908e0/yansongda-aliyun-iot-device-0.6.0.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8e571b36905ade1556abe8d039fe4967", "sha256": "40c64bb30d01bb7e67b975b70d1b8c6365e069bda0bcc5a7604862c6d8982340" }, "downloads": -1, "filename": "yansongda_aliyun_iot_device-0.6.0-py3-none-any.whl", "has_sig": false, "md5_digest": "8e571b36905ade1556abe8d039fe4967", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.0, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 10603, "upload_time": "2019-10-25T01:50:56", "upload_time_iso_8601": "2019-10-25T01:50:56.715713Z", "url": "https://files.pythonhosted.org/packages/58/74/38df9d5f011131113349faab3b7570925dfc94a7a6d436812704d36d114b/yansongda_aliyun_iot_device-0.6.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "100d39cdf3827b1446a1895a8401ea92", "sha256": "e851e6ea4c7fd278fb0358a0949d406825dc0afeb7a20f736c4a27914f122d7f" }, "downloads": -1, "filename": "yansongda-aliyun-iot-device-0.6.0.tar.gz", "has_sig": false, "md5_digest": "100d39cdf3827b1446a1895a8401ea92", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.0, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 9171, "upload_time": "2019-10-25T01:50:58", "upload_time_iso_8601": "2019-10-25T01:50:58.633252Z", "url": "https://files.pythonhosted.org/packages/0e/75/d7a16a08752f3315b6af607c7af9eea02273ae117a06b78882ea31c908e0/yansongda-aliyun-iot-device-0.6.0.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }