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))
Esempio n. 2
0
    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("Connected !")
addr = socket.getaddrinfo('loboris.eu', 80)[0][-1]
s = socket.socket()
s.connect(addr)
s.send(b'GET /ESP32/info.txt HTTP/1.1\r\nHost: loboris.eu\r\n\r\n')
data = s.recv(1000)
print('data=', end='')
print(data)
s.close()

# GSM connection is complete.
# You can now use modules like urequests, uPing, etc.
# Let's try socket API:
Esempio n. 3
0
 def gsm_connect(self):
     import gsm
     gsm.connect()
     while gsm.status()[0] != 1:
         pass
     LOG.info('IP: %s' % gsm.ifconfig()[0])
Esempio n. 4
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()