Skip to content

Commit

Permalink
Merge pull request #148 from emfcamp/sammachin-gprs
Browse files Browse the repository at this point in the history
Sammachin gprs
  • Loading branch information
alistairuk committed Sep 16, 2018
2 parents ce621a7 + 912cc34 commit 20b1d31
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
51 changes: 51 additions & 0 deletions hologram_demo/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""This app connects to the Hologram service via GPRS displays recieved data on the screen and sets the neopixles"""

___title___ = "Hologram Demo"
___license___ = "MIT"
___dependencies___ = ["app", "sim800"]
___categories___ = ["EMF", "System"]
___bootstrapped___ = False

#import ugfx, os, time, sleep, app, sim800

import ugfx, app, sim800
import os
from tilda import Buttons
from time import sleep
from machine import Neopix


n = Neopix()

ugfx.init()
ugfx.clear()
ugfx.set_default_font(ugfx.FONT_FIXED)


def callback(data):
payload=data.decode("utf-8")
ugfx.Label(5, 100, 240, 15, payload)
colour = int(payload)
n.display([colour,colour])

print('Launching Hologram Demo')
ugfx.Label(5, 20, 240, 15, "Starting....")
sim800.setup_gprs()
ugfx.Label(5, 20, 240, 15, "GPRS Ready")
sim800.connect_gprs('hologram')
ugfx.Label(5, 40, 240, 15, "GPRS Connected")
sim800.start_server(4010, callback)
ugfx.Label(5, 60, 240, 15, "Server Started")


ugfx.Label(5, 300, 240, 15, "** Hold A or B or MENU to exit **")


while (not Buttons.is_pressed(Buttons.BTN_A)) and (not Buttons.is_pressed(Buttons.BTN_B)) and (not Buttons.is_pressed(Buttons.BTN_Menu)):
sleep(2)

ugfx.clear()
ugfx.Label(5, 20, 240, 15, "Stopping....")
sim800.stop_server()
sim800.stop_gprs()
app.restart_to_default()
29 changes: 29 additions & 0 deletions lib/sim800.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

# A list of callback functions
callbacks = []
server_callback = None

# Globals for remembering callback data
clip = ""
Expand Down Expand Up @@ -105,6 +106,12 @@ def processcallbacks(line):
# Check for Bluetooth pairing request
if line.startswith("+BTPAIRING:"):
btpairing = line[11:].strip()
# Handle TCP Server Data
if line.startswith("+RECEIVE"):
dlen = int(line.split(",")[2].rstrip(":"))+1
payload = uart.read(dlen)
if server_callback:
micropython.schedule(server_callback, payload[1:])
# Check for app callbacks
for entry in callbacks:
if line.startswith(entry[0]):
Expand Down Expand Up @@ -847,6 +854,28 @@ def callbuttonpressed_internal(nullparam=None):
def endbuttonpressed_internal(nullparam=None):
hangup()

#GPRS and TCP server functions

def setup_gprs():
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):
command("AT+CSTT=\""+apn+"\"", response_timeout=10000)
command("AT+CIICR", response_timeout=10000)
command("AT+CIFSR")

def stop_gprs():
command("AT+CIPSHUT", response_timeout=60000, custom_endofdata="SHUT OK")

def start_server(port, callback):
global server_callback
server_callback = callback
command("AT+CIPSERVER=1,"+str(port), response_timeout=10000)

def stop_server():
command("AT+CIPSERVER=0", response_timeout=10000)

# Startup...

Expand Down

0 comments on commit 20b1d31

Please sign in to comment.