tuanpmt / esp_mqtt

MQTT client library for ESP8266
http://tuanpm.net/post/esp_mqtt/
MIT License
1.14k stars 400 forks source link

Can use this ESP_MQTT to "iot.eclipse.org" , but can't for "test.mosquitto.org" . Why ? #150

Open TridentTD opened 6 years ago

TridentTD commented 6 years ago

I use this library on Arduino IDE 1.8.5 , and create very simple 2 functions call APIs from this library. my_mqttconn_and_subscribe() and my_publish() It's very good connection to any MQTT Broker.

However when I try connecting to "test.mosquitto.org" . It occurs WDT reset both PROTOCOL_NAMEv311 and PROTOCOL_NAMEv31. Why? and how to solve ?

Thank you.

//------------------------------------------ // Environment Platform : ArduinoIDE 1.8.5 ESP8266 Hardware : Wemos D1 mini ESP8266 Core : ESP8266 2.4.0-rc2 ESP8266 SDK : 2.1.0 //------------------------------------------

#include <ESP8266WiFi.h>

//--------User Config---------------------------------------------
#define SSID              "MyHome"
#define PASSWORD          "12345678"

#define PROTOCOL_NAMEv311  // PROTOCOL_NAMEv31
//#define MQTT_BROKER          "iot.eclipse.org"
#define MQTT_BROKER       "test.mosquitto.org"  
//#define MQTT_BROKER       "broker.hivemq.com"; 

#define MQTT_PORT         1883

//----------------------------------------------------------------

extern "C" {
typedef bool      BOOL;
typedef uint8_t   U8;
#include "user_interface.h"
#include "espconn.h"
#include "mqtt.h"      
}

MQTT_Client mqttClient;

void my_mqttconn_and_subscribe(){
  char client_id[30];
  uint8_t macaddr[6];
  if( wifi_get_macaddr( 0, macaddr ) ) {
    sprintf( client_id, "TD_MQTTClient_%0X%0X%0X", macaddr[3], macaddr[4],macaddr[5]);
  }

  MQTT_Disconnect(&mqttClient);
  MQTT_DeleteClient(&mqttClient);
  MQTT_InitConnection(&mqttClient, (uint8_t*) MQTT_BROKER, MQTT_PORT, 0);
  MQTT_InitClient(&mqttClient, (uint8_t*) client_id, 0, 0, 15, 0);

  MQTT_OnData(&mqttClient, [](uint32_t *args, const char* topic, uint32_t topic_len, const char *data, uint32_t data_len){  
    char topic_buff[topic_len+1]; memcpy(topic_buff, topic, topic_len); topic_buff[topic_len] = '\0';
    char data_buff[data_len+1];   memcpy(data_buff, data, data_len);    data_buff[data_len] = '\0';

    Serial.printf("[onData] %s\t%s\n", topic_buff, data_buff);
  });

  MQTT_Connect(&mqttClient);
  MQTT_Subscribe(&mqttClient, (char*) "/MyHome/Test/12342/Hello", 0);
}

void my_publish(){
  String data = String(random(10,90));
  MQTT_Publish(&mqttClient, "/MyHome/Test/12342/Hello",  data.c_str() , data.length(), 0, 0);
}

//----------------------------------------------------------------
void setup() {
  Serial.begin(115200); Serial.println();
  WiFi.begin(SSID, PASSWORD);
  while(!WiFi.isConnected()) delay(500);
  Serial.println(WiFi.localIP());

  my_mqttconn_and_subscribe();
  int countdown = 10;
  while( countdown-- > 0 ) {
    Serial.print(10-countdown);delay(1000);
  }
  Serial.println();
}

void loop() {
  my_publish();
  delay(1000);
}
//----------------------------------------------------------------

error on serial monitor ..

192.168.43.53
12345678910[onData] bbc/subtitles/bbc_news24/raw     seeing
[onData] bbc/subtitles/bbc_one_london/raw    is
[onData] CPM/MTS/IGB/data   {"d" :
{"Input_Roller_Bearing": 71.720187, "Output_Roller_Bearing" : 67.762813, "Output_Duplex_Bearing": 71.648572, "RMS_time_domain": 0.175518, "Peak_to_Peak": 1.430276, "max_value": 0.000000, "Frequency":  3.000000, "RMS": 0.000000, "max_value_2": "NaN", "2nd_Harmonic": 8.000000, "RMS_2": "NaN", "max_value_3": 0.000000, "frequency_3": 13.000000, "RMS_3": "NaN", "max_value_4": 0.000000, "frequency_4": 80.000000, "RMS_4": "NaN", "max_value_5": 0.000000, "frequency_5": 160.000000, "RMS_5": "NaN", "Torque_Load": -0.200000, "RMS_time_domain_2": 0.023384, "Peak_to_Peak_2":  0.083542, "Amps": -3.700608, "Shaft_RPM": 0.000000, "Recording_Time": 0.000000} 
}
[onData] JAG1/out/components    {"fingerprint":00006791,"components":{"sensor":{"traits":["jag"],"state": {"jag":{"humidity": 22,"lightness": 6,"temperature": 24}}}}}
[onData] /outbox/crouton-demo/temperature   {"update": {"labels":[3772],"series":[[63]]}}

Exception (28):
epc1=0x40208f24 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: sys 
sp: 3ffffa90 end: 3fffffb0 offset: 01a0

>>>stack>>>
3ffffc30:  3fff33d8 75716572 00000000 ffff0208  
3ffffc40:  3ffffdb0 3ffffd80 00000010 0000002d  
3ffffc50:  3ffe911b 00000001 22202c30 5f78616d  
3ffffc60:  756c6176 22325f65 4e22203a 00000058  
3ffffc70:  3ffef7c4 3ffe8304 00000059 40205751  
3ffffc80:  3fff1b0c 30303030 00000000 ffff0208  
3ffffc90:  3fff1ab4 00000058 22202c22 5f78616d  
3ffffca0:  3ffef7a4 0000045c 0000045c 4010020c  
3ffffcb0:  3ffef7c4 000000a4 3fff3334 4010068c  
3ffffcc0:  31203a22 30302e33 30303030 40202cfc  
3ffffcd0:  3ffef7c4 00000008 40225dfb 00000001  
3ffffce0:  ffffffff 00000000 3ffe9d11 00000008  
3ffffcf0:  40225e4a 3ffed330 3fff1144 00000001  
3ffffd00:  40225f56 3ffed330 40225dfb 00000001  
3ffffd10:  ffffffff 00000000 3ffe9d11 00000008  
3ffffd20:  40225e4a 3ffed330 3fff1144 00000001  
3ffffd30:  40225f56 3ffed330 3fff1144 3ffed330  
3ffffd40:  00000002 00000000 00000020 40100ec2  
3ffffd50:  3ffe9bc2 40224f23 3ffed330 3fff1537  
3ffffd60:  00000000 4020dadf 3ffee7d8 003a2273  
3ffffd70:  00000000 00000002 00000000 3ffed330  
3ffffd80:  3fff2f7e 4022eeac 3fff2f7e 3fff2f44  
3ffffd90:  3fff1504 365b5b3a 6d6f6322 656e6f70  
3ffffda0:  4010228b 00080000 00000010 00000002  
3ffffdb0:  3fff0d38 00000003 3fff1504 4022f17d  
3ffffdc0:  3fffc278 40101f88 3fffc200 00000022  
3ffffdd0:  000000c0 0001f3fa 40225dfb 00000001  
3ffffde0:  ffffffff 00000000 3ffe9d11 00000008  
3ffffdf0:  40225e4a 3ffed470 3ffedf8c 3ffedbb0  
3ffffe00:  00000005 00000000 00000020 40100ec2  
3ffffe10:  3ffe9bc5 401042bf 3ffed650 40100ec2  
3ffffe20:  40101bdd 3ffed650 3ffedd40 3fff13ec  
3ffffe30:  00000000 3ffffc40 3ffee04c 3ffef578  
3ffffe40:  00000001 3fff2f44 3ffef4c0 3ffef578  
3ffffe50:  000001e8 3fff2f44 3ffef4c0 40237a68  
3ffffe60:  40233729 00000000 00000000 000001e8  
3ffffe70:  4022c49a 00004288 3ffec3f0 4022c4b1  
3ffffe80:  3fff1c6c 00000000 3fff1ab4 401004f4  
3ffffe90:  3fffc278 3fff2e8c 3fff1ab4 3fff2f44  
3ffffea0:  3fff1a44 3fff2e8c 3fff1ab4 40242edd  
3ffffeb0:  00000000 3ffe9969 00000006 00000001  
3ffffec0:  40000f58 00000000 00000020 3fff0e24  
3ffffed0:  3fff2e8c 3fff0e2c 3fff0e28 40231c74  
3ffffee0:  000001e8 352ba8c0 00000018 000001e8  
3ffffef0:  00000000 00000018 3ffeee68 40106abc  
3fffff00:  40200000 00000000 00000064 3fff0ed8  
3fffff10:  3ffea4c6 3fff0edc 3fff1ab4 40230091  
3fffff20:  003c4288 3fff1504 3fff1504 3ffee7d8  
3fffff30:  00000000 3fff1ab4 0000001c 3fff1504  
3fffff40:  3ffea4b8 00000000 3fff1ab4 4022f495  
3fffff50:  106abb25 00000246 00000000 0000002d  
3fffff60:  00000002 0000001a 402253df 3ffed650  
3fffff70:  3ffea490 3fffdcc0 3ffe9c28 3ffe9c28  
3fffff80:  40225352 3ffed650 00000000 3fff154c  
3fffff90:  3fffdc80 00000000 3fff1ab4 402330c7  
3fffffa0:  40000f49 3fffdab0 3fffdab0 40000f49  
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(1,6)

 ets Jan  8 2013,rst cause:4, boot mode:(1,6)

wdt reset