tuanpm wrote:rvbcrs wrote:What I would like to do is as soon as I publish to a topic on the ESP8266, I want it to respond with a publish to the other subscribers so lets say I post to topic /gettemperature that the ESP publishes a message to topic /currenttemperature
Can you please tell me how to do that tuanpm?
You need a subscriber on channel /gettemperature, when it receive your publish msg, it will response by publish msg to /currenttemperature.
this is what I have done for now.. it responds on any topic for now but I don't care for now:
void mqttDataCb(uint32_t *args, const char* topic, uint32_t topic_len, const char *data, uint32_t data_len)
{
char topicBuf[64], dataBuf[64];
MQTT_Client* client = (MQTT_Client*)args;
os_memcpy(topicBuf, topic, topic_len);
topicBuf[topic_len] = 0;
os_memcpy(dataBuf, data, data_len);
dataBuf[data_len] = 0;
INFO("MQTT topic: %s, data: %s \r\n", topicBuf, dataBuf);
char tempBuf[128];
uint32_t temp_len = 128;
struct sensor_reading* r = readDHT();
float lastTemp=r->temperature;
float lastHum=r->humidity;
char* temp = (char*)((lastTemp - (int)lastTemp)*100);
os_memcpy(tempBuf, temp, temp_len);
tempBuf[temp_len] = 0;
MQTT_Publish(client, "/currenttemperature", tempBuf, temp_len, 0, 0);
/* Echo back to /echo channel*/
MQTT_Publish(client, "/echo", dataBuf, data_len, 0, 0);
}
I have MQTT Spy subscribed to the topic /currenttemperature but I never receive it! I do receive the /echo that is published right above it.. any ideas?