forked from alokshaw/TTGO-T-Call
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
74 lines (54 loc) · 1.69 KB
/
main.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'''
Using your phone:
- Disable PIN code on the SIM card
- Check your balance
- Check that APN, User, Pass are correct and you have internet
Ensure the SIM card is correctly inserted into the board
Ensure that GSM antenna is firmly attached
NOTE: While GSM is connected to the Internet, WiFi can be used only in AP mode
More docs on GSM module here:
https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/gsm
Author: Volodymyr Shymanskyy
'''
import machine, time, sys
import gsm
# APN credentials (replace with yours)
GSM_APN = '' # Your APN
GSM_USER = '' # Your User
GSM_PASS = '' # Your Pass
# Power on the GSM module
GSM_PWR = machine.Pin(4, machine.Pin.OUT)
GSM_RST = machine.Pin(5, machine.Pin.OUT)
GSM_PWR.value(0)
GSM_RST.value(1)
# Init PPPoS
#gsm.debug(True) # Uncomment this to see more logs, investigate issues, etc.
gsm.start(tx=27, rx=26, apn=GSM_APN, user=GSM_USER, password=GSM_PASS)
sys.stdout.write('Waiting for AT command response...')
for retry in range(20):
if gsm.atcmd('AT'):
break
else:
sys.stdout.write('.')
time.sleep_ms(5000)
else:
raise Exception("Modem not responding!")
print()
print("Connecting to GSM...")
gsm.connect()
while gsm.status()[0] != 1:
pass
print('IP:', gsm.ifconfig()[0])
# GSM connection is complete.
# You can now use modules like urequests, uPing, etc.
# Let's try socket API:
import socket
addr_info = socket.getaddrinfo("towel.blinkenlights.nl", 23)
addr = addr_info[0][-1]
s = socket.socket()
s.connect(addr)
while True:
data = s.recv(500)
print(str(data, 'utf8'), end='')
# You should see terminal version of StarWars episode
# Just like this: https://asciinema.org/a/1457