Using a API to send out a SMS



  • After running this code, I get no errors only a blank screen. Could anyone tell what I did wrong at first glance?

    from m5stack import *
    from m5ui import *
    from uiflow import *

    fields = {
    'from': 'PythonElk',
    'to': '+XXXXXXXX',
    'message': 'Test Message To your phone.'
    }
    try:
    req = urequests(
    method='POST',
    url='https://api.46elks.com/a1/SMS',
    headers=fields,
    data={'XXXXXXXXXXXXXXXXXXXXX',' YYYYYYYYYYYYYYYYYYYY'}
    )
    except Exception as e:
    print(e)
    import urequests
    import ujson
    setScreenColor(0x111111)
    auth = (
    'XXXXXXXXXXXXXXXXXXXXXXXX',
    'YYYYYYYYYYYYYYYYYYYYYY'
    )
    fields = {
    'from': 'PythonElk',
    'to': '+XXXXXXXX',
    'message': 'Test Message To your phone.'
    }
    headers = {'Content-Type': 'application/json'}
    try:
    #urequests.request(method='POST', url='https://api.46elks.com/a1/SMS', auth, fields,headers
    post_data = ujson.dumps('XXXXXXXXXXXXXXXXXXXXXXX','YYYYYYYYYYYYYYYYYYYYYYYYYYY')
    request_url = 'https://api.46elks.com/a1/SMS'
    res = requests.post(request_url, headers = {'content-type': 'application/json'}, data = post_data,json=fields)
    print(res)

    req = urequests.request(method='POST', url="import urequests setScreenColor(0x222222) fields = { 'from': 'PythonElk', 'to': '+XXXXXXX', 'message': 'Test Message To your phone.' } try: req = urequests.request( method='POST', url='https://api.46elks.com/a1/SMS', headers=fields, data=('XXXXXXXXXXXXXXXX','YYYYYYYYYYYYYYYYYYYYY') ) except: print(req.status_code)",json={'user':'a'}, headers={})

    except Exception as e:
    print(e)



  • I do not see any GUI objects required to show text on the screen. I only see code that runs in the background.



  • Me and a friend of mine figured out how to do a HTTP post with parameters in micropython. Me used it for sending SMS, but it can be modified to anything else.
    https://forum.m5stack.com/topic/1902/http-post-from-arduino-esp8266-esp32-how-to-send-parameters-x-www-form-urlencoded-using-micropython/3