Closed jhx2002 closed 4 years ago
Use mqtt-sn-tools to test
./mqtt-sn-tools-master/mqtt-sn-pub -h 192.168.1.9 -p 10000 -t 10 -m hello
2020-04-16 15:24:16 DEBUG Debug level is: 1.
2020-04-16 15:24:16 DEBUG Network timeout is: 30 seconds.
2020-04-16 15:24:16 DEBUG Trying 192.168.1.9...
2020-04-16 15:24:16 DEBUG Connecting...
2020-04-16 15:24:16 DEBUG Sending CONNECT packet...
2020-04-16 15:24:16 DEBUG waiting for packet...
2020-04-16 15:24:46 DEBUG Timed out waiting for packet.
2020-04-16 15:24:46 ERROR Failed to connect to MQTT-SN gateway.
Gateway waits a packet via UDP6. Client have to send a packet via UDP6.
tshark can get udp packet. Add some debug info in the source code as following. Foud that: return value of select always <= 0
//TODO: test if this is working properly (GW works, but this function is not completely tested)
int UDPPort6::recv(uint8_t* buf, uint16_t len, SensorNetAddress* addr)
{
struct timeval timeout;
fd_set recvfds;
timeout.tv_sec = 0;
timeout.tv_usec = 1000000; // 1 sec
FD_ZERO(&recvfds);
FD_SET(_sockfdUnicast, &recvfds);
std::cout << "xxxUDPPort6::recv" <<std::endl;
int rc = 0;
if ( select(_sockfdUnicast + 1, &recvfds, 0, 0, &timeout) > 0 )
{
// debug found : can not come here
if (FD_ISSET(_sockfdUnicast, &recvfds))
{
std::cout << "xxxUDPPort6::recv 2" <<std::endl;
rc = recvfrom(_sockfdUnicast, buf, len, 0, addr);
std::cout << "xxxUDPPort6::recv 3" <<std::endl;
}
}
std::cout << "yyyUDPPort6::recv rc=" << rc << std::endl;
return rc;
}
Gateway waits a packet via UDP6. Client have to send a packet via UDP6.
fe80::f58c:2fb7:adad:1 and 192.168.1.9 are on the same eth0, so the client can use 192.168.1.9 to publish . right ?
I test with sending a UDP6 packet. MQTT-SN Gateway can not recive the packet. But tshark can catch it.
Two cases log : Gateway.conf bind ip6 to 240e:390:3f:7560:f01e:4888:7e85:a
$ ./mqtt-sn-tools-master/mqtt-sn-pub -h 240e:390:3f:7560:f01e:4888:7e85:a -p 10000 -t 1 -m hello
recv failed: Connection refused
2. Running mqtt-sn gateway.
$ ./mqtt-sn-tools-master/mqtt-sn-pub -h 240e:390:3f:7560:f01e:4888:7e85:a -p 10000 -t 1 -m hello 2020-04-19 11:17:02 ERROR Failed to connect to MQTT-SN gateway.
I use udp 6 receiver from here, it's OK, it can recive the package from mqtt-sn-pub
https://github.com/jhx2002/test_riot/tree/master/udp_recv
Setup on same machine: mosquto broker + paho.mqtt-sn.gateway I have tested it successfully on x84 machine. On arm64 soc, build and run is OK, ping ipv6 and ipv4 is OK, but pub failed.
Here is log when gateway starting:
Following is error log when connecting it with mqtt-sn-tools: