novastone-media / MQTT-Client-Framework

iOS, macOS, tvOS native ObjectiveC MQTT Client Framework
Other
1.84k stars 466 forks source link

Not receiving messages, mosquitto version 1.4.2 #43

Closed vldn20 closed 7 years ago

vldn20 commented 9 years ago

Hello! I can not get messages. mosquitto version 1.3.4 (build date 2014-08-17 00:14:52-0300), Debian 8.0 - I get the messages mosquitto version 1.4.2 (build date Mon, 18 May 2015 15:25:19 +0100), Ubuntu 14.04 LTS - Not receiving messages

Paho works well on both versions

I tested for this code

- (void)start
{
    NSString *uuidString = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    self.session = [[MQTTSession alloc] initWithClientId:uuidString];
    self.session.delegate = self;
    self.session.keepAliveInterval = 610;
    self.session.cleanSessionFlag = YES;

    [self.session connectAndWaitToHost:@"127.0.0.1" port:1883 usingSSL:NO];
    [self.session subscribeToTopic:@"notification" atLevel:MQTTQosLevelExactlyOnce];
}

- (void)newMessage:(MQTTSession *)session data:(NSData *)data onTopic:(NSString *)topic qos:(MQTTQosLevel)qos retained:(BOOL)retained mid:(unsigned int)mid
{
    NSLog(@"MQTT got new message");

}

- (void)subAckReceived:(MQTTSession *)session msgID:(UInt16)msgID grantedQoss:(NSArray *)qoss
{
    NSLog(@"subscribed");
}
jpmens commented 9 years ago

Are you connecting to 127.0.0.1 from your iOS app? I don't think there's a Mosquitto broker running there ... :-)

vldn20 commented 9 years ago

No. IP is random :-)

yury commented 9 years ago

Yep, on latest pod version we don't recieve messages some times with mosquitto server. Checking...

ckrey commented 9 years ago

Can you do me a favor and check if you can connect and subscribe successfully with mosquitto_sub to both of your servers

Would you then check if you are connecting MQTT V3.1 or MQTT V3.1.1?

-V : specify the version of the MQTT protocol to use when connecting. Can be mqttv31 or mqttv311. Defaults to mqttv31.

The MQTT Client Library connects using MQTT V3.1.1 per default. You may change this by setting

self.session.protocolLevel = 3; before connecting.

Could you check the status of the connection before subscribing?

if (self.status == MQTTSessionStatusConnected) ...

vldn20 commented 9 years ago

I tried to connect to mosquitto version 1.4.2 with self.session.protocolLevel = 3 and self.session.protocolLevel = 4; It did not help me. I connected to the server and subscribed without errors, but not receiving messages. I can not check self.session.protocolLevel = 3 for the mosquitto version 1.3.4

ckrey commented 9 years ago

In your code sample shown initially, what are you doing after

[self.session connectAndWaitToHost:@"127.0.0.1" port:1883 usingSSL:NO]; [self.session subscribeToTopic:@"notification" atLevel:MQTTQosLevelExactlyOnce]; }

Are you keeping the thread running? Without that, you get no message?

Can you show me a bit more of your code? Or have a look at the examples in the Test package or in the demo application https://github.com/ckrey/MQTTChat

ckrey commented 9 years ago

@nv2089 were you able to resolve your issue?

tennessine commented 8 years ago

Subscribe after connected

    [self.session connectToHost:@"domain.com" port:8883 usingSSL:YES connectHandler:^(NSError *error) {

        [self.session subscribeToTopic:@"test/topic" atLevel:MQTTQosLevelExactlyOnce];
    }];
ckrey commented 8 years ago

@nv2089 were you able to resolve your issue? Can we close the issue?