1+ import time
2+ import board
3+ import busio
4+ import digitalio
5+ from adafruit_fona .adafruit_fona import FONA
6+ import adafruit_fona .adafruit_fona_socket as cellular_socket
7+ import adafruit_requests as requests
8+
9+ # Get GPRS details and more from a secrets.py file
10+ try :
11+ from secrets import secrets
12+ except ImportError :
13+ print ("GPRS secrets are kept in secrets.py, please add them there!" )
14+ raise
15+
16+ # Create a serial connection for the FONA connection using 4800 baud.
17+ # These are the defaults you should use for the FONA Shield.
18+ # For other boards set RX = GPS module TX, and TX = GPS module RX pins.
19+ uart = busio .UART (board .TX , board .RX , baudrate = 4800 )
20+ rst = digitalio .DigitalInOut (board .D4 )
21+
22+ # Initialize FONA module (this may take a few seconds)
23+ print ("Initializing FONA" )
24+ fona = FONA (uart , rst )
25+
26+ # Enable GPS
27+ fona .gps = True
28+
29+ # Bring up cellular connection
30+ fona .configure_gprs ((secrets ["apn" ], secrets ["apn_username" ], secrets ["apn_password" ]))
31+
32+ # Bring up GPRS
33+ fona .gprs = True
34+ print ("FONA initialized" )
35+
36+ # Initialize a requests object with a socket and cellular interface
37+ requests .set_socket (cellular_socket , fona )
38+
39+ counter = 0
40+
41+ while True :
42+ print ("Posting data..." , end = "" )
43+ data = counter
44+ feed = "test"
45+ payload = {"value" : data }
46+ response = requests .post (
47+ "http://io.adafruit.com/api/v2/"
48+ + secrets ["aio_username" ]
49+ + "/feeds/"
50+ + feed
51+ + "/data" ,
52+ json = payload ,
53+ headers = {"X-AIO-KEY" : secrets ["aio_key" ]},
54+ )
55+ print (response .json ())
56+ response .close ()
57+ counter = counter + 1
58+ print ("OK" )
59+ response = None
60+ time .sleep (15 )
0 commit comments