eclipse / paho.mqtt-sn.embedded-c

Paho C MQTT-SN gateway and libraries for embedded systems. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
315 stars 178 forks source link

Error: ClientSendTask can't send a packet to the client #155

Closed skireichev closed 4 years ago

skireichev commented 5 years ago

Hello. I have some problem with mqtt-sn gateway. Log + settings attached.

20190603 144116.313 CONNECT <--- 11 04 00 01 03 84 00 09 55 4D 33 31 53 4D 41 52 54 20190603 144116.366 CONNECT ===> 10 51 00 04 4D 51 54 54 04 C0 03 84 00 01 2A 00 40 66 4A 52 32 42 35 71 46 4F 38 48 30 33 57 32 6A 45 33 48 74 65 6C 59 73 63 50 6E 31 37 61 6A 61 4A 31 32 61 55 68 45 77 64 39 6D 36 54 66 64 6E 36 4B 46 39 54 74 70 57 36 43 4C 33 43 56 34 39 00 00 20190603 144116.447 CONNACK <=== 20 02 01 00 20190603 144116.447 CONNACK ---> 03 05 00 Error: ClientSendTask can't send a packet to the client *.

BrokerName=mqtt.flespi.io BrokerPortNo=1883 BrokerSecurePortNo=8883 ClientAuthentication=NO AggregatingGateway=NO QoS-1=NO Forwarder=NO

ClientsList=/path/to/your_clients.conf

PredefinedTopic=NO

PredefinedTopicList=/path/to/your_predefinedTopic.conf

RootCAfile=/etc/ssl/certs/ca-certificates.crt

RootCApath=/etc/ssl/certs/

CertsFile=/path/to/certKey.pem

PrivateKey=/path/to/privateKey.pem

GatewayID=1 GatewayName=PahoGateway-01 KeepAlive=900 LoginID=someprivateid Password=

UDP

GatewayPortNo=10000 MulticastIP=225.1.1.1 MulticastPortNo=1883

XBee

Baudrate=38400 SerialDevice=/dev/ttyUSB0 ApiMode=2

LOG

ShearedMemory=NO;

ty4tw commented 5 years ago

'*' is not allowed as ClientId. Only Alpha Numeric are allowed. Check the Specifications of MQTT-SN and MQTT.

skireichev commented 5 years ago

Thanks. Connect message was wrong. CliendID was written in MQTT style : length + data. Now clientID = 55 4D 33 31 53 4D 41 52 54 (only alpha numeric) But error persists.

20190604 111019.244 CONNECT <--- 0F 04 04 01 03 84 55 4D 33 31 53 4D 41 52 54 20190604 111019.298 CONNECT ===> 10 51 00 04 4D 51 54 54 04 C2 03 84 00 01 2A 00 40 66 4A 52 32 42 35 71 46 4F 38 48 30 33 57 32 6A 45 33 48 74 65 6C 59 73 63 50 6E 31 37 61 6A 61 4A 31 32 61 55 68 45 77 64 39 6D 36 54 66 64 6E 36 4B 46 39 54 74 70 57 36 43 4C 33 43 56 34 39 00 00 20190604 111019.673 CONNACK <=== 20 02 00 00 20190604 111019.673 CONNACK ---> 03 05 00 Error: ClientSendTask can't send a packet to the client *.

ty4tw commented 5 years ago

CliendID is not written in MQTT style. Just data without length.

5.4.4 CONNECT
 ClientId: same as with MQTT, contains the client id which is a 1-23 character
long string which uniquely identifies the client to the server.

Unlike MQTT, the length of the client Id is explicitly obtained from Message length.   

5.3.1 ClientId  
 A with MQTT, the ClientId field has a variable length and contains a 1-23 
character string.   

Explanation is not correct.
The specification is ambiguous about this.

skireichev commented 5 years ago

There are two logs in posts 1 and 3, with different clientID ( post 1 - length + clienID, post 3 - clientID only). I get an error anyway.

Add:Use transparent mode, without clients list (device with NB-IoT modem, UDP only).

ty4tw commented 5 years ago

GW can't send a packet by some reason. Can you try the code as follows to get the reason?

MQTTSNGWClientSendTask.cpp line 76.

        if ( rc < 0 )
        {
            WRITELOG("%s ClientSendTask can't send a packet to the client %s. Error=%d%s\n",
                ERRMSG_HEADER, (client ? (const char*)client->getClientId() : UNKNOWNCL ), rc, ERRMSG_FOOTER);
        }
        delete ev;
    }
}
skireichev commented 5 years ago

Add error message. Result:

Error: ClientSendTask can't send a packet to the client *. Error=-1

ty4tw commented 5 years ago

errno should be taken, sorry. Add #include and change rc to errno. Thank you.

skireichev commented 5 years ago

Done.

Error: ClientSendTask can't send a packet to the client *. Error=22

ty4tw commented 5 years ago

Errno 22 is Invalid Argument.

Compile the GW with make argument -DDEBUG_NWSTACK to activate D_NWSTACK() function. $ make -DDEBUG_NWSTACK

int UDPPort::unicast(const uint8_t* buf, uint32_t length, SensorNetAddress* addr)
{
    sockaddr_in dest;
    dest.sin_family = AF_INET;
    dest.sin_port = addr->getPortNo();
    dest.sin_addr.s_addr = addr->getIpAddress();

    int status = ::sendto(_sockfdUnicast, buf, length, 0, (const sockaddr*) &dest, sizeof(dest));
    if (status < 0)
    {
        D_NWSTACK("errno == %d in UDPPort::sendto\n", errno);
    }
    D_NWSTACK("sendto %s:%u length = %d\n", inet_ntoa(dest.sin_addr), ntohs(dest.sin_port), status);
    return status;
}
Hamilton-Dias commented 4 years ago

I got the same error while working the Paho Gateway.

The error was that my client was connecting to the gateway with the port 1883, while the corrent one is 10000.

ty4tw commented 4 years ago

Hi Hamulton, Thank you for kind information. I am going to close this issue if there is no more responsein near future.