[Solved]:FiPy socket.connect command

  • Thanks a ton @jmarcelino. My problem is solved, added the following right after lte.connect(cid=3), and before s=socket.socket....

    while not lte.isconnected():

    and edited the s.connect to :

    address = socket.getaddrinfo('',4949) #update with you own server IP, 

    One minor problem still exists, which I need to look investigate further...maybe tomorrow, the code works once...top to bottom as expected , but if I press "reset" the code executes again as expected, but modem fails to attach...CSQ is 99,99. So far I have seen, if I do power-down-up it works again...but not with reset. Maybe I should run it in loop every 5-10 minutes and check.

    @administrators, @jmarcelino
    Per my last forum topic: https://forum.pycom.io/topic/3201/solved-fipy-cat-m1-connection
    I am able to connect to the Verizon network with my FiPy, but as I modified the code to post data to my server I am getting an unexpected error with s.connect((host,port)). I even tried
    s.connect(addr) instead of s.connect((host,port)) but same error each time.
    Here is my code block and error

    from network import LTE
    #from socket import *
    import socket
    import ssl
    import time
    import sys
    import pycom 
    host='abc.dyndns.org' # replaced actual host name portion with "abc"
    print('Pycom module and firmware version:%s' % os.uname())
    lte = LTE(carrier="verizon")  # instantiate the LTE object
    lte.attach(band=13)   # attach the cellular modem to a base station, initially it was lte.attch()
    print('FiPY is attached to network')
    pycom.rgbled(0x0000ff) # BLUE LED
    while not lte.isattached():
        print('While not attached yet, signal:%s'%lte.send_at_cmd('AT+CSQ'))
        print('While not attached yet, status:%s '%lte.send_at_cmd('AT+CEER'))
        time.sleep(.25)  # originally 0.25 changed to 5.0 if unseccful in connecting
    lte.connect(cid=3)       # start a data session and obtain an IP address
    print('Connected to LTE-CATM1')
    pycom.rgbled(0x00ff00) # GREEN LED
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    print('Socket created')
    #s.connect((host, port))  # tried this as well
    print('Socket Bind Complete....moving to send data  ')
    #print('Received:, repr(data)')
    pycom.rgbled(0xff0000) # RED LED
    print( " Reached EOP")

    Terminal output:

    >>> os.mkfs('/flash')
    Uploading project (main folder)...
    Reading file status
    Failed to read project status, uploading all files
    Creating dir workspaceStorage
    Creating dir workspaceStorage/bc895fb1973b5d5624b4a2ed2625b38c
    Creating dir workspaceStorage/d0c7d1ef2572273c369bbcf44005cf73
    [1/5] Writing file main.py
    [2/5] Writing file pymakr.json
    [3/5] Writing file settings.json
    [4/5] Writing file workspaceStorage/bc895fb1973b5d5624b4a2ed2625b38c/meta.json
    [5/5] Writing file workspaceStorage/d0c7d1ef2572273c369bbcf44005cf73/meta.json
    Upload done, resetting board...
    ets Jun  8 2016 00:22:57
    rst:0x7 (TG0WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    mode:DIO, clock div:1
    entry 0x400a059c
    Pycom module and firmware version:(sysname='FiPy', nodename='FiPy', release='1.17.3.b1', version='v1.8.6-849-83e2f7f on 2018-03-19', machine='FiPy with ESP32', lorawan='1.0.2', sigfox='1.0.1')
    FiPy is attached to network
    Connected to LTE-CATM1
    Socket created
    Traceback (most recent call last):
      File "main.py", line 36, in <module>
    ValueError: invalid arguments
    MicroPython v1.8.6-849-83e2f7f on 2018-03-19; FiPy with ESP32
    Type "help()" for more information.

    Please advise.Thanks much!!

  • Hi @dda

    socket.connect doesn't take a domain name, you need to resolve it first into a tuple like this - (family, type, proto, canonname, sockaddr) - which you can obtain from socket.getaddrinfo()

    In your case doing:

    s.connect(socket.getaddrinfo(addr, port)[0][-1])

    should do what you want.

    There currently isn't a way to obtain your assigned IP address.

  • @administrators @jmarcelino @daniel @robert-hh @timh
    Any body any suggestions, I am still stuck! Thanks

  • Also, once connected how do I find the assigned IP address of the FiPy? Use AT+CGPIAF?

Pycom on Twitter