123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- # -*- coding: utf-8 -*-
- #!/usr/bin/env python
- import os, sys,datetime
- from os.path import abspath, join
- import ConfigParser
- from apps.web.constant import Const, DeviceCmdCode
- from apps.web.core.networking import MessageSender
- try:
- configParser = ConfigParser.ConfigParser()
- configParser.read('./settings.ini')
- settingModuleName = configParser.get('CORE', 'setting')
- except Exception:
- settingModuleName = 'staging'
- settingModuleIdentifier = "configs.production"
- PROJECT_ROOT = abspath(os.path.split(os.path.realpath(__file__))[0] + "/..")
- sys.path.insert(0, PROJECT_ROOT)
- sys.path.insert(0, join(PROJECT_ROOT, "apps"))
- os.environ.update({"DJANGO_SETTINGS_MODULE": settingModuleIdentifier})
- from apps.web.device.models import Device, DeviceDict
- print 'nowtime = %s start update device now.....' % datetime.datetime.now()
- objs = Device.get_collection().find({'softVer':{'$in':['v1.5','v1.7','v1.7.3','v1.7.5','v1.7.1']}})
- devNoList = [obj['devNo'] for obj in objs]
- for devNo in devNoList:
- try:
- dev = Device.get_dev(devNo) # type: DeviceDict
- if (not dev.online) or dev.groupId == '':
- continue
- if dev['softVer'] == 'v1.5':
- cmdPara = {"IMEI":devNo,"ota_set":{"fw_url":"http://www.washpayer.com/uploaded/SMARTBOX_1.0.0_Luat_V0014_8955_SSL.bin"}}
- else:
- cmdPara = {"IMEI":devNo,"ota_set":{"fw_url":"http://www.washpayer.com/uploaded/SMARTBOX_1.0.0_Luat_V0016_8955_SSL.bin"}}
- result = MessageSender.send(device = dev, cmd = DeviceCmdCode.SET_DEVINFO, payload = cmdPara)
- if result['rst'] != 0:
- print 'send updating cmd error,imei=%s' % devNo
- else:
- print 'success for imei=%s,send the message' % devNo
-
- nowHour = datetime.datetime.now().hour
- if nowHour > 5:
- print 'finished in morning'
- break
- except Exception,e:
- print 'some exception =%s' % e
-
|