コード例 #1
0
def online(sid, data):
    l.success(str(data))
    devInfo = db.getDeviceInfo(data['devId'])
    if devInfo['status'] == 0:
        sio.disconnect(sid)
        return
    l.default('Device: {0} is online'.format(data['devId']))
コード例 #2
0
def auth(sid, data):
    # decrypting data
    keys = db.getKeys()
    data['status'] = func.decrypt(keys['privKey'], unhexlify(data['status']))
    data['time'] = func.decrypt(keys['privKey'], unhexlify(data['time']))

    # update status
    db.updateStatus(data['devId'], data['status'])

    # encrypting data
    deviceInfo = db.getDeviceInfo(str(data['devId']))
    data['status'] = hexlify(
        func.encrypt(str(deviceInfo['pubKey']), data['status']))
    data['time'] = hexlify(
        func.encrypt(str(deviceInfo['pubKey']), data['time']))

    sio.emit(str(data['devId']), data)
コード例 #3
0
def on_connect():
    print('connection established')
    deviceInfo = db.getDeviceInfo(sys.argv[1])
    status = func.encrypt(deviceInfo['pubKey'], str(sys.argv[3]))
    t = func.encrypt(deviceInfo['pubKey'], str(time.time()))
    sio.emit('auth', {'fleetId': sys.argv[1], 'devId': str(sys.argv[2]), 'status': hexlify(status), 'time': hexlify(t)})
コード例 #4
0
ファイル: fleet.py プロジェクト: zezo010/IoT-IDS
Fleet Client
"""

import sys
sys.path.append('..')
import func
import logger as l
import db
import socketio
reload(sys)
sys.setdefaultencoding('utf8')
import fx

# Defaults
sio = socketio.Client()
devInfo = db.getDeviceInfo(db.getDevId())

@sio.on('connect')
def on_connect():
    l.success('connection established')
    # register deviceId
    #sio.emit('register', {'devId': db.getDevId(), 'pubKey': devInfo['pubKey']})
    sio.emit('online', {'devId': db.getDevId()})

@sio.on(str(db.getDevId()))
def on_message(data):
    l.default('message received with {0}'.format(str(data)))
    fx.sendDeviceMessage(str(data['fleetId']), data)
    #sio.emit('my response', {'response': 'my response'})

@sio.on('disconnect')