pycom / pycom-micropython-sigfox

A fork of MicroPython with the ESP32 port customized to run on Pycom's IoT multi-network modules.
MIT License
199 stars 167 forks source link

GPy Board: Failing to send data accross when in bridge mode #340

Open syedaliiaos opened 5 years ago

syedaliiaos commented 5 years ago

Hi,

I am using GPy board to have an IOT device connect to it via WIFI and have internet connectivity on the device via LTE-M connection. Here is what I have done so far:

  1. At power up, the GPy board comes up as WIFI AP (default).
  2. I can successfully connect to the Verizon Cellular Network as evident by 'isconnected' and 'isattached' commands coming as TRUE.
  3. I have written a socket server which does the following: a. Listens to incoming client sockets and accepts the connection. b. Whatever data is received from the sockets and it is sent out.
  4. At this point, I can connect my cell phone to GPY WIFI AP. (I can see the socket connection being accepted in log.)
  5. But I am not getting any internet connectivity on my cell phone i.e. I cannot load emails, web pages etc.
  6. Any idea what might be happening? My suspicion is that there is something missing in my socket server implementation. I read data from sockets and write the received data back to sockets. But am I really sending data out to the LTE-M socket? Not sure.
  7. Please let me know what do you guys think?
  8. My socket server code is below along with the FW version.
  9. Any help is much appreciated!

Thanks, SYED

===========================================

import os os.uname() (sysname='GPy', nodename='GPy', release='1.20.0.rc13', version='v1.9.4-94bb382 on 2019-08-22', machine='GPy with ESP32')

===========================================

import socket import ssl import time import sys import select

from network import LTE

lte = LTE(carrier="verizon", cid=3) # instantiate the LTE object lte.attach(band=13, apn="VZWINTERNET", type=LTE.IP) # attach the cellular modem to a base station

while not lte.isattached(): time.sleep(0.25) print('Attaching...') print ('Attached!')

lte.connect() # start a data session and obtain an IP address

while not lte.isconnected(): time.sleep(0.25) print('Connecting...') print ('Connected!')

CONNECTION_LIST = [] # list of socket clients RECV_BUFFER = 1024 # Advisable to keep it as an exponent of 2 PORT = 8888

Create socket

server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) print ('Server socket created')

Bind socket

server_socket.bind(('', PORT)) print ('Server socket bind')

Listen socket

server_socket.listen(1) print ('Server socket listen')

Add server socket to the list of readable connections

CONNECTION_LIST.append(server_socket)

while 1:

Get the list sockets which are ready to be read through select

read_sockets,write_sockets,error_sockets = select.select(CONNECTION_LIST,[],[])

for sock in read_sockets:       
    #New connection
    if sock == server_socket:
        #Handle the case in which there is a new connection received through server_socket
        client_socket, addr = server_socket.accept()
        CONNECTION_LIST.append(client_socket)
        print ('Client socket connected @ ' + addr[0] + ':' + str(addr[1]))

    #Some incoming message from a client
    else:
        data = sock.recv(RECV_BUFFER)
        #echo back the client message
        if data:
            sock.send(data)

        #client disconnected, so remove from socket list
        else:
            sock.close()
            print ('Client socket removed')
            CONNECTION_LIST.remove(sock)

server_socket.close() print ('Socket closed')

joschi36 commented 4 years ago

Hey I'm intrested in doing the same, did you get it running? I want to bridge mainly MQTT.