How to send UDP packet over NB-IoT



  • Hi everyone,
    I am trying to send UDP packet using GPy and Expansionboard V3.1.
    Thank you in advance for your assistance.
    Regards, Vojtech

    I have succeeded to connect modem to the NB-IoT network:

    >>> from network import LTE
    >>> lte = LTE()
    >>> lte.attach(band=20, apn="nb.xxx")
    >>> lte.isattached()
    True
    >>> lte.connect()
    >>> lte.isconnected()
    True
    

    I am trying to create socket:

    import socket
     import usocket
    s_nb = usocket.socket(usocket.AF_NBIOT, usocket.SOCK_DGRAM, usocket.IPPROTO_UDP)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'module' object has no attribute 'AF_NBIOT'
    

    It seems address family type AF_NBIOT does not exist.



  • @nadvorvo Code 9 stands for NB-IoT RAT, so your connection is ok. You might get your packets lost over-the-air, as plain UDP does not allow for confirmation. You can also check with TCP or MQTT if your operator allows it (many operators block non-UDP communication)



  • @agotsis Thank you for your reply. I really appreciate the help you’ve given me.

    I have tried to send UDP packet again:

    >>> from network import LTE
    >>> lte = LTE()
    >>> lte.attach(band=20, apn="xxx")
    >>> lte.isattached()
    True
    >>> lte.send_at_cmd('AT+CGPADDR')
    '\r\n+CGPADDR: 1,"10.0.1.197"\r\n\r\nOK\r\n'
    >>> lte.send_at_cmd('AT+CEREG?')
    '\r\n+CEREG: 2,5,"B7B6","0010581F",9\r\n\r\nOK\r\n'
    >>> lte.send_at_cmd('AT+COPS?')
    '\r\n+COPS: 0,2,"23003",9\r\n\r\nOK\r\n'
    

    +CGPADDR:
    IP address is ok 10.0.1.197 (same IP shown in NB-IoT backend)
    +CEREG:
    n=2 ... enable network registration and location information unsolicited result code
    stat=5 ... registered, roaming
    tac="B7B6" ... two byte tracking area code in hexadecimal format
    ci="0010581F" ... four byte E-UTRAN cell ID in hexadecimal format
    AcT=9 ... 9 undefined ???

    >>> lte.isattached()
    True
    >>> lte.connect()
    >>> lte.isconnected()
    True
    >>> import socket
    >>> UDP_IP = "10.1.0.1 "
    >>> UDP_PORT = 50000
    >>> MESSAGE = b"Hello, World!"
    >>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
    >>> s.sendto(MESSAGE, (UDP_IP, UDP_PORT))
    13
    

    Surprisingly, it was delivered to the NB-IoT backend.



  • @nadvorvo For all available AT commands you should check the Modem manual posted on the Pycom documentation: https://docs.pycom.io/gitbook/assets/Monarch-LR5110-ATCmdRefMan-rev6_noConfidential.pdf
    For example, you could check the IP address you got by the network by simply issuing: lte.send_at_cmd('AT+CGPADDR'). Notice that you need to do this not in data mode, so check it before lte.connect() and just after lte.isattached() becomes True. Also, what do you get from lte.send_at_cmd('AT+CEREG?')?



  • @agotsis Thank you for your reply.
    I do not have requirement to be connected to a WiFi and NB-IoT simultaneously.
    I am just troubleshooting, because I can not see packed send in NB-IoT back-end.

    >>> import socket
    >>> UDP_IP = "10.1.0.1 "
    >>> UDP_PORT = 50000
    >>> MESSAGE = b"Hello, World!"
    >>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
    >>> s.sendto(MESSAGE, (UDP_IP, UDP_PORT))
    13
    

    I can see output sendto function 13 character send. But I can not see anything in NB-IoT back-end.
    Is it possible to verify PLMN (public land mobile network) my modem is connected?
    Is there any other troubleshooting I can do to identify the problem?

    How to print IP address modem got from DHCT from telco provider? From NB-IoT back-end I can see It should be 10.0.1.197.

    >>> lte.IP
    'IP'
    

    I really appreciate the help given me.
    Regards, Vojtech



  • @nadvorvo I guess you mean you have simultaneously connected to a WiFi and an NB-IoT network, right? I am not sure if this can be handled by the pycom modules. I recall from a previous post forum, that you can't have more than one networks enabled at the same time, but not 100% sure. What is your use-case that requires more than one networks to be available at the same time?



  • @agotsis Thanks a lot for writing back.
    Let me ask to understand in detail.
    How is selected network (wifi / NB-IoT) which will be used to send UDP packet?
    Thanks Vojtech



  • @nadvorvo said in How to send UDP packet over NB-IoT:

    socket.AF_NBIOT

    There is no AF_NBIOT family type.
    The following snippet will do the work:

    import socket
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
    s.sendto(b'hello'.encode('utf-8'), (host, port))
    s.close()
    

Log in to reply
 

Pycom on Twitter