/SDK/PythonSDK/README.md

https://github.com/ECSLab/ES_IoT_Cloud · Markdown · 71 lines · 66 code · 5 blank · 0 comment · 0 complexity · d25692a8b580e80bed33ee577fd7dc7c MD5 · raw file

  1. # ESLABIOT:基于RaspberryPi的Python IOT Module
  2. ### 利用Pyhton基础包实现对ESLAB_IOT平台的长连接
  3. ## License
  4. > LGPL
  5. ## 功能实现
  6. - 长连接 *Websocket*
  7. - 单词发送 *HTTP POST*
  8. - 硬件开发 *WiringPi for Python*
  9. ## 使用提示
  10. - 本模块仅支持 Python 3.x 版本
  11. - 本模块目前仅测试于 *Github* 提供的 webscoket-client 模块环境
  12. - 本模块为了适配服务器时间建议使用时将其时间调至上海时区时间非UTC并进行校准
  13. ## 模块类定义
  14. #### `DHT11` 温湿度传感器DHT11封装类定义
  15. ```https://gitee.com/wustemla/iotplatform.git
  16. def __init__(self,owpin):
  17. """
  18. Test DEMO
  19. :param owpin: get data from this GPIO pin
  20. """
  21. ```
  22. - `getval()` 获取温湿度数据
  23. - `getresult()` 校验所得数据
  24. #### `Humidity_detect` 土壤湿度传感器封装类定义无数模转换
  25. ```
  26. def __init__(self, hdpin):
  27. """
  28. there is no AD transfer module
  29. so it can only print wet or dry
  30. :param owgin: get data from this GPIO pin
  31. """
  32. ```
  33. - `wet_or_dry()` 获得当前温湿状态
  34. #### `LocalTime` 系统时间封装类
  35. > 此类无需初始化
  36. - `get_current_time` 获得系统当前时间
  37. #### `HTTPPost` HTTP协议POST至服务器封装类定义只可单向
  38. ```
  39. def __init__(self, ip_address = "127.0.0.1", port = 9006,
  40. api_key = None, device_id = None,
  41. user_data = "Hi I'm Python",
  42. dev_num = None,sleep_time = 3):
  43. ```
  44. - `messages_send_to_server` 定义POST到服务器的数据包
  45. - `post_forever` 循环POST数据包至服务器失败仍重发
  46. #### `Websocket` Websocket协议与服务保持长连接封装类定义
  47. ```
  48. def __init__(self, ip_address = "127.0.0.1",
  49. port = 9000, api_key = None, dev_id = None,
  50. data = 'Hi I,m Python',sleep_time = 3):
  51. """
  52. :param ws: websocket object
  53. :param ip_address: the default value is "127.0.0.1"
  54. :param port: the default value is 9006
  55. """
  56. ```
  57. - `connect_to_server` 与服务器建立长连接
  58. - `send_message` 向服务器发送数据
  59. - `recv_from_server` 接受服务器数据并对心跳包进行处理
  60. - `run_forever` 断线重连一直保持连接
  61. ## 注意事项
  62. 若出现无法运行错误可将项目中包含的*websocket*包拷贝至本机python链接库中
  63. ```
  64. Path In Debian Release:
  65. /usr/local/lib/dist-packages/python3.x
  66. ```