Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    How do you send data over NB-IOT on a FiPy? What socket.XXX to use? or do it ia AT+Commands?

    Scheduled Pinned Locked Moved FiPy
    fipynb-iotnb1nbiot
    8 Posts 4 Posters 2.0k Views 7 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C Offline
      combaindeft
      last edited by

      How do you send data over NB-IOT on a FiPy?

      I've tired all of the following socket-options ... and best I can mange is that get a HTTP Response of 47

      print('@ usocket.socket()')
      #s = usocket.socket()
      #s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
      #s = usocket.socket(usocket.AF_INET, usocket.SOCK_DGRAM)
      #s = usocket.socket(usocket.AF_INET, usocket.SOCK_RAW)
      #s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM, usocket.IPPROTO_TCP)
      #s = usocket.socket(usocket.AF_INET, usocket.SOCK_DGRAM, usocket.IPPROTO_TCP)
      #s = usocket.socket(usocket.AF_INET, usocket.SOCK_RAW, usocket.IPPROTO_TCP)
      #s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM, usocket.IPPROTO_UDP)
      s = usocket.socket(usocket.AF_INET, usocket.SOCK_DGRAM, usocket.IPPROTO_UDP)
      #s = usocket.socket(usocket.AF_INET, usocket.SOCK_RAW, usocket.IPPROTO_UDP)
      

      I do manage to connect to the Telia NB-IOT (Sweden, Lund):

      -----------------------------------------------------------------------------
      LOG: Initializing LTE NB-IOT
      LOG: define LTE()
      LOG: Reset LTE()
      LOG: Disonnecting LTE ... OK
      LOG: Detaching LTE ... OK
      LOG: LTE IMEI: 354346099263716
      LOG: AT CMD: AT+CEREG=2
      LOG: AT CMD: AT+CFUN=0
      LOG: AT CMD: AT!="clearscanconfig"
      LOG: AT CMD: AT!="addscanfreq band=20 dl-earfcn=6300"
      LOG: AT CMD: AT!="disablelog 1"
      LOG: AT CMD: AT+CGDCONT=1,"IP","lpwa.telia.iot"
      LOG: AT CMD: AT+CFUN=1
      
      DL SYNCHRO STATISTICS
      =====================
          Synchro state                         : IDLE
          PPU SIB1 ACQ watchdog                 : 0
          Frequency Hypothesis RF  (Hz)         : 0
          RSRP (dBm)                            : 0.00
          RSRQ  (dB)                            : 0.00
          Channel estimation state (Cell-spec.) : LOW CINR
          Channel estimation state (UE-spec.)   : LOW CINR
          Channel estimation state (MBSFN)      : LOW CINR
          Channel estimation CINR               : 0.00
          Channel length                        : SHORT
        AGC
          AGC RX gain (dB)                      : 0.00
          RX PSD BO (dBFs)                      : 0.00
          RX PSD (dBm)                          : 0.00
          Noise level RS (dBm)                  : 0.00
          Digital gain (dB)                     : 0.00
          CINR RS (dB)                          : 0.00
        NARROWBANDS
          Last DL NB                            : 0
          Last UL NB                            : 0
        AFC
          Frequency offset RF  (Hz)             : 0
          Frequency offset BB  (Hz)             : 0
        PBCH
          MIB received quantity                 : 0
          MIB timeout quantity                  : 0
      
      OK
      
      
      SYSTEM FSM
      ==========
          +--------------------------+--------------------+
          |            FSM           |        STATE       |
          +--------------------------+--------------------+
          | RRC TOP FSM              |STOPPED             |
          | RRC SEARCH FSM           |NULL                |
          | RRC ACTIVE FSM           |NULL                |
          | PMM PLMN FSM             |NULL                |
          | EMM MAIN FSM             |NULL                |
          | EMM AUTH FSM             |NULL                |
          | EMM CONN FSM             |NULL                |
          | EMM TAU FSM              |NULL                |
          | EMM TEST FSM             |NULL                |
          | ESM BEARER FSM           |BEARER_NULL         |
          | SMS MT FSM               |IDLE                |
          | SMS MO FSM               |IDLE                |
          | LPP FSM                  |IDLE                |
          | HP MAIN FSM              |IDLE                |
          | HP USIM FSM              |NULL                |
          | HP SMS MO FSM            |IDLE                |
          | HP SMS MT FSM            |IDLE                |
          | HP CAT FSM               |NULL                |
          +--------------------------+--------------------+
      
      OK
      
      LOG: Attaching to LTE network ......... OK
      LOG: Check LTE signal streanght (RSSI): +CSQ: 12,99OK
      LOG: Getting IP address: +CGPADDR: 1,"10.17.162.180"OK
      LOG: Connecting on LTE network  OK```
      
      

      But I cannot establish a socket or usocket connection to the Wia.io platform we use ... I have tested via Postman that the API is working properly and it all checks out ... so it's not a Platform issue ... and just a simple data connectivity issue of how to establish a connection ...via LTE NB-IOT

      S M 2 Replies Last reply Reply Quote 0
      • S Offline
        shedaim @combaindeft
        last edited by

        @combaindeft said in How do you send data over NB-IOT on a FiPy? What socket.XXX to use? or do it ia AT+Commands?:

        and just a simple data connectivity issue of h

        I use the library socket for the GPy, but it probably works the same for the FiPy.

        import socket
        
        addr = socket.getaddrinfo(ip, port)[0][-1]
        s = socket.socket()
        s.connect(addr)
        s.send(bytes(message), 'utf8'))
        
        

        Check whether you are connecting to the right "cid" for the right APN.

        C 1 Reply Last reply Reply Quote 0
        • C Offline
          combaindeft @shedaim
          last edited by

          @shedaim Hi,

          as you can read in my post usocket getaddrinfo issues ... there is something not OK with how it get's it's ip.

          Also, how do you tell usocket to use the LTE connection to send the data through? ... kinda like you do with Sigfox ... it has it's own socket.AF_SIGFOX defined ... LTE NB-IOT should have it's own aswell ...

          Right now can create a socket ... but it doesn't send any data through NB-IOT ... big question is, how where does all the data that I send go?

          D 1 Reply Last reply Reply Quote 0
          • D Offline
            danielm @combaindeft
            last edited by

            @combaindeft
            In my opinion it makes perfect sense to use the same socket family type for all IP based interfaces. It allows to use application-level protocol libraries (e.g. urequests, umqtt) over multiple types of IP interfaces without adaptation.

            Regarding DNS lookups - following fix was introduced in pre-release 1.18.1.r5:

            • Improved socket.getaddrinfo to only resolve name if avilable interfaces are up
              https://github.com/pycom/pycom-micropython-sigfox/releases

            Another issue with DNS resolving using socket.getaddrinfo() seems to be the fact that according to Sequans AT command reference it is not possible to manually set IP addresses of DNS servers. They may be some undocumented command...

            You may check if IP addresses of DNS servers are provided by the network by command:
            PDP Context Read Dynamic Parameters: +CGCONTRDP
            Response format: <bearer_id>, <apn>, <local_addr and subnet_mask>, <gw_addr>, <DNS_prim_addr>, <DNS_sec_addr>, <P-CSCF_prim_addr>, <P-CSCF_sec_addr>, <IM_CN_Signalling_Flag>

            Some DNS-related fixed was introduced in Sequans firmware NB1-40343.

            However, my experience is that releases 1.18.1.r3 to 1.18.1.r5 do not work well with NB-IoT connections in "real" applications. 1.18.1.r2 seems to work best from available releases however there is a known issue of eternal LTE.init() hang. It does not happen after every reset but you will eventually encounter it.

            Check my post and the post following after it for code for testing of NB-IoT connection. Do not forget to adapt band number and APN.
            https://forum.pycom.io/topic/3985/new-lte-firmware-releases-v1-18-1-r4-stable-1-19-0-b5-development-nb-iot-firmware-40343/21

            I also see that @iwahdan just released 1.18.1.r6 so we should test this release asap as well :)

            C 1 Reply Last reply Reply Quote 0
            • C Offline
              combaindeft @danielm
              last edited by

              @danielm

              Hi again,

              I have update to the latest development firmware 1.20.0.rc1

              >>> send_at_cmd_pretty('AT+CGPADDR')
              
              +CGPADDR: 1,"10.17.160.149"
              
              OK
              
              >>> 
              send_at_cmd_pretty('AT+CGCONTRDP=1')
              
              +CGCONTRDP: 1,5,"lpwa.telia.iot.mnc020.mcc238.gprs","10.17.160.149.255.255.255.255","","","","",""
              
              OK
              
              >>>
              

              And yes, it looks like we don't get any DNS_Prim_Server_IP from the DHCP :-( .. so doing DNS lookups doesn't work :-(

              D 1 Reply Last reply Reply Quote 1
              • D Offline
                danielm @combaindeft
                last edited by

                @combaindeft
                It's the same situation like with NB-IoT network of Slovak Telekom which I am using. It would help if it could be possible to set IP address of DNS server manually but I am not aware of such command.

                Another option is to implement DNS client directly in MicroPython.

                C 1 Reply Last reply Reply Quote 0
                • C Offline
                  combaindeft @danielm
                  last edited by

                  @danielm

                  UPDATE - DNS over NB-IOT is now working!

                  Please update to the latest 1.18.2 (stable):
                  https://forum.pycom.io/topic/4361/new-stable-firmware-release-v1-18-2

                  or to the latest 1.20.0.rc7 (development):
                  https://forum.pycom.io/topic/4359/new-v1-20-0-release-candidate-v1-20-0-rc7

                  Use the following to set your DNS Server to Google's DNS Servers ...

                  usocket.dnsserver(0,'8.8.8.8')
                  usocket.dnsserver(1,'4.4.4.4')
                  usocket.dnsserver()
                  ('8.8.8.8', '4.4.4.4')
                  

                  Then bring up your LTE Connection, and do:

                  >>> print(usocket.getaddrinfo("www.google.com", 80)[0][-1])
                  ('216.58.211.4', 80)
                  1 Reply Last reply Reply Quote 0
                  • M Offline
                    mraj @combaindeft
                    last edited by

                    @combaindeft Hej! I have just started to play with he Telia IoT using fipy. But I guess I am having similar problem with the socket creation as you experienced. I got such an error OSError: [Errno 113] EHOSTUNREACH while connecting to sockets. So how is it working for you now? Thanks.

                    1 Reply Last reply Reply Quote 1

                    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                    With your input, this post could be even better 💗

                    Register Login
                    • 1 / 1
                    • First post
                      Last post

                    Pycom on Twitter

                    Pycom