From a19445f862fcff09cbf8829c9ea8d5c1cad851e3 Mon Sep 17 00:00:00 2001 From: Sam Machin Date: Tue, 11 Sep 2018 19:04:26 +0100 Subject: [PATCH] Update sim800.py Added GPRS support, `setup_gprs()` will prepare the sim800 for data, `connect_gprs("hologram")` will connect to the hologram APN Also added a function to start a tcp server on the SIM 800 using `start_server(4010)` to listen on port 4010, the payload will be a binary object passed to whatever is defined as `server_callback` --- lib/sim800.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/sim800.py b/lib/sim800.py index 1c26ff8..8db26f5 100644 --- a/lib/sim800.py +++ b/lib/sim800.py @@ -108,10 +108,10 @@ def processcallbacks(line): btpairing = line[11:].strip() # Handle TCP Server Data if line.startswith("+RECEIVE"): - dlen = int(line.split(",")[2].rstrip(":")) + dlen = int(line.split(",")[2].rstrip(":"))+1 payload = uart.read(dlen) if server_callback: - micropython.schedule(server_callback, payload) + micropython.schedule(server_callback, payload[1:]) # Check for app callbacks for entry in callbacks: if line.startswith(entry[0]): @@ -857,18 +857,18 @@ def endbuttonpressed_internal(nullparam=None): #GPRS and TCP server functions def setup_gprs(): - sim800.command("AT+CIPSHUT", response_timeout=60000, custom_endofdata="SHUT OK") - sim800.command("AT+CGATT?", response_timeout=10000) - sim800.command("AT+CIPMUX=1", response_timeout=10000) + command("AT+CIPSHUT", response_timeout=60000, custom_endofdata="SHUT OK") + command("AT+CGATT?", response_timeout=10000) + command("AT+CIPMUX=1", response_timeout=10000) def connect_gprs(apn): - sim800.command("AT+CSTT=\""+apn+"\"", response_timeout=10000) - sim800.command("AT+CIICR", response_timeout=10000) - sim800.command("AT+CIFSR") + command("AT+CSTT=\""+apn+"\"", response_timeout=10000) + command("AT+CIICR", response_timeout=10000) + command("AT+CIFSR") def start_server(port): - sim800.command("AT+CIPSERVER=1,"+port, response_timeout=10000) - sim800.registercallback('+RECEIVE', handle_data) + command("AT+CIPSERVER=1,"+port, response_timeout=10000) + # Startup... # Start turning on the SIM800 asynchronously