def do_TokenUpdate(pl): global mdm_commands my_PushMagic = pl['PushMagic'] my_DeviceToken = pl['Token'].data my_UnlockToken = pl['UnlockToken'].data newTuple = (web.ctx.ip, my_PushMagic, my_DeviceToken, my_UnlockToken) print "NEW DEVICE UDID:", pl.get('UDID') # A new device has enrolled, add a new device if pl.get('UDID') not in device_list: # Device does not already exist, create new instance of device device_list[pl.get('UDID')] = device(pl['UDID'], newTuple) print "ADDING DEVICE TO DEVICE_LIST" else: # Device exists, update information - token stays the same device_list[pl['UDID']].reenroll(web.ctx.ip, my_PushMagic, my_UnlockToken) print "DEVICE ALREADY EXISTS, UPDATE INFORMATION" # Queue a DeviceInformation command to populate fields in device_list # Is this command causing an off-by-one error with commands? queue('DeviceInformation', pl['UDID']) # Store devices in a file for persistence store_devices() # Return empty dictionary for use in do_mdm return dict()
def trigger_event(): param_json = request.get_json() #Send event to scheduler if 'event' not in param_json: abort(404) dev = device('') if 'device' in param_json and param_json['device'] in MAX.devices.devices: dev = MAX.devices.devices[param_json['device']] MAX.events.event(param_json['event'], dev, param_json) return jsonify({"result": True})
def do_TokenUpdate(pl): global mdm_commands, devicesAwaitingConfiguration print "CONTENTS OF TokenUpdate plist:\n\n", pl my_PushMagic = pl['PushMagic'] print dir(pl['Token']) # my_DeviceToken = pl['Token'].data my_DeviceToken = pl['Token'] if pl.get('UnlockToken'): my_UnlockToken = pl['UnlockToken'].data else: my_UnlockToken = pl['Token'] # Check whether the device doing the TokenUpdate is currently awaiting # configuration via the AwaitingConfiguration key and if so add to list if pl.get('AwaitingConfiguration'): if pl.get('UDID') in devicesAwaitingConfiguration: devicesAwaitingConfiguration[pl['UDID']] = { 'status': 'AwaitingConfiguration', 'mtime': int(datetime.now().strftime('%s'))} newTuple = (web.ctx.ip, my_PushMagic, my_DeviceToken, my_UnlockToken) print "NEW DEVICE UDID:", pl.get('UDID') # A new device has enrolled, add a new device if pl.get('UDID') not in device_list: # Device does not already exist, create new instance of device device_list[pl.get('UDID')] = device(pl['UDID'], newTuple) print "ADDING DEVICE TO DEVICE_LIST" else: # Device exists, update information - token stays the same device_list[pl['UDID']].reenroll(web.ctx.ip, my_PushMagic, my_UnlockToken) print "DEVICE ALREADY EXISTS, UPDATE INFORMATION" # Queue a DeviceInformation command to populate fields in device_list # Is this command causing an off-by-one error with commands? queue('DeviceInformation', pl['UDID']) # Store devices in a file for persistence store_devices() # Return empty dictionary for use in do_mdm return dict()
def run_app(): 'Run the application' import sys, os main_obj = Main(sys.argv) print main_obj.opts if main_obj.opts.device: os.environ['OMRON_DEV'] = main_obj.opts.device import device omron_dev = device.device() if omron_dev: print 'Using device: "%s"' % omron_dev else: print 'No device autodetected, try running "lsusb" and ' \ + 'setting OMRON_DEV=/dev/bus/usb/BBB/DDD' pass root = tk.Tk() app = Gui(root, main_obj.opts.name, main_obj.opts.file) root.mainloop()
#!/usr/bin/env python import omron, store, device import os, sys print sys.path devfile = device.device() print 'Using', devfile, omron.VID, omron.PID dev = omron.create_device() print dev ret = omron.get_count(dev, omron.VID, omron.PID) print ret if not ret: print 'No omron device!' sys.exit(1) print 'Found %d omron'%ret o = omron.Omron() print 'Openning' ret = o.open() if ret < 0: print 'Cannot open omron 790IT' sys.exit(1) print 'Getting device version' ret = o.get_device_version() if not ret: print 'Cannot get device version!' sys.exit(1) print 'Device version: "%s"'%ret
def test_already_registered(self): dev = device("TestDevice3", "BR42F2N3") self.assertTrue(device.is_already_registered("BR42F2N3"))
def test_not_connected(self): dev = device("TestDevice2", "BR42F2N2") self.assertFalse(dev.socket)
def test_new_device(self): dev = device("TestDevice1", "BR42F2N1") self.assertIn(dev, device.get_all())
##New Device Template ##New Devices should be added into the initalState() function in ##the device mod which will add the new device to every device import socket import device ##mod with device class and other useful funcs import select ##DEVICE ThisDevice = device.device("device1", "off") ##SOCKET s = socket.socket() host = socket.gethostname() port = 7776 ##Start State/Variables deviceList = [] currentStateDict = device.initialState() server_on = True ##COMMANDS: add new commands to the commandList as tupples ##(list of the requirements(tupples), action("on"/"off")) ##please be careful to not put mutually exclusive commands on ##the same device or commands on several devices that will result ##in oscillation. Commands at the end of the list will supercede ##previous commands if there is a contradiction commandList = [([("device2","on"),("device3","on")],"on"),([("device2","off"),("device3","off")],"off")]
def __init__(self, devicesInit): self.devices = {} for deviceID in devicesInit.keys(): self.devices[deviceID] = device(devicesInit[deviceID])
def moData(self, mo_payload): payload = json.loads(mo_payload) try: self.niddConfig = payload['niddConfiguration'] except: print('error while parsing nidd confg') pass try: self.msisdn = payload['msisdn'] except: print('error while parsing msisdn parameter ') pass try: self.externalId = payload['externalId'] except: print('error while parsing externalId parameter ') pass try: self.data = json.loads(base64.b64decode(payload['data'])) except: print('error while parsing externalId parameter ') pass try: self.msg_id = self.data['T'] except: print('error in parsing message ID') pass try: self.eventType = self.data['E'] if (self.eventType=='B'): except: print('error in parsing event type') pass try: self.battery = self.data['B'] except: print('error in parsing Battery') pass try: self.signal_strength = self.data['S'] except: print('error in parsing signalStrength') pass try: self.value = self.data['V'] except: print('error in parsing value') pass try: self.lat = self.data['LAT'] except: print('error in parsing lattitude') pass try: self.lat = self.data['LONG'] except: print('error in parsing longitude') pass try: if redis_client.exists(self.msg_id) is 0: device_modata = { 'type': 'moData', 'msg_id': self.msg_id, 'msisdn': self.msisdn, 'battery': self.battery, 'signal_strength': self.signal_strength, 'value': self.value, 'lat': self.lat, 'long': self.long, 'TimeStamp': datetime.datetime.now() } print(device_modata) redis_client.hmset(self.msg_id, device_modata) return {'status': 'CREATED', 'message': 'Device MO Data event Created Successfully'} else: return {'status': 'ERROR'} except: print('Error in creating new row in DB') pass deviceLa = device.device(self.msisdn) deviceLa.updateLattitude(self.lat) deviceLa.updatelongitude(self.long) deviceLa.updateSignal_strenght(self.signal_strength) deviceLa.updateBattery(self.battery) deviceLa.updateLastSeen(self.msg_id)
def new_dev(self, dtype, UC, file=None, rwb=None, printer=None): for dev in self.devs: if dev.get_type()==dtype and dev.get_UC()==UC: raise MVNError("Device ja existe") self.devs.append(device.device(dtype, UC, file, rwb, printer, self.quiet))
def addDevice(self, devName): if devName in self.devSet: pass else: self.devSet[devName] = device(self.projID, devName)
#!/usr/bin/env python import omron, store, device import os, sys print sys.path devfile = device.device() print 'Using', devfile, omron.VID, omron.PID dev = omron.create_device() print dev, dev.device._is_inited ret = omron.get_count(dev, omron.VID, omron.PID) print ret if not ret: print 'No omron device!' sys.exit(1) print 'Found %d omron' % ret o = omron.Omron() print 'Openning' ret = o.open() if ret < 0: print 'Cannot open omron 790IT' sys.exit(1) print 'Getting device version' ret = o.get_device_version() if not ret: print 'Cannot get device version!' sys.exit(1) print 'Device version: "%s"' % ret