├── .gitattributes ├── GPS.py ├── led_blink.py ├── led_button.py ├── A9G_SMS.py └── MQTT.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /GPS.py: -------------------------------------------------------------------------------- 1 | import gps 2 | import time 3 | 4 | gps.on() 5 | 6 | while True: 7 | print("Location", gps.get_location()) 8 | print("Satellites (tracked, visible)", gps.get_satellites()) 9 | time.sleep(1) -------------------------------------------------------------------------------- /led_blink.py: -------------------------------------------------------------------------------- 1 | import machine 2 | import time 3 | 4 | # Built-in blue LED on the pudding board 5 | led = machine.Pin(27, machine.Pin.OUT, 0) 6 | value = 1 7 | 8 | while(1): 9 | led.value(value) 10 | time.sleep(1) 11 | value = not value -------------------------------------------------------------------------------- /led_button.py: -------------------------------------------------------------------------------- 1 | import machine 2 | import time 3 | 4 | # Built-in blue LED on the pudding board 5 | led = machine.Pin(27, machine.Pin.OUT) 6 | but = machine.Pin(26, machine.Pin.IN) 7 | value = 1 8 | 9 | while(1): 10 | but_status = but.value() 11 | if but_status == 1: 12 | led.value(1) 13 | else: 14 | led.value(1) -------------------------------------------------------------------------------- /A9G_SMS.py: -------------------------------------------------------------------------------- 1 | import cellular 2 | import time 3 | 4 | global flag 5 | flag = 1 6 | 7 | def sms_handler(evt): 8 | global flag 9 | if evt == cellular.SMS_SENT: 10 | print("SMS sent") 11 | 12 | elif evt == cellular.SMS_RECEIVE: 13 | print("SMS received, attempting to read ...") 14 | ls = cellular.SMS.list() 15 | print(ls[-1]) 16 | flag = 0 17 | 18 | cellular.on_sms(sms_handler) 19 | cellular.SMS("+91xxxxxxxxxx", "Hello From A9G").send() 20 | 21 | print("Doing something important ...") 22 | while flag: 23 | time.sleep(1) 24 | 25 | print("Done!") -------------------------------------------------------------------------------- /MQTT.py: -------------------------------------------------------------------------------- 1 | import cellular 2 | import machine 3 | import time 4 | 5 | cellular.gprs("www", "", "") # ("apn_name","username","password") 6 | 7 | led_topic = " " 8 | sensor_topic = " " 9 | 10 | led = machine.Pin(27,machine.Pin.OUT) 11 | 12 | time_period = 6 13 | 14 | # Import mqtt (download client if necessary) 15 | try: 16 | from umqtt import simple 17 | except ImportError: 18 | import upip 19 | upip.install("micropython-umqtt.simple") 20 | from umqtt import simple 21 | 22 | def cb(led_topic, msg): # Callback function 23 | print('Received Data: Topic = {}, Msg = {}'.format(led_topic, msg)) 24 | recieved_data = str(msg,'utf-8') # Recieving Data 25 | if recieved_data=="0": 26 | led.value(0) 27 | if recieved_data=="1": 28 | led.value(1) 29 | 30 | # Report location 31 | name = "a9g-micropython-board" 32 | server = "io.adafruit.com" 33 | port = 1883 34 | username = " " 35 | password = " " 36 | 37 | 38 | client = simple.MQTTClient(name, server, port, username, password ) 39 | client.connect() 40 | 41 | client.set_callback(cb) # Callback function 42 | client.subscribe(led_topic) # Subscribing to particular topic 43 | 44 | def send_sensor(): 45 | msg = "100" 46 | print('Sending Data: Topic = {}, Msg = {}'.format(sensor_topic, msg)) 47 | client.publish(sensor_topic, msg) 48 | 49 | while True: 50 | for x in range(time_period): 51 | for x in range(10): 52 | client.check_msg() 53 | time.sleep(0.1) 54 | send_sensor() 55 | 56 | --------------------------------------------------------------------------------