def get_or_create_classroom(datatype):
    dc = get_authenticated_dc()
    classroom = dc.streams.get_stream_if_exists('classroom')
    if not classroom:
        classroom = dc.streams.create_stream(
            stream_id='classroom',
            data_type=datatype,
            description='Stream representing a classroom of students',
        )
    return classroom
Exemplo n.º 2
0
    if len(sys.argv) < 2:
        # print sys.argv
        disp_help()

    return sys.argv


if __name__ == "__main__":
    print(
        "Device Exporter - version {major}.{minor}.{patch}".format(**VERSION))
    args = parse_args(sys.argv)

    print("Opening {}".format(args[1]))

    dc = get_authenticated_dc()
    devices = dc.devicecore.get_devices()

    fieldnames = [
        'devMac', 'devCellularModemId', 'devConnectwareId', 'xpExtAddr',
        'dpLastKnownIp', 'dpGlobalIp', 'dpDeviceType', 'dpDescription',
        'dpConnectionStatus', 'dpRestrictedStatus', 'dpFirmwareLevelDesc',
        'dpLastConnectTime', 'dpContact', 'dpLocation', 'dpMapLat',
        'dpMapLong', 'dpCapabilities', 'dvVendorId', 'dpUserMetaData',
        'dpTags', 'dpLastDisconnectTime', 'dpLastUpdateTime', 'dpHealthStatus',
        'grpPath', 'dpPanId', 'dpFirmwareLevel', 'devTerminated',
        'devEffectiveStartDate', 'grpId', 'cstId', 'devRecordStartDate', 'id',
        'dpZigbeeCapabilities'
    ]

    with open(args[1], 'w') as csvfile:
    dc.monitor.stop_listeners()

def test_http_monitor(dc):
    # Create a fresh monitor over a pretty broad set of topics
    topics = ['DeviceCore', 'FileDataCore', 'FileData', 'DataPoint']
    mon = dc.monitor.get_monitor(topics)
    if mon is not None:
        mon.delete()
    mon = dc.monitor.create_http_monitor(topics, 'http://digi.com',  transport_token=None, transport_method='PUT',
                                         connect_timeout=0, response_timeout=0, batch_size=1, batch_duration=0,
                                         compression='none', format_type='json')
    pprint.pprint(mon.get_metadata())

    def listener(data):
        pprint.pprint(data)
        return True  # we got it!

    test_stream = dc.streams.get_stream("test")
    try:
        while True:
            test_stream.write(DataPoint(random.random()))
            time.sleep(3.14)
    except KeyboardInterrupt:
        print("Shutting down threads...")

if __name__ == '__main__':
    dc = get_authenticated_dc()
    test_http_monitor(dc)