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

    uping doesn´t work on LTE-M1

    Scheduled Pinned Locked Moved GPy
    4 Posts 2 Posters 213 Views 2 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.
    • F Offline
      fruiz1113
      last edited by

      I am attached and connected to LTE-M in Argentina :
      lte.send_at_cmd('at+cgdcont=1, "IP", "datos.personal.com"')
      Also enable the functionality +CFUN=1

      1.JPG
      When I import uping.py file and try uping.ping('google.com') I got an error in line 52
      2.JPG
      3.JPG
      I thinks it is a modem configuration issue, something I have to define as I was playing with different at commands after lte.pppsuspend() , and one time when I return to LTE lte.pppresume() , it worked , but I didn´t save the configuration and since then I can not make it run.
      Any idea to configure in the modem or in the uping script ?[uping.py]

      Also I can not run the simple LTE example

      s = socket.socket()
      s = ssl.wrap_socket(s)
      s.connect(socket.getaddrinfo('www.google.com', 443)[0][-1])
      s.send(b"GET / HTTP/1.0\r\n\r\n")
      print(s.recv(4096))

      It fails in the s.connect(socket.getaddrinfo('www.google.com', 443)[0][-1]) line
      (/assets/uploads/files/1584659765014-uping.py)

      1 Reply Last reply Reply Quote 0
      • F Offline
        fruiz1113
        last edited by

        An interesting thing is that If I put IPV4 instead of IP it works , but after a minute if I try again it throws error in line 55

        addr = usocket.getaddrinfo(host, 1)[0][-1][0] # ip address

        1 Reply Last reply Reply Quote 0
        • K Offline
          kjm
          last edited by

          1. I've found pppsuspend/resume to be unreliable, maybe avoid them for the time being & use lte.disconnect() instead if you want to run an at cmd
          2. Try to limit yourself to one query per post, I've found it improves your chances of getting a reply if you don't conflate multiple issues.
          3. There are multiple versions of most micropython libraries, many of them not functional on pycom product. Try running the version of ping below on an attached/connected gpy
          def checksum(data):
              if len(data) & 0x1: # Odd number of bytes
                  data += b'\0'
              cs = 0
              for pos in range(0, len(data), 2):
                  b1 = data[pos]
                  b2 = data[pos + 1]
                  cs += (b1 << 8) + b2
              while cs >= 0x10000:
                  cs = (cs & 0xffff) + (cs >> 16)
              cs = ~cs & 0xffff
              return cs
          
          def ping(host, count=4, timeout=5000, interval=10, quiet=False, size=64):
              import utime
              import uselect
              import uctypes
              import usocket
              import ustruct
              import uos
          
              # prepare packet
              assert size >= 16, "pkt size too small"
              pkt = b'Q'*size
              pkt_desc = {
                  "type": uctypes.UINT8 | 0,
                  "code": uctypes.UINT8 | 1,
                  "checksum": uctypes.UINT16 | 2,
                  "id": (uctypes.ARRAY | 4, 2 | uctypes.UINT8),
                  "seq": uctypes.INT16 | 6,
                  "timestamp": uctypes.UINT64 | 8,
              } # packet header descriptor
              h = uctypes.struct(uctypes.addressof(pkt), pkt_desc, uctypes.BIG_ENDIAN)
              h.type = 8 # ICMP_ECHO_REQUEST
              h.code = 0
              h.checksum = 0
              h.id[0:2] = uos.urandom(2)
              h.seq = 1
          
              # init socket
              #sock = usocket.socket(usocket.AF_INET, usocket.SOCK_RAW, 1)
              sock = usocket.socket(usocket.AF_INET, 3, 1)
              sock.setblocking(0)
              sock.settimeout(timeout/1000)
              try:
                  addr = usocket.getaddrinfo(host, 1)[0][-1][0] # ip address
              except IndexError:
                  not quiet and print("Could not determine the address of", host)
                  return None
              sock.connect((addr, 1))
              not quiet and print("PING %s (%s): %u data bytes" % (host, addr, len(pkt)))
          
              seqs = list(range(1, count+1)) # [1,2,...,count]
              c = 1
              t = 0
              n_trans = 0
              n_recv = 0
              finish = False
              while t < timeout:
                  if t==interval and c<=count:
                      # send packet
                      h.checksum = 0
                      h.seq = c
                      h.timestamp = utime.ticks_us()
                      h.checksum = checksum(pkt)
                      if sock.send(pkt) == size:
                          n_trans += 1
                          t = 0 # reset timeout
                      else:
                          seqs.remove(c)
                      c += 1
          
                  # recv packet
                  while 1:
                      socks, _, _ = uselect.select([sock], [], [], 0)
                      if socks:
                          resp = socks[0].recv(4096)
                          resp_mv = memoryview(resp)
                          h2 = uctypes.struct(uctypes.addressof(resp_mv[20:]), pkt_desc, uctypes.BIG_ENDIAN)
                          # TODO: validate checksum (optional)
                          seq = h2.seq
                          if h2.type==0 and h2.id==h.id and (seq in seqs): # 0: ICMP_ECHO_REPLY
                              #t_elasped = (utime.ticks_us()-h2.timestamp) / 1000
                              t_elasped = utime.ticks_diff(h2.timestamp, utime.ticks_us()) / 1000
                              ttl = ustruct.unpack('!B', resp_mv[8:9])[0] # time-to-live
                              n_recv += 1
                              not quiet and print("%u bytes from %s: icmp_seq=%u, ttl=%u, time=%f ms" % (len(resp), addr, seq, ttl, t_elasped))
                              seqs.remove(seq)
                              if len(seqs) == 0:
                                  finish = True
                                  break
                      else:
                          break
          
                  if finish:
                      break
          
                  utime.sleep_ms(1)
                  t += 1
          
              # close
              sock.close()
              ret = (n_trans, n_recv)
              not quiet and print("%u packets transmitted, %u packets received" % (n_trans, n_recv))
              return (n_trans, n_recv)
          
          ping('google.com')
          
          
          F 1 Reply Last reply Reply Quote 0
          • F Offline
            fruiz1113 @kjm
            last edited by

            @kjm thanks for your reply , the problem was the pppsuspend/resume ,absolutely it hangs the modem for internet. The uping file and the ping file you have sent works properly.

            1 Reply Last reply Reply Quote 0

            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