<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[PYP SIM800L]]></title><description><![CDATA[<p dir="auto">After updating the devices to V6.2 UIflow still offers only 4.5 or beta and the <strong>pyb</strong> library is not available to access the UART for operating the SIM800L.<br />
Any hints?<br />
My first guess  - don't mix  German UIflow with English firmware but that was not the problem. The device stalls when trying to use either  of the module commands  PM2.5, Cellular, or Hardware-&gt;Power<br />
thanks</p>
]]></description><link>https://community.m5stack.com/topic/2198/pyp-sim800l</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 06:20:55 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/2198.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 12 Aug 2020 19:21:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to PYP SIM800L on Fri, 14 Aug 2020 17:44:11 GMT]]></title><description><![CDATA[<p dir="auto">Nothing spectacular</p>
<p dir="auto">either trials via module or the example do not work</p>
<p dir="auto">what  is the order to initiate GPRS transmition - upload to a server?</p>
<p dir="auto">This second attempt throws name 'pyb' isn't defined</p>
<p dir="auto">from m5stack import *<br />
from m5ui import *<br />
from uiflow import *<br />
import module</p>
<p dir="auto">setScreenColor(0x222222)</p>
<h1>Driver for SIM800L module (using AT commands)</h1>
<h1>MIT License; Copyright (c) 2017 Jeffrey N. Magee</h1>
<h1><a href="https://github.com/jeffmer/micropython-upyphone" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/jeffmer/micropython-upyphone</a></h1>
<p dir="auto">import math</p>
<h1>kludge required because "ignore" parameter to decode not implemented</h1>
<p dir="auto">def convert_to_string(buf):<br />
try:<br />
tt =  buf.decode('utf-8').strip()<br />
return tt<br />
except UnicodeError:<br />
tmp = bytearray(buf)<br />
for i in range(len(tmp)):<br />
if tmp[i]&gt;127:<br />
tmp[i] = ord('#')<br />
return bytes(tmp).decode('utf-8').strip()</p>
<p dir="auto">class SIM800LError(Exception):<br />
pass</p>
<p dir="auto">def check_result(errmsg,expected,res):<br />
if not res:<br />
res = 'None'<br />
#print(errmsg+res)<br />
if not expected == res and not res == 'None':<br />
raise SIM800LError('SIM800L Error {}  {}'.format(errmsg,res))</p>
<p dir="auto">class SIM800L:</p>
<pre><code>def __init__(self,uartno):  # pos =1 or 2 depending on skin position
    self._uart = pyb.UART(uartno, 9600, read_buf_len=2048)
    self.incoming_action = None
    self.no_carrier_action = None
    self.clip_action = None
    self._clip = None
    self.msg_action = None
    self._msgid = 0
    self.savbuf = None
    self.credit = ''
    self.credit_action = None
    
def callback_incoming(self,action):
    self.incoming_action = action

def callback_no_carrier(self,action):
    self.no_carrier_action = action

def callback_clip(self,action):
    self.clip_action = action

def callback_credit_action(self,action):
    self.credit_action = action

def get_clip(self):
    return self._clip
    
def callback_msg(self,action):
    self.msg_action = action

def get_msgid(self):
    return self._msgid

def command(self, cmdstr, lines=1, waitfor=500, msgtext=None):
    #flush input
    #print(cmdstr)
    while self._uart.any():
        self._uart.readchar()
    self._uart.write(cmdstr)
    if msgtext:
        self._uart.write(msgtext)
    # if waitfor&gt;1000:
    #    pyb.delay(waitfor-1000)
    buf=self._uart.readline() #discard linefeed etc
    #print(buf)
    buf=self._uart.readline()
    #print(buf)
    if not buf:
        return None
    result = convert_to_string(buf)
    if lines&gt;1:
        self.savbuf = ''
        for i in range(lines-1):
            buf=self._uart.readline()
            if not buf:
                return result
            #print(buf)
            buf = convert_to_string(buf)
            if not buf == '' and not buf == 'OK':
                self.savbuf += buf+'\n'
    return result

def setup(self):
    self.command('ATE0\n')         # command echo off
    self.command('AT+CRSL=99\n')   # ringer level
    self.command('AT+CMIC=0,10\n') # microphone gain
    self.command('AT+CLIP=1\n')    # caller line identification
    self.command('AT+CMGF=1\n')    # plain text SMS
    self.command('AT+CALS=3,0\n')  # set ringtone
    self.command('AT+CLTS=1\n')    # enabke get local timestamp mode
    self.command('AT+CSCLK=0\n')   # disable automatic sleep
    
def wakechars(self):
    self._uart.write('AT\n')        # will be ignored
    # pyb.delay(100)

def sleep(self,n):
    self.command('AT+CSCLK={}\n'.format(n))
        
def sms_alert(self):
    self.command('AT+CALS=1,1\n')  # set ringtone
    # pyb.delay(3000)
    self.command('AT+CALS=3,0\n')  # set ringtone

def call(self,numstr):
    self.command('ATD{};\n'.format(numstr))
    
def hangup(self):
    self.command('ATH\n')     
    
def answer(self):
    self.command('ATA\n')

def set_volume(self,vol):
    if (vol&gt;=0 and vol&lt;=100):
        self.command('AT+CLVL={}\n'.format(vol))

def signal_strength(self):
    result = self.command('AT+CSQ\n',3)
    if result:
        params=result.split(',')
        if not params[0] == '':
            params2 = params[0].split(':')
            if params2[0]=='+CSQ':
                x = int(params2[1])
                if not x == 99:
                    return(math.floor(x/6+0.5))
    return 0
    
def battery_charge(self):   
    result = self.command('AT+CBC\n',3,1500)
    if result:
        params=result.split(',')
        if not params[0] == '':
            params2 = params[0].split(':')
            if params2[0]=='+CBC':
                return int(params[1])
    return 0
    
def network_name(self):   
    result = self.command('AT+COPS?\n',3)
    if result:
        params=result.split(',')
        if not params[0] == '':
            params2 = params[0].split(':')
            if params2[0]=='+COPS':
                if len(params)&gt;2:
                    names = params[2].split('"')
                    if len(names)&gt;1:
                        return names[1]
    return ''


def read_sms(self,id):
    result = self.command('AT+CMGR={}\n'.format(id),99)
    if result:
        params=result.split(',')
        if not params[0] == '':
            params2 = params[0].split(':')
            if params2[0]=='+CMGR':
                number = params[1].replace('"',' ').strip()
                date   = params[3].replace('"',' ').strip()
                time   = params[4].replace('"',' ').strip()
                return  [number,date,time,self.savbuf]
    return None

def send_sms(self,destno,msgtext):
    result = self.command('AT+CMGS="{}"\n'.format(destno),99,5000,msgtext+'\x1A')
    if result and result=='&gt;' and self.savbuf:
        params = self.savbuf.split(':')
        if params[0]=='+CUSD' or params[0] == '+CMGS':
            return 'OK'
    return 'ERROR'

def check_credit(self):
    self.command('AT+CUSD=1,"*100#"\n')

def get_credit(self):
    return self.credit

def delete_sms(self,id):
    self.command('AT+CMGD={}\n'.format(id),1)
                 
def date_time(self):
    result = self.command('AT+CCLK?\n',3)
    if result:
        if result[0:5] == "+CCLK":
            return result.split('"')[1]
    return ''
    
def check_incoming(self): 
    if self._uart.any():
        buf=self._uart.readline()
        # print(buf)
        buf = convert_to_string(buf)
        params=buf.split(',')
        if params[0] == "RING":
            if self.incoming_action:
                self.incoming_action()
        elif params[0][0:5] == "+CLIP":
            params2 = params[0].split('"')
            self._clip = params2[1]
            if self.clip_action:
                self.clip_action()
        elif params[0][0:5] == "+CMTI":
            self._msgid = int(params[1])
            if self.msg_action:
                self.msg_action()
        elif params[0][0:5] == "+CUSD":
            if len(params)&gt;1:
                st = params[1].find('#')
                en = params[1].find('.',st)
                en = params[1].find('.',en+1)
                if st&gt;0 and en&gt;0:
                    self.credit = '£'+params[1][st+1:en]
                    if self.credit_action:
                        self.credit_action()
        elif params[0] == "NO CARRIER":
                self.no_carrier_action()


# http get command using gprs
def http_get(self,url,apn="giffgaff.com"):
    resp = None
    rstate = 0
    proto, dummy, surl = url.split("/", 2)
    is_ssl = 0
    if  proto == "http:":
        is_ssl = 0
    elif proto == "https:":
        is_ssl == 1
    else:
        raise ValueError("Unsupported protocol: " + proto)
    try:
        # open bearer context
        res = self.command('AT+SAPBR=3,1,"Contype","GPRS"\n')
        check_result("SAPBR 1: ",'OK',res)
        res = self.command('AT+SAPBR=3,1,"APN","{}"\n'.format(apn))
        check_result("SAPBR 2: ",'OK',res)
        res = self.command('AT+SAPBR=1,1\n',1,2000)
        check_result("SAPBR 3: ",'OK',res)
        # now do http request
        res = self.command('AT+HTTPINIT\n',1)
        check_result("HTTPINIT: ",'OK',res)
        res = self.command('AT+HTTPPARA="CID",1\n')
        check_result("HTTPPARA 1: ",'OK',res)
        res = self.command('AT+HTTPPARA="URL","{}"\n'.format(surl))
        check_result("HTTPPARA 2: ",'OK',res)
        res = self.command('AT+HTTPSSL={}\n'.format(is_ssl))
        check_result("HTTPSSL: ",'OK',res)
        res = self.command('AT+HTTPACTION=0\n')
        check_result("HTTPACTION: ",'OK',res)
        for i in range(20):  #limit wait to max 20 x readline timeout
            buf = self._uart.readline()
            if buf and not buf==b'\r\n':
                buf = convert_to_string(buf)
                #print(buf)
                prefix,retcode,bytes = buf.split(',')
                rstate = int(retcode)
                nbytes = int(bytes)
                break
        res = self.command('AT+HTTPREAD\n',1)
        buf = self._uart.read(nbytes)
        check_result("HTTPACTION: ",'+HTTPREAD: {}'.format(nbytes),res)
        if buf[-4:] == b'OK\r\n':  # remove final OK if it was read
            buf = buf[:-4]
        resp = Response(buf)
    except SIM800LError as err:
        print(str(err))
    self.command('AT+HTTPTERM\n',1) # terminate HTTP task
    self.command('AT+SAPBR=0,1\n',1) # close Bearer context
    return resp


def test(self):
    r = self.http_get('http://exploreembedded.com/wiki/images/1/15/Hello.txt')
    print(r.text)
</code></pre>
<p dir="auto">class Response:</p>
<pre><code>def __init__(self, buf, status = 200):
    self.encoding = "utf-8"
    self._cached = buf
    self.status = status

def close(self):
    self._cached = None

@property
def content(self):
    return self._cached

@property
def text(self):
    return str(self.content, self.encoding)

def json(self):
    import ujson
    return ujson.loads(self.content)        
</code></pre>
<p dir="auto">phone = SIM800L(1)<br />
print(phone.signal_strength())</p>
]]></description><link>https://community.m5stack.com/post/9657</link><guid isPermaLink="true">https://community.m5stack.com/post/9657</guid><dc:creator><![CDATA[Efried]]></dc:creator><pubDate>Fri, 14 Aug 2020 17:44:11 GMT</pubDate></item><item><title><![CDATA[Reply to PYP SIM800L on Thu, 13 Aug 2020 02:21:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/efried" aria-label="Profile: efried">@<bdi>efried</bdi></a>  if you want to use UART in UIFlow you could find the block in the Advanced category could you provide more detail?  we not clearly the problem you said.  which program are you used? the device salls? if you could share you code or block screenshot to here , will very helpful for us to find the proble .  also the language seting don't effect the program.</p>
]]></description><link>https://community.m5stack.com/post/9635</link><guid isPermaLink="true">https://community.m5stack.com/post/9635</guid><dc:creator><![CDATA[m5stack]]></dc:creator><pubDate>Thu, 13 Aug 2020 02:21:19 GMT</pubDate></item></channel></rss>