Particle Electron -- Help using socket library.... set socket to DGRAM


#1

I am able to connect to cellular network.
I can get IP of Zerynth.com
But…

sock = socket.socket(type=socket.SOCK_DGRAM) gives errors

###################################################################################
try:
    # connect to our APN
    gsm.connect_net(‘xxxxxxxx’)
except Exception as e:
    print(“ooops, something wrong while connecting :(”, e)

    sleep(1000)
print(“g350.actived()”)
print (g350.activated())
print(g350.gethostbyname(“zerynth.com”))
sleep(2000)
    
try:    
# create a tcp socket
    print(“sock = socket.socket(type=socket.SOCK_DGRAM)”)
    sock = socket.socket(type=socket.SOCK_DGRAM)

# connect the socket to net address XXX.XXX.XXX.XXX port 7777
    print(“sock.connect((“XXX.XXX.XXX.XXX”,7777))”)
    sock.connect((“34.202.239.150”,7777))

# send something on the socket!
    print(" sock.sendato(“55”)")
    sock.sendto(“55”)   
except Exception as e:   
    print(“ooops, not send :(”, e)
###################################################################################

<div><span>Debug =<b> True</b> of G350.py</span><br>g350.actived()<br><br>True</div><div>cmd: &nbsp;AT+UDNSRN=0,"zerynth.com"</div><div>-1</div><div>-1</div><div>-1</div><div>-1</div><div>-1</div><div>-1</div><div>+UDNSRN: "108.167.183.127"</div><div>OK</div><div>108.167.183.127</div><div>sock = socket.socket(type=socket.SOCK_DGRAM)</div><div>cmd: &nbsp;AT+USOCTL=0,1</div><div>-1</div><div>+CME ERROR: operation not allowed</div><div>cmd: &nbsp;AT+USOCTL=1,1</div><div>-1</div><div>+CME ERROR: operation not allowed</div><div>cmd: &nbsp;AT+USOCTL=2,1</div><div>-1</div><div>+CME ERROR: operation not allowed</div><div>cmd: &nbsp;AT+USOCTL=3,1</div><div>-1</div><div>+CME ERROR: operation not allowed</div><div>cmd: &nbsp;AT+USOCTL=4,1</div><div>-1</div><div>+CME ERROR: operation not allowed</div><div>cmd: &nbsp;AT+USOCTL=5,1</div><div>-1</div><div>+CME ERROR: operation not allowed</div><div>cmd: &nbsp;AT+USOCTL=6,1</div><div>-1</div><div>+CME ERROR: operation not allowed</div><div>sock.connect(("XXX.XXX.XXX.XXX",7777))</div><div>cmd: &nbsp;AT+USOCO=None,"XXX.XXX.XXX.XXX",7777</div><div>-1</div><div>+CME ERROR: operation not supported</div><div>ooops, not send :( g350Exception @[00A4:0064:0000:0000:0000:0000:0000:0000]</div><div><br></div>

#2

Hello @pmjackson ,

thanks for your report. It seems there is a bug in g350 library for UDP.
We are running tests to spot other related issues, however in the meantime you can try this (untested) patch: open the g350 driver at dist/r2.0.9/libs/official/ublox/g350/g350.py and add modify from line 687 with this:


                    self.send(“AT+USOCR=17”)
                    r = self.wait_resp(callback = self._handle_usocr)
                    if r[0] != RESP_OK:
                        break
                    self._sockets[i] = _sockdata(proto,i)
                    self._sockets[i].channel = r[1]
</div><div><br></div>Let me know if this solves the issue. We will release a bugfix asap.</span>


#3

Hello @Giacomo,

I tried the patch, it allowed the firmware to run to the next socket command but still has g350Exception.

cmd:  AT+USOCTL=0,1
-1
+CME ERROR: operation not allowed
cmd:  AT+USOCTL=1,1
-1
+CME ERROR: operation not allowed
cmd:  AT+USOCTL=2,1
-1
+CME ERROR: operation not allowed
cmd:  AT+USOCTL=3,1
-1
+CME ERROR: operation not allowed
cmd:  AT+USOCTL=4,1
-1
+CME ERROR: operation not allowed
cmd:  AT+USOCTL=5,1
-1
+CME ERROR: operation not allowed
cmd:  AT+USOCTL=6,1
-1
+CME ERROR: operation not allowed
sock1
cmd:  AT+USOCO=None,“XXX.XXX.XXX.XXX”,7777
-1
+CME ERROR: operation not supported
sock connecting :( g350Exception @[00A4:0064:0000:0000:0000:0000:0000:0000]