I have setup an esp-07 to read from the ADC. It is working perfectly, but I do not see where in Tuan's user_main.c that I can put my code in a 'main' loop. Under function mqttConnectedCb(uint32_t *args) I have added a code snippet to read from the ADC and store it in a buffer to be written to topic '/mqtt/topic/adc':
MQTT_Publish(client, "/mqtt/topic/0", "hello0", 6, 0, 0);
MQTT_Publish(client, "/mqtt/topic/1", "hello1", 6, 1, 0);
MQTT_Publish(client, "/mqtt/topic/2", "hello2", 6, 2, 0);
// Publish to ADC topic.
uint8_t buffer[4];
uint16 adc = system_adc_read();
ets_sprintf( buffer, "%d", adc );
MQTT_Publish(client, "/mqtt/topic/adc", buffer, 4, 1, 0);
The above gets run exactly one time AFAICT. I know the code is working OK, b/c I can publish (using mosquitto_pub) from my Mac terminal to the topics and it immediately pushes to the esp-07 subscriber. Also, I see the repeated keepAlive output.
I am a newbie at this and C is not a language I write code in for my day job. I'm just looking for that one comment that says:
// put main loop below here...
// ...
// end main loop.
In that main loop I would read from my ADC every n seconds and publish it to the mqtt broker.
Sorry if I'm not being clear. Sample code would be much appreciated!
Cheers,
Marshall