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

Issues related to use MQTT-SN Gateway with XBee on raspberry pi #119

Closed chjej202 closed 6 years ago

chjej202 commented 6 years ago

Hello,

I have used Tomoaki yamaguchi's old MQTT-SN Gateway (https://github.com/ty4tw/MQTT-SN/tree/master/Gateway#mqtt-sn-gateway) on raspberry pi, and I recently know that Eclipse Paho project supports MQTT-SN Gateway.

So, I just tried to change old MQTT-SN Gateway to new Paho one.

During migration, I noticed that there are some issues for using the current Paho MQTT-SN Gateway with XBee on raspberry pi.

I cannot run the MQTT-SN Gateway with XBee on raspberry pi which is uploaded on the master, so I modified some codes in SensorNetwork.cpp.

The main issue is that I cannot get any data from ZigBee clients such as arduinos, so I just changed the below code in SensorNetwork.cpp.


bool SerialPort::recv(unsigned char* buf)
{
    struct timeval timeout;
    fd_set rfds;
    FD_ZERO(&rfds);
    FD_SET(_fd, &rfds);
    timeout.tv_sec = 0;
    timeout.tv_usec = 500000;    // 500ms
    if ( select(_fd+1, &rfds, 0, 0, &timeout) > 0 )
    {
        if (read(_fd, buf, 1) > 0)
        {
            D_NWSTACK( " %02x",buf[0] );
            return true;
        }
    }
    return false;
}

I changed the first parameter of the select() function from "1" to _fd+1.

For above change, I can get data from ZigBee clients to the MQTT-SN Gateway on raspberry pi 2, but I still cannot run the gateway on raspberry pi 3. After changing the below code, MQTT-SN Gateway is properly worked on both raspberry pi 2 and raspberry pi 3.


SerialPort::SerialPort()
{
    _tio.c_iflag = IGNBRK | IGNPAR;
    _tio.c_cflag = CS8 | CLOCAL | CRTSCTS  | CREAD;
    _tio.c_cc[VINTR] = 0;
    _tio.c_cc[VTIME] = 10;   // 1 sec.
    _tio.c_cc[VMIN] = 1;
    _fd = 0;
}

I added flag CREAD which is also used in Tomy's old gateway to open serial port.

I'm not sure it is a right way to fix the problem, but at least I need to fix these codes to run on my raspberry pi.