def runit():

    # APN credentials (replace with yours)

    GSM_APN = 'wholesale'  # 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_MODEM_PWR = machine.Pin(23, machine.Pin.OUT)

    GSM_PWR.value(0)
    GSM_RST.value(1)
    GSM_MODEM_PWR.value(1)
    print("Here we go!")

    # 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(30):
        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])

    print("Making get request...")
    response = urequests.get("https://bot.whatismyipaddress.com")
    print(response.text)
    gsm.disconnect()
    gsm.sendSMS("+1xxxx", "My public ip is: {}".format(response.text))
Example #2
0
    def gsm_start(self, apn_settings):
        import gsm
        gsm.debug(True)  # see more logs, investigate issues, etc.

        gsm.start(tx=self._conf['gsm_modem']['tx'],
                  rx=self._conf['gsm_modem']['rx'],
                  **apn_settings)

        sys.stdout.write('Waiting for AT command response...')
        for retry in range(20):
            machine.resetWDT()
            if gsm.atcmd('AT'):
                return True
            else:
                sys.stdout.write('.')
                utime.sleep(5)
        else:
            sys.stdout.write("Modem not responding!")
            machine.reset()
Example #3
0
GSM_PASS = ''  # Your Pass

# Power on the GSM module
GSM_PWR = machine.Pin(4, machine.Pin.OUT)
GSM_PWR.value(1)
time.sleep_ms(300)
GSM_PWR.value(0)

LED = machine.Pin(12, machine.Pin.OUT)
LED.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()
Example #4
0
import t
import gsm
import machine

t.modemOnOffNew()
#gsm.start(tx=5, rx=35, apn='internet', connect=False)
gsm.start(tx=5, rx=35, apn='internet', connect=False, user='******', password='******')
gsm.connect()
gsm.status()
gsm.stop()
uart = machine.UART(1, tx=5, rx=35)
#uart.write('AT\r\n')
recipient = "+393406440781"
message = "Hello, F1neye!"

try:
    time.sleep(0.5)
    #uart.write(b'ATZ\r\n')
    uart.write('ATZ\r\n')
    time.sleep(0.5)
    uart.write('AT+CMGF=1\r\n')
    time.sleep(0.5)
    uart.write('AT+CMGS="' + recipient + '"\r\n')
    time.sleep(0.5)
    uart.write(message + "\r\n")
    time.sleep(0.5)
    uart.write(bytes([26]))
    time.sleep(0.5)
finally:
    uart.close()
Example #5
0
import gc
import network
import time
#import ntptime
import machine
import utime
import gsm

#
# ap = network.WLAN(network.AP_IF) # create access-point interface
# ap.config(essid='ESP32F') # set the ESSID of the access point
# ap.active(True)         # activate the interface


#gsm.start(tx=27, rx=21, apn='ctnet', connect = True)
gsm.start(tx=27, rx=21, apn='ctnet')

# wlan = network.WLAN(network.STA_IF)
# wlan.active(True)
# #time.sleep(2)
# wlan.connect('XiaoPiDan', 'asdfzxcv123')
# time.sleep(3)
# if wlan.isconnected() == True:
#     print('alread connect')
# else:
#     wlan.connect('ZMI_E9C0', '63254450')
#     time.sleep(3)

#set time
rtc = machine.RTC()
rtc.ntp_sync(server="hr.pool.ntp.org", tz="CCT-8")
Example #6
0
import gsm, json
from network import mqtt

gsm.debug(True)
gsm.start(tx=17, rx=16, apn="TM", roaming=True, wait=True)
gsm.connect()
gsm.status()
gsm.ifconfig()
client = mqtt("test1",
              "calupietru.duckdns.org",
              port=1883,
              user="******",
              password="******")
client.start()
message = {
    "espid": "Prato",
    "timestamp": None,
    "temperatura": 23,
    "peso": 70.1
}
client.publish("/maia/4", json.dumps(message))
client.publish("/maia/4", json.dumps(message))
client.stop()
gsm.disconnect()
Example #7
0
This example shows how to initialize your ESP32 board
and connect it to Blynk using a Cellular modem.

Read more about LoBo GSM module here:
  https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/gsm

Don't forget to change TX/RX pins, APN, user, password and BLYNK_AUTH ;)
"""

import BlynkLib
import gsm
import machine, time

BLYNK_AUTH = 'YourAuthToken'

gsm.start(tx=27, rx=26, apn='', user='', password='')

for retry in range(10):
    if gsm.atcmd('AT'):
        break
    else:
        print("Waiting modem")
        time.sleep_ms(5000)
else:
    raise Exception("Modem not responding!")

print("Connecting to GSM...")
gsm.connect()

while gsm.status()[0] != 1:
    pass
Example #8
0
    MODEM_RST.value(1)

GSM_PWR = machine.Pin(MODEM_PWRKEY_PIN, machine.Pin.OUT)
GSM_PWR.value(1)
time.sleep_ms(200)
GSM_PWR.value(0)
time.sleep_ms(1000)
GSM_PWR.value(1)

# Init PPPoS

gsm.debug(True)  # Uncomment this to see more logs, investigate issues, etc.

gsm.start(tx=MODEM_TX,
          rx=MODEM_RX,
          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...")