Comments (1)
Hi I also face similar problem. I genereally raise a flag to show that scubscription is done if not I restart the process after some tries. subscribtion call back is not called. as you post above said not to immediately publish while subscribing. so I pushed my publish call to subscribe_cb. still I don't get subscription callback this use to work before.
this is my codes out put. (sorry code is complex now )
`
[MQTT INFO] Connected to MQTT broker, create sending thread before call connected callback
[MQTT INFO] mqtt_sending_task
I (7792) BYTELENSCLIENT: Connected to BROKER.
I (7802) BYTELENSCLIENT:
I (7802) BYTELENSCLIENT: /27/24:a:c4:1:1b:34/auth <----- I first create topic strings( concate string etc)
I (7812) BYTELENSCLIENT: /27/24:a:c4:1:1b:34/authdone
I (7822) BYTELENSCLIENT: /37/24:a:c4:1:1b:34/list
(then I subscribe to topics, only 2 topics for now)
[MQTT INFO] Queue subscribe, topic"/27/24:a:c4:1:1b:34/authdone", id: 1
[MQTT INFO] Sending...50 bytes
[MQTT INFO] Queue subscribe, topic"/24:a:c4:1:1b:34/list", id: 2
[MQTT INFO] Sending...49 bytes
[MQTT INFO] mqtt_start_receive_schedule
[MQTT INFO] Read len 5
[MQTT INFO] Read len 50
[MQTT INFO] Queue response QoS: 1
[MQTT INFO] Sending...4 bytes
[MQTT INFO] deliver_publish
(no subscribe_cb called)
[MQTT INFO] Data received: 1/1 bytes
I (8072) BYTELENSCLIENT: Data cb.
I (8082) BYTELENSCLIENT: Publish topic: /27/24:a:c4:1:1b:34/authdone
[MQTT INFO] Read len 5
I (12892) wifi: pm start, type:0
[MQTT INFO] Read len 50
[MQTT INFO] deliver_publish
[MQTT INFO] Data received: 3/3 bytes
I (19102) BYTELENSCLIENT: Data cb.
I (19102) BYTELENSCLIENT: Publish topic: /27/24:a:c4:1:1b:34/authdone <---- but I receive data when I publish from hivemq.com try demo
I (31872) GATTC_DEMO: Ticker: conn: 0 ,Noti: 0, scan: 0
I (31872) GATTC_DEMO: Ticker: wificon: 1, mqttcon: 1, mqttsub: 0
I (31872) GATTC_DEMO: Ticker: MQTT broker not Subscribed, retrying 0
I (62872) GATTC_DEMO: Ticker: conn: 0 ,Noti: 0, scan: 0
I (62872) GATTC_DEMO: Ticker: wificon: 1, mqttcon: 0, mqttsub: 0
I (62872) GATTC_DEMO: Ticker: MQTT broker not Connected, retrying 1
[MQTT INFO] Sending pingreq
[MQTT INFO] Read len 2
[MQTT INFO] MQTT_MSG_TYPE_PINGRESP
`
my subscribe_cb and
void subscribe_cb(void *self, void *params)
{
ESP_LOGI(BCLIENT_TAG, "Subscribed to ");
mqtt_client *client = (mqtt_client *)self;
mqtt_event_data_t *event_data = (mqtt_event_data_t *)params;
char *myID=getStrHubID();
mqtt_publish(client,MQTT_CSV_AUTH,myID,strlen(myID),0,0);
mqttSubscribed=true;
// mqtt_publish(client, MQTT_TOPIC_INFO,str,strlen(str), 0, 0);
}
void connected_cb(void *self, void *params)
{
ESP_LOGI(BCLIENT_TAG,"Connected to BROKER. \n")
mqtt_client *client = (mqtt_client *)self;
MQTTCLIENT=client;
mqtt_event_data_t *event_data = (mqtt_event_data_t *)params;
//char *str="I am ESP32.";
Broker_Connected = true;
mqttConnected=Broker_Connected;
create_topics();
// first subscribe to all topics
mqtt_subscribe(client,MQTT_CSV_AUTHDONE,1);
mqtt_subscribe(client,MQTT_CSV_LIST,1);
}
//and mqtt settings
mqtt_settings settings = {
.host = MQTT_HOST,
#if defined(CONFIG_MQTT_SECURITY_ON)
.port = 8883, // encrypted
#else
.port = 1883, // unencrypted
#endif
.client_id = MQTT_CLIENT_ID,
.username = MQTT_USER,
.password = MQTT_PASS,
.clean_session = 0,
.keepalive = 120,
.lwt_topic = MQTT_TOPIC_LWT,
.lwt_msg = "offline",
.lwt_qos = 0,
.lwt_retain = 0,
.connected_cb = connected_cb,
.disconnected_cb = disconnected_cb,
// .reconnect_cb = reconnect_cb,
.subscribe_cb = subscribe_cb,
.publish_cb = publish_cb,
.data_cb = data_cb
};
from esp32-mqtt.
Related Issues (20)
- What does t MQTT_MSG_TYPE_PINGRESP mean? HOT 9
- Connection refuse, Unknown reason HOT 1
- Samsung's ARTIK Cloud connect error HOT 1
- not able to connect to hive mqtt HOT 3
- example fails compile, when fixed fails to execute properly HOT 1
- Compilation error - undeclared struct field "reconnect_cb" HOT 5
- esp32 as server broker
- MQTT cjson HOT 8
- mqtt_stop() sometimes does not work.
- Documentation for MQTT Library by tuanpmt HOT 1
- Client socket being destroyed after unsuccessful read from mqtt_start_receive_schedule() function HOT 2
- Offline Buffer issues trigger watchdog timer error
- Installing library in Eclipse environment
- Connection refused, not authorized HOT 9
- Mqtt_1 HOT 1
- lwt message is blank
- last will
- esp32 constant reboot HOT 1
- Link to new version is 404
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esp32-mqtt.