项目作者: mqvivarium

项目描述 :
Microcontroller client
高级语言: Python
项目地址: git://github.com/mqvivarium/ESP32.git
创建时间: 2018-04-27T18:42:36Z
项目社区:https://github.com/mqvivarium/ESP32

开源协议:MIT License

下载


ESP32 Microcontroller Sensor code

This contains the code to enable sensor readings utilising an ESP32 microcontroller

This is a work in progress

Diagram of project

Breadboard schematic

Breadboard schematic

Getting Started

Clone this repo to a location from which you can upload to your ESP32 microcontroller running MicroPython

  1. git clone https://github.com/mqvivarium/EP32.git

Config

Copy config/config.py.example to config/config.py, then adjust the config values

  1. # Set the SSID for your WiFi network
  2. SSID = 'YourSSID'
  3. # Set the password for your WiFi network
  4. WIFI_PASSWORD = 'YourWIFIPassword'
  5. # Time in seconds to wait between registering on the network
  6. # and attempting the sensor readings
  7. NETWORK_WAIT = 20
  8. # IP address of your MQTT broker
  9. MQTT_BROKER = '127.0.0.1'
  10. # Client name you want to publish to your broker as
  11. CLIENT_ID = 'ClientName'
  12. # Name to give the temperature reading topic
  13. TOPIC_TEMP = 'NameOfTemperatureTopic'
  14. # Name to give the humidity reading topic
  15. TOPIC_HUMID = 'NameOfHumidityTopic'
  16. # Time in seconds between each attempt reading the DHT22, MUST be greater than 2
  17. SENSOR_SLEEP = 30
  18. # Data in pin number
  19. DHT22_PIN = 15
  20. # Publish data LED pin number (optional), set to None if no LED used
  21. LED_PUBLISH_PIN = None
  22. # Read data LED pin number (optional), set to None if no LED used
  23. LED_READ_PIN = None

Copy files to your board

Copy main.py, config/ and mq/ to the root of your board

You should then have a structure like

  1. /home/pi/projects/ESP32> ls -la /pyboard/
  2. 75 Jan 1 2000 boot.py
  3. 0 Jan 1 2000 config/
  4. 249 Jan 1 2000 main.py
  5. 0 Jan 1 2000 mq/

Dependencies

You will need a copy of the micropython-lib umqtt.simple file

simple.py

Make a directory umqtt in root of your board and copy simple.py to that directory.

  1. /home/pi/projects/ESP32> mkdir /pyboard/umqtt
  2. /home/pi/projects/ESP32> cp simple.py /pyboard/uqmtt/

Running the code

When the ESP32 microcontroller boots it will automatically run the main.py file.
So just rebooting the board is sufficient to connect to your WiFi network and begin reading the sensor data.

Sensor data will be published to your MQTT broker at the interval your specified in the configuration file.