コード例 #1
0
    # print banner
    print '\nVMgr_TemperatureData (c) Dust Networks'
    print 'SmartMesh SDK {0}\n'.format('.'.join([str(i) for i in sdk_version.VERSION]))

    mgrhost = raw_input('Enter the IP address of the manager (e.g. {0}): '.format(DFLT_MGR_HOST))
    if mgrhost == "":
        mgrhost = DFLT_MGR_HOST

    # log-in as user "dust"
    config = Configuration()
    config.username     = '******'
    config.password     = '******'
    config.verify_ssl   = False
    
    if os.path.isfile(certifi.where()):
        config.ssl_ca_cert  = certifi.where()
    else:
        config.ssl_ca_cert = os.path.join(os.path.dirname(sys.executable), "cacert.pem")

    # initialize the VManager Python library
    voyager = VManagerApi(host=mgrhost)

    # Start listening for data notifications
    voyager.get_notifications(
        'data',
        notif_callback       = process_data, 
        disconnect_callback  = show_disconnect,
    )

    print '\n==== Subscribing to data notifications'
    reply = raw_input ('Waiting for notifications. Press any key to stop\n\n')
コード例 #2
0
        sys.exit('\n\n Mote Mac address entered is invalid\n')

    userinput = raw_input(' Turn the LED ON or OFF? Default = ON:')
    if userinput == "":
        ledVal = 1
    else:
        ledVal = 0

    # log in as user "dust"
    config = Configuration()
    config.username = '******'
    config.password = '******'
    config.verify_ssl = False

    if os.path.isfile(certifi.where()):
        config.ssl_ca_cert = certifi.where()
    else:
        config.ssl_ca_cert = os.path.join(os.path.dirname(sys.executable),
                                          "cacert.pem")

    # initialize the VManager Python library
    voyager = VManagerApi(host=mgrhost)

    # build OAP message
    oap_msg = OAPMessage.build_oap(
        seq=0,
        sid=0,
        cmd=OAPMessage.CmdType.PUT,
        addr=[3, 2],
        tags=[OAPMessage.TLVByte(t=0, v=ledVal)],
        sync=True,
コード例 #3
0
def main():

    writeToFile(intype='admin', indata={'msg': 'starting'}, firstline=True)

    try:
        #=== connect

        # banner
        print '\nVMgr_LogFileSnapshot (c) Dust Networks'
        print 'SmartMesh SDK {0}\n'.format('.'.join(
            [str(i) for i in sdk_version.VERSION]))

        # log-in as user "dust"
        config = Configuration()
        config.username = '******'
        config.password = '******'
        config.verify_ssl = False

        if os.path.isfile(certifi.where()):
            config.ssl_ca_cert = certifi.where()
        else:
            config.ssl_ca_cert = os.path.join(os.path.dirname(sys.executable),
                                              "cacert.pem")

        # initialize the VManager Python library
        voyager = VManagerApi(host=DFLT_VMGR_HOST)

        fileLock = threading.RLock()

        voyager.get_notifications(notif_callback=_handle_notifications)

        #=== collect

        snapshot = {}

        while True:

            motes = voyager.motesApi.get_motes().to_dict()
            assert motes.keys() == ['motes']
            motes = motes['motes']
            '''
            motes = [
                {   'mac_address': '00-17-0D-00-00-31-CA-03', 'state': 'operational'},
                {   'mac_address': '00-17-0D-00-00-38-06-D5', 'state': 'operational'},
                ...
            ]
            '''
            snapshot['motes'] = motes

            for (i, mote) in enumerate(motes):

                mote_info = voyager.motesApi.get_mote_info(
                    mote['mac_address']).to_dict()
                mote_info = remove_datetime(mote_info)
                '''
                mote_info = {
                    'app_id': 1,
                    'app_sw_rev': '1.4.1.8',
                    'avg_hops': 1.0,
                    ...
                }
                '''
                snapshot['motes'][i]['mote_info'] = mote_info

                connections = voyager.pathsApi.get_connections(
                    mote['mac_address']).to_dict()
                assert connections.keys() == ['devices']
                connections = connections['devices']
                for (i, c) in enumerate(connections):
                    connections[i] = remove_datetime(c)
                '''
                connections = [
                    {
                        'mac_address': '00-17-0D-00-00-58-2B-4F',
                        'num_links': None,
                        'quality': None,
                        'rssi_ato_b': None,
                        'rssi_bto_a': None,
                    },
                    ...
                ]
                '''
                snapshot['motes'][i]['connections'] = connections

            network_info = voyager.networkApi.get_network_info().to_dict()
            network_info = remove_datetime(network_info)
            '''
            network_info = {
                'adv_state': 'on',
                'cur_down_frame_size': 512,
                ...
            }
            '''
            snapshot['network_info'] = network_info

            #==== write

            writeToFile(
                intype='snapshot',
                indata=snapshot,
            )

            #=== wait a bit

            time.sleep(5 * 60)

    except:
        traceback.print_exc()