-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsocketTest.py
More file actions
51 lines (42 loc) · 1.22 KB
/
socketTest.py
File metadata and controls
51 lines (42 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from CZCATM1.CATM1 import CATM1
import time
import RPi.GPIO as GPIO
node = CATM1()
#Wait for the LTE Network to connect
time.sleep(2)
while True:
if node.isAttachNetwork():
print("Network connect")
break
else:
print("Network disconnect")
print("Activate PDP Context: " + node.attachNetwork())
print("myIP: " + node.myIP())
#UDP Socket Test
socketNum = 0
if node.openSocket(socketNum, 0, "\"echo.mbedcloudtesting.com\"", 7):
print("UDP Socket Open")
else:
print("UDP Socket Open Error")
node.sendSCKData(socketNum, "Hello World")
print(">>> UDP Test Result : " + node.receiveSCKData(socketNum))
if node.closeSocket(socketNum):
print("UDP Socket Close")
else:
print("UDP Socket Close Error")
#TCP Socket Test
if node.openSocket(socketNum, 1, "\"echo.mbedcloudtesting.com\"", 7):
print("TCP Socket Open")
else:
print("TCP Socket Open Error")
node.sendSCKData(socketNum, "Hello World")
print(">>> TCP Test Result : " + node.receiveSCKData(socketNum))
if node.closeSocket(socketNum):
print("TCP Socket Close")
else:
print("TCP Socket Close Error")
#Deactiveate Network
print("Deactivate PDP Context: " + node.attachNetwork(False))
time.sleep(2)
#program End
GPIO.cleanup()