-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathexample_SIM800L.py
More file actions
47 lines (38 loc) · 1.61 KB
/
example_SIM800L.py
File metadata and controls
47 lines (38 loc) · 1.61 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
# ---------------------
# SIM800L example usage
# ---------------------
from SIM800L import Modem
import json
def example_usage():
print('Starting up...')
# Create new modem object on the right Pins
modem = Modem(MODEM_PWKEY_PIN = 4,
MODEM_RST_PIN = 5,
MODEM_POWER_ON_PIN = 23,
MODEM_TX_PIN = 26,
MODEM_RX_PIN = 27)
# Initialize the modem
modem.initialize()
# Run some optional diagnostics
#print('Modem info: "{}"'.format(modem.get_info()))
#print('Network scan: "{}"'.format(modem.scan_networks()))
#print('Current network: "{}"'.format(modem.get_current_network()))
#print('Signal strength: "{}%"'.format(modem.get_signal_strength()*100))
# Connect the modem
modem.connect(apn='web.omnitel.it', user='yourUser', pwd='yourPassword') #leave username and password empty if your network don't require them
print('\nModem IP address: "{}"'.format(modem.get_ip_addr()))
# Example GET
print('\nNow running demo http GET...')
url = 'http://checkip.dyn.com/'
response = modem.http_request(url, 'GET')
print('Response status code:', response.status_code)
print('Response content:', response.content)
# Example POST
print('Now running demo https POST...')
url = 'https://postman-echo.com/post'
data = json.dumps({'myparameter': 42})
response = modem.http_request(url, 'POST', data, 'application/json')
print('Response status code:', response.status_code)
print('Response content:', response.content)
# Disconnect Modem
modem.disconnect()