[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(): time.sleep(0.25)
and edited the s.connect to :
address = socket.getaddrinfo('18.104.22.168',4949) #update with you own server IP, print(address) s.connect(address[-1])
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.
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" port=4949 addr=(host,port) pycom.heartbeat(False) 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') time.sleep(0.25) pycom.rgbled(0x0000ff) # BLUE LED while not lte.isattached(): print('While not attached yet, signal:%s'%lte.send_at_cmd('AT+CSQ')) lte.send_at_cmd('AT+CSQ') print('While not attached yet, status:%s '%lte.send_at_cmd('AT+CEER')) lte.send_at_cmd('AT+CEER') time.sleep(.25) # originally 0.25 changed to 5.0 if unseccful in connecting lte.attach(band=13) 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.settimeout(5.0) #s.connect((host, port)) # tried this as well s.connect(addr) print('Socket Bind Complete....moving to send data ') #s.listen(10) s.send('1~660832~05/08/1501:00A0A141E28323C4650~') #data=s.recv(1024) s.close() #print('Received:, repr(data)') lte.disconnect() lte.dettach() pycom.rgbled(0xff0000) # RED LED print( " Reached EOP")
>>> 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 clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:1 load:0x3fff8028,len:8 load:0x3fff8030,len:1728 load:0x4009fa00,len:0 load:0x4009fa00,len:14584 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!!
jmarcelino last edited by jmarcelino
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:
should do what you want.
There currently isn't a way to obtain your assigned IP address.
Also, once connected how do I find the assigned IP address of the FiPy? Use AT+CGPIAF?