From 81441b1b4d6db702a7ca06982b68ab01cb0491f1 Mon Sep 17 00:00:00 2001 From: Alistair MacDonald Date: Tue, 28 Aug 2018 22:49:14 +0100 Subject: [PATCH 1/7] Big fix Don't check for callbacks while running a command. --- lib/sim800.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/sim800.py b/lib/sim800.py index 9f7d2ea..518ad86 100644 --- a/lib/sim800.py +++ b/lib/sim800.py @@ -29,6 +29,7 @@ callbacks = [] # Globals for remembering callback data clip = "" btpairing = '' +holdoffirq=False # Check if the SIM800 is powered up def ison(): @@ -119,6 +120,9 @@ def processbuffer(): # The same interface as and called by command() but without power so can be called from power() def command_internal(command="AT", response_timeout=default_response_timeout, required_response=None, custom_endofdata=None): global dirtybuffer + global holdoffirq + # Don't let the interupt process the buffer mid command + holdoffirq = True # Process anything remaining in the buffer processbuffer() # Send the command @@ -142,12 +146,14 @@ def command_internal(command="AT", response_timeout=default_response_timeout, re customcomplete = True # Check if we are done if complete and customcomplete: + holdoffirq = False return result # We ran out of time # set the dirty buffer flag is an out of date end of responcs cound end up in the buffer if required_response is None: dirtybuffer = True result.append("TIMEOUT") + holdoffirq = False return result # Send the command to set the default configuration to the SIM800 @@ -174,7 +180,7 @@ def power(onoroff, asyncro): if not asyncro and pwr_key_pin.value(): pwr_key_pin.off() time.sleep(3) - # Press the virtual power key if we are off + # Press the virtual power key if we are off if not (ison()==onoroff): pwr_key_pin.on() if not asyncro: @@ -217,7 +223,8 @@ def netlightscheduled_internal(pinstate): if pwr_key_pin.value() and ison(): poweron() # Check for incomming commands - processbuffer() + if holdoffirq==False: + processbuffer() # Netlight IRQ (called for polling uart) def netlightirq_internal(pinstate): @@ -463,7 +470,7 @@ def setoperator(mode, format=None, operator=None): if format is not None: params += "," + str(format) if operator is not None: - params += "," + str(operator) + params += ",\"" + str(operator) + "\"" command("AT+COPS=" + str(mode) + params, 120000) # Get the activity status (returns 0=ready, 2=unknown, 3=ringing, 4=call in progress) @@ -669,6 +676,8 @@ def btsppwrite(connection, data): # Receive data from a Bluetooth serial connection def btsppread(connection): command() + # Don't let the interupt process the buffer mid command + holdoffirq = True request = "AT+BTSPPGET=3," + str(connection) + "\n" uart.write(request) data = uart.read() @@ -677,6 +686,7 @@ def btsppread(connection): if uart.any()==0: break data += uart.read() + holdoffirq = False if not data.endswith("ERROR\r\n"): return data[len(request)+2:-6] else: @@ -770,6 +780,8 @@ def fscreate(filename): def fsreadpart(filename, size=256, start=0): mode=int(start>0) command() + # Don't let the interupt process the buffer mid command + holdoffirq = True request = "AT+FSREAD=" + str(filename) + "," + str(mode) + "," + str(size) + "," + str(start) + "\n" uart.write(request) data = uart.read() @@ -778,6 +790,7 @@ def fsreadpart(filename, size=256, start=0): if uart.any()==0: break data += uart.read() + holdoffirq = False if not data.endswith("ERROR\r\n"): return data[len(request)+2:-6] else: From ac4d65d74849330cc134410d89d6e41994be3109 Mon Sep 17 00:00:00 2001 From: Alistair MacDonald Date: Tue, 28 Aug 2018 23:12:57 +0100 Subject: [PATCH 2/7] Basic SMS reader app --- sms/main.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 sms/main.py diff --git a/sms/main.py b/sms/main.py new file mode 100644 index 0000000..2ef78cd --- /dev/null +++ b/sms/main.py @@ -0,0 +1,30 @@ +"""SMS app for reading and sending messages +""" +___name___ = "SMS" +___license___ = "MIT" +___dependencies___ = ["dialogs", "ugfx_helper", "app", "stack_nav", "sim800"] +___categories___ = ["System"] +___bootstrapped___ = True + +import sim800 +import ugfx_helper, ugfx +from app import * +from dialogs import * + +ugfx_helper.init() +ugfx.clear() + +menuset = [] +messages = sim800.listsms(4) + +for message in messages: + splitmessage = message.split(",") + menuset.insert(0, { "title" : splitmessage[5] + " " + splitmessage[4] + " from " + splitmessage[2], "index" : splitmessage[0] }) + +while True: + selection = prompt_option(menuset, text="Select message", select_text="Read", none_text="Exit") + if (selection): + message = sim800.readsms(selection["index"]) + notice(message, title=selection["title"]) + else: + break From 87053ff323b243e2062297d52d808064b1936c35 Mon Sep 17 00:00:00 2001 From: Alistair MacDonald Date: Tue, 28 Aug 2018 23:23:38 +0100 Subject: [PATCH 3/7] Basic phone app for testing This needs work but can dial a number. --- phone/main.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 phone/main.py diff --git a/phone/main.py b/phone/main.py new file mode 100644 index 0000000..83a0b45 --- /dev/null +++ b/phone/main.py @@ -0,0 +1,20 @@ +"""Phone app for baic calling functions +""" +___name___ = "Phone" +___license___ = "MIT" +___dependencies___ = ["dialogs", "ugfx_helper", "app", "stack_nav", "sim800"] +___categories___ = ["System"] +___bootstrapped___ = True + +import sim800 +import ugfx_helper, ugfx +from app import * +from dialogs import * + +ugfx_helper.init() +ugfx.clear() + +notocall = prompt_text("Number to call:") + +if (notocall): + sim800.call(notocall) From 2399c9c58959d7083d127c607d43c2151ebff90c Mon Sep 17 00:00:00 2001 From: Alistair MacDonald Date: Tue, 28 Aug 2018 23:28:58 +0100 Subject: [PATCH 4/7] Fix header for MK4 --- phone/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phone/main.py b/phone/main.py index 83a0b45..3f563cf 100644 --- a/phone/main.py +++ b/phone/main.py @@ -2,14 +2,14 @@ """ ___name___ = "Phone" ___license___ = "MIT" -___dependencies___ = ["dialogs", "ugfx_helper", "app", "stack_nav", "sim800"] +___dependencies___ = ["dialogs", "app", "sim800"] ___categories___ = ["System"] ___bootstrapped___ = True -import sim800 -import ugfx_helper, ugfx from app import * from dialogs import * +import sim800 +import ugfx_helper, ugfx ugfx_helper.init() ugfx.clear() From 5c528d141178cbf2858df623adb53bade94c6a47 Mon Sep 17 00:00:00 2001 From: Alistair MacDonald Date: Tue, 28 Aug 2018 23:35:45 +0100 Subject: [PATCH 5/7] Trying to fix headers --- sms/main.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sms/main.py b/sms/main.py index 2ef78cd..39c042b 100644 --- a/sms/main.py +++ b/sms/main.py @@ -1,15 +1,16 @@ """SMS app for reading and sending messages """ -___name___ = "SMS" +___name___ = "Phone" ___license___ = "MIT" -___dependencies___ = ["dialogs", "ugfx_helper", "app", "stack_nav", "sim800"] +___dependencies___ = ["app", "dialogs", "sim800", "ugfx_helper"] ___categories___ = ["System"] ___bootstrapped___ = True -import sim800 -import ugfx_helper, ugfx from app import * from dialogs import * +import ugfx +import ugfx_helper +import sim800 ugfx_helper.init() ugfx.clear() From 781eff06cca35af388fbedd5f2f2972d12a3d3aa Mon Sep 17 00:00:00 2001 From: Alistair MacDonald Date: Tue, 28 Aug 2018 23:35:49 +0100 Subject: [PATCH 6/7] Trying to fix headers --- phone/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phone/main.py b/phone/main.py index 3f563cf..d2fe6e5 100644 --- a/phone/main.py +++ b/phone/main.py @@ -2,14 +2,15 @@ """ ___name___ = "Phone" ___license___ = "MIT" -___dependencies___ = ["dialogs", "app", "sim800"] +___dependencies___ = ["app", "dialogs", "sim800", "ugfx_helper"] ___categories___ = ["System"] ___bootstrapped___ = True from app import * from dialogs import * +import ugfx +import ugfx_helper import sim800 -import ugfx_helper, ugfx ugfx_helper.init() ugfx.clear() From 52b28bbc1f470389eace912cef09feb16f7f45d4 Mon Sep 17 00:00:00 2001 From: Alistair MacDonald Date: Tue, 28 Aug 2018 23:44:23 +0100 Subject: [PATCH 7/7] Start the SIM800 at load --- phone/external.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 phone/external.py diff --git a/phone/external.py b/phone/external.py new file mode 100644 index 0000000..6104659 --- /dev/null +++ b/phone/external.py @@ -0,0 +1,4 @@ +"""Load the SIM800 library at start so it starts in the background while turning on +""" + +import sim800