def getResrictionCode(number, code): print('inside getResrictionCode') gsm = GsmModem(port=dev) sendSMS(gsm, number, code) print("clear storage before recieve message") clear_storage(gsm) rcode = waiting_response(number, gsm) return rcode
class Command(BaseCommand): help = "This command need to be started whenever the application is running, of course after executing runserver." print conf['gsm'] gsm = GsmModem(port=conf['gsm']['port'], logger=GsmModem.debug_logger).boot() def handle(self, **options): print "Transmitting SMS..." cmd = SmsHandler(self.gsm).transmit_sms()
def on_connect(client, userdata, flags, rc): print("Connected with result code " + str(rc)) global gsm #Initializing GSM Modem gsm = GsmModem(port="/dev/ttyUSB1", logger=GsmModem.debug_logger).boot() # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. client.subscribe(("iot-2/cmd/bluepi/fmt/json", 0))
allRFCommDevicePorts = scanRadioComm() allUSBDevicePorts = scanUSBSerial() print("RFPorts detected with devices on them: " + str(allRFCommDevicePorts)) print("USBPorts detected with devices on them: " + str(allUSBDevicePorts)) usbPortsIdentified = {} iccid = '' # Default values are blank for those that come from GSM modem imei = '' for usbPort in allUSBDevicePorts: try: with time_limit(4): print("Trying to connect as GSM to " + str(usbPort)) gsm = GsmModem(port=usbPort, logger=GsmModem.debug_logger).boot() print("GSM modem detected at " + str(usbPort)) allUSBDevicePorts.remove( usbPort) # We just found it engaged, don't use it again iccid = gsm.query("AT^ICCID?", "^ICCID:").strip('"') imei = gsm.query("ATI", "IMEI:") usbPortsIdentified[str(usbPort)] = "gsm" print(usbPort, usbPortsIdentified[usbPort]) break # We got a port, so break out of loop except TimeoutException: # Maybe this is not the right port for the GSM modem, so skip to the next number print("Timed out!") except IOError: print("IOError - so " + usbPort + " is also not a GSM device") # Open a SQLlite3 connection
import time from pygsm import GsmModem gsm = GsmModem(port="/dev/ttyUSB0", logger=GsmModem.debug_logger).boot() print("Waiting for network...") s = gsm.wait_for_network() with open("messaggio.txt", "rt") as f: messaggio = f.read() with open("lista.csv", "rt") as f: for i, l in enumerate(f): gsm.send_sms(l.strip(), messaggio) time.sleep(1) gsm.disconnect()
print 'Position: ' + UTC + ', ' + Latitude + ', ' + Longitude + ', ' + Altitude # Text to mobile Message = ' Position: ' + UTC + ', ' + str(Latitude) + ', ' + str( Longitude) + ', ' + str( Altitude) + ' http://maps.google.com/?q=' + str( Latitude) + ',' + str(Longitude) print "Sending to mobile " + MobileNumber + ": " + Message gsm.send_sms(MobileNumber, Message) # Set mobile number here MobileNumber = "017412312312" lastmessage = 'Stop' print "Booting modem ..." gsm = GsmModem(port="/dev/serial0") gsm.boot() print "Modem details:" reply = gsm.hardware() print "Manufacturer = " + reply['manufacturer'] print "Model = " + reply['model'] # Try and get phone number reply = gsm.command('AT+CNUM') if len(reply) > 1: list = reply[0].split(",") phone = list[1].strip('\"') print "Phone number = " + phone print
GatewayNumber = sys.argv[3] print "Texts will be sent to gateway number " + GatewayNumber else: GatewayNumber = None SendTimeout = 5 # Send position every x minutes regardless of movement HorizontalDelta = 50 # Send position if it moves horizontally by at keast this many metres VerticalDelta = 50 # Send position if it moves vertically by at least this many metres MaxGSMAltitude = 2000 # Don't try to send above this altitude PreviousSeconds = 0 PreviousAltitude = 0 PreviousLatitude = 0 PreviousLongitude = 0 gsm = GsmModem(port="/dev/ttyAMA0") gsm.boot() print "GPS/GSM UKHAS Tracker" print "=====================" print print "Modem details ..." reply = gsm.hardware() print "Manufacturer = " + reply['manufacturer'] print "Model = " + reply['model'] print # Try and get phone number reply = gsm.command('AT+CNUM') if len(reply) > 1:
'192.168.0.101', # The host name. 8090, # A port number where to wait for the request. application, # Our application object name, in this case a function. server_class=SecureWSGIServer, #up there ;) handler_class=SecureWSGIRequestHandler #up there also ) # Wait for request, serve it . httpd.serve_forever() logging.debug('srver started succefuly', extra=s) except Exception, e: logging.exception('Error ------------- ', extra=s) Daisy13_on_D1 = "/dev/ttyS1" gsm = GsmModem(port=Daisy13_on_D1, baudrate=115200, logger=GsmModem.debug_logger).boot() z = gsm.wait_for_network() app = gsmmodule(gsm) if __name__ == "__main__": daemon = MyDaemon('/tmp/daemon-example.pid') if len(sys.argv) == 2: if 'start' == sys.argv[1]: #gsm.boot() daemon.start() elif 'stop' == sys.argv[1]: #app.sendsms(s,"0633466667","sms server stoping") #activate this to secure server logging.debug('srver stoping', extra=s) daemon.stop() elif 'restart' == sys.argv[1]: gsm.boot()
#!/usr/bin/env python # vim: ai ts=4 sts=4 et sw=4 import time from pygsm import GsmModem gsm = GsmModem(port="/dev/ttyUSB2").boot() csq = gsm.signal_strength() approx_dBm = ((-113) + (2 * csq)) csq_marginal = 9 csq_ok = 14 csq_good = 19 csq_excellent = 30 def csq_name(csq): if csq <= csq_marginal: return 'marginal' elif csq <= csq_ok: return 'ok' elif csq <= csq_good: return 'good' elif csq <= csq_excellent: return 'excellent' else: return 'searching' print 'CSQ: ',csq,'/',csq_excellent,'(',approx_dBm,'dBm) - ',csq_name(csq)
# gsm.send_sms(MobileNumber, Message) # DEFINE GLOBAL VARIABLES #---------------------------------------------------------------------- SendTimeout = 5. # Send position every x minutes regardless of movement HorizontalDelta = 20. # Send position if it moves horizontally by at least this many metres VerticalDelta = 2. # Send position if it moves vertically by at least this many metres # variabile logica per capire quando c'รจ stata una variazione di posizione changeXYZ = 0 # Set mobile number here MobileNumber = "+39xxxxxxxxx" # Set here mobile number print("Booting modem ...") gsm = GsmModem(port="/dev/ttyAMA0") # try with ttyS0 gsm.boot() print("Modem details:") reply = gsm.hardware() print("Manufacturer = " + reply['manufacturer']) print("Model = " + reply['model']) # Try and get phone number reply = gsm.command('AT+CNUM') if len(reply) > 1: list = reply[0].split(",") phone = list[1].strip('\"') print("Phone number = " + phone) print
Delete all messages if full ''' out = gsm.query("AT+CPMS=SM") m = re.match(r'\+CPMS: (\d{1,2}),(\d{2})', out) cur_size = m.group(1) max_size = m.group(2) print("current messages: %s, maximum size: %s" % (cur_size, max_size)) if cur_size == max_size: # clear the storage, delete all messages delete_all_sms(gsm) def getResrictionCode(number, code): print('inside getResrictionCode') gsm = GsmModem(port=dev) sendSMS(gsm, number, code) print("clear storage before recieve message") clear_storage(gsm) rcode = waiting_response(number, gsm) return rcode if __name__ == "__main__": # clear_storage() gsm = GsmModem(port=dev) delete_all_sms(gsm) # gsm.query("AT+CMGD=1")
def __init__(self, port, logger=""): self.logger = logger self.gsm = GsmModem(port=port, logger=logger).boot()