Do this
wait until done
Do next
Might be wasteful but it's a LOT easier than setting up a callback and passing stuff to it - especially as there are not many examples around to follow right now and we don't exactly have a manual. I think I'd like the OPTION to have buffering or for it to return when done...
Pete.
gicho wrote:I also saw that buffering doesn't work but maybe it shouldn't ... you have "void mqttPublishedCb(uint32_t *args)" to know when first publishing is ready so you can proceed (e.g. to the next value from this sensor or to the next sensor that needs to be served). This is the concept of "event", asynchronous programming. This way there is no need of huge buffers.
My point is that sending small chunks of separate topics is not the most efficient way to work on the embedded device.
What I've used on other IoT boards (but not yet on the ESP8266) is to put either JSON or type-lenght-value encoded blocks in one report. This fits in your scenario where you get both readings (temp and humidity) at the same time. It is also logical if you have and "object" (DHT11 sensor) with more than one properties. This will save you (and the broker, and the network) the overhead of multiple messages and processings. Also, no need to worry if both readings are from the same time.
JSON parser is available in the SDK, sometimes it is heavy on RAM (heap) but no matter it is probably a good alternative to the additional buffers.
I believe that most nodes in fact follow a simple sequence - startup/wakeup, read from sensor(s), optionally check if there is a change in the value since last reading, that send the data, Than maybe check for retained command message (subscribe) to execute something - e.g. change wakeup rate from 10s to 180s, or enter continuous mode (e.g. for configuration).