Skip to content

Commit d0a129a

Browse files
author
brentru
committed
add simpletest mirroring w5k simpletest
1 parent f3ce21d commit d0a129a

File tree

3 files changed

+28
-106
lines changed

3 files changed

+28
-106
lines changed

adafruit_fona/adafruit_fona.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ def _set_gps(self, gps_on=False):
485485
self._read_line()
486486
if self._fona_type == FONA_808_V2:
487487
# try GNS
488-
print("trying GNS...")
489488
if not self._send_check_reply(b"AT+CGNSPWR=1", reply=REPLY_OK):
490489
return False
491490
else:

examples/fona_simpletest.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
import busio
44
import digitalio
55
from adafruit_fona.adafruit_fona import FONA
6-
import adafruit_fona.adafruit_fona_socket as socket
6+
import adafruit_fona.adafruit_fona_socket as cellular_socket
7+
import adafruit_requests as requests
78

8-
SERVER_ADDRESS = ("wifitest.adafruit.com", 80)
9+
print("FONA WebClient Test")
10+
11+
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
12+
JSON_URL = "http://api.coindesk.com/v1/bpi/currentprice/USD.json"
913

1014
# Get GPRS details and more from a secrets.py file
1115
try:
@@ -21,7 +25,7 @@
2125
rst = digitalio.DigitalInOut(board.D4)
2226

2327
# Initialize FONA module (this may take a few seconds)
24-
fona = FONA(uart, rst, debug=True)
28+
fona = FONA(uart, rst)
2529

2630
print("Adafruit FONA WebClient Test")
2731

@@ -34,31 +38,28 @@
3438
# Bring up GPRS
3539
fona.gprs = True
3640

37-
# Set socket interface
38-
socket.set_interface(fona)
39-
40-
sock = socket.socket()
41-
42-
print("Connecting to: ", SERVER_ADDRESS[0])
43-
sock.connect(SERVER_ADDRESS)
41+
# Initialize a requests object with a socket and cellular interface
42+
requests.set_socket(cellular_socket, fona)
4443

45-
print("Connected to:", sock.getpeername())
46-
time.sleep(7)
44+
print("My IP address is:", fona.local_ip)
45+
print(
46+
"IP lookup adafruit.com: %s" % fona.get_host_by_name("adafruit.com")
47+
)
4748

48-
# Make a HTTP Request
49-
sock.send(b"GET /testwifi/index.html HTTP/1.1\n")
50-
sock.send(b"Host: 104.236.193.178")
51-
sock.send(b"Connection: close\n\n")
49+
fona._debug = True
50+
print("Fetching text from", TEXT_URL)
51+
r = requests.get(TEXT_URL)
52+
print("-" * 40)
53+
print(r.text)
54+
print("-" * 40)
55+
r.close()
5256

53-
bytes_avail = 0
54-
while not bytes_avail:
55-
bytes_avail = sock.available()
56-
if bytes_avail > 0:
57-
print("bytes_avail: ", bytes_avail)
58-
data = sock.recv(bytes_avail)
59-
print(data.decode())
60-
break
61-
time.sleep(0.05)
57+
print()
58+
print("Fetching json from", JSON_URL)
59+
r = requests.get(JSON_URL)
60+
print("-" * 40)
61+
print(r.json())
62+
print("-" * 40)
63+
r.close()
6264

63-
sock.close()
64-
print("Socket connected: ", sock.connected)
65+
print("Done!")

examples/fona_simpletest_requests.py

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)