NodeMCU code that collects data about temperature, humidity, heat index and posts to a MQTT topic. This code uses NTP time, so the events can be even processed out-of-order and still reflect the data on a given instant.
This code uses deep sleep. Unless pin D0 is conneceted to RST pin, the application never wakes up. Also, when uploading the code to the board, disconnect pin D0 from RST or you'll not be able to upload it.
- Sometimes the NTP client returns a very small number that clearly is not a timestamp (e.g. 3, 4, ...)
- Externalize configuration to a file that can be added to
.gitignore
so I'm less prone to commit sensistive data.
From the PubSubClient library, the result of max_header_size + the topic name size + the payload size
cannot be greater that 128 (MQTT_MAX_PACKET_SIZE), otherwise it fails the publish with a false
status.
This code requires the following libraries