Exemple #1
0
        public static void Init()
        {
            Console.WriteLine("Please enter applicaiton details");
            Console.Write("Enter your org id :");
            orgId = Console.ReadLine();

            Console.Write("Enter your app id :");
            appId = Console.ReadLine();

            Console.Write("Enter your api Key :");
            apiKey = Console.ReadLine();

            Console.Write("Enter your auth token :");
            authToken = Console.ReadLine();

            Console.WriteLine("Please enter device details to which you want to implement Infomation Mangement");

            Console.Write("Enter your device type :");
            deviceType = Console.ReadLine();

            Console.Write("Enter your device id :");
            deviceID = Console.ReadLine();

            Console.Write("Enter your device event :");
            deviceEvent = Console.ReadLine();

            client = new ApplicationClient(orgId, appId, apiKey, authToken);
            client.connect();
            cli         = client.GetAPIClient();
            cli.Timeout = 30000;
            //MQTT Topic subscription for IM State
            client.subscribeToIMState(deviceType, deviceID);
            client.IMStateCallback += processIM;
        }
Exemple #2
0
 public static void Devices(IBMWIoTP.ApiClient cli, LogicalInterfaceInfo li)
 {
     Console.WriteLine("===============================================================================");
     Console.WriteLine("Get Device state ");
     Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetCurrentDeviceState(deviceType, deviceID, li.id)));
     Console.WriteLine("===============================================================================");
 }
Exemple #3
0
        public static LogicalInterfaceInfo LogicalInterface(IBMWIoTP.ApiClient cli, SchemaInfo sc)
        {
            Console.WriteLine("Logical Interface sample request");
            Console.WriteLine("Add Draft LogicalInterface");
            LogicalInterfaceDraft draft = new LogicalInterfaceDraft();

            draft.name        = "lidraft";
            draft.schemaId    = sc.id;
            draft.description = "some thing";
            var li = cli.AddDraftLogicalInterfaces(draft);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(li));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get all Draft Logical Interfaces");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetAllDraftLogicalInterfaces()));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Update Draft Logical Interfaces");
            li.description = "changed to new discription";
            li             = cli.UpdateDraftLogicalInterfaces(li);
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(li));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get Draft Logical Interfaces");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetDraftLogicalInterfaces(li.id)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Perform action on Draft Logical Interfaces");
            OperationInfo work = new OperationInfo(OperationInfo.Validate);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.OperateDraftLogicalInterfaces(li.id, work)));

            Console.WriteLine("===============================================================================");
            Console.WriteLine("Delete Draft Logical Interfaces");
            var dummyli = cli.AddDraftLogicalInterfaces(draft);

            cli.DeleteDraftLogicalInterfaces(dummyli.id);
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get all Draft Logical Interfaces");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetAllDraftLogicalInterfaces()));
            Console.WriteLine("===============================================================================");

            Console.WriteLine("Get All active Logical Interfaces");
            LogicalInterfaceCollection coll = cli.GetAllActiveLogicalInterfaces();

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(coll));
            Console.WriteLine("===============================================================================");
            if (coll.results.Count > 0)
            {
                Console.WriteLine("Get active Logical Interfaces");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetActiveLogicalInterfaces(coll.results[0].id)));
                Console.WriteLine("===============================================================================");
                Console.WriteLine("Oparate on Logical Interfaces  ");
                work = new OperationInfo(OperationInfo.Deactivate);
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.OperateLogicalInterfaces(coll.results[0].id, work)));
                Console.WriteLine("===============================================================================");
            }
            return(li);
        }
Exemple #4
0
        public static PhysicalInterfacesInfo PhysicalInterfaces(IBMWIoTP.ApiClient cli, EventTypeInfo evnt)
        {
            Console.WriteLine("Physical Interfaces sample request");
            Console.WriteLine("Add Draft PhysicalInterfaces");
            PhysicalInterfaceDraft draft = new PhysicalInterfaceDraft();

            draft.name        = "TempPI";
            draft.description = "new PhysicalInterfaces for temp";
            PhysicalInterfacesInfo newPI = cli.AddDraftPhysicalInterfaces(draft);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(newPI));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get all Draft PhysicalInterfaces");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetAllDraftPhysicalInterfaces()));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Update Draft PhysicalInterfaces");
            newPI.description = "changed to new discription";
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.UpdateDraftPhysicalInterfaces(newPI)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get Draft PhysicalInterfaces");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetDraftPhysicalInterfaces(newPI.id)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Map PhysicalInterfaces EventType");
            EventTypeBind bind = new EventTypeBind();

            bind.eventTypeId = evnt.id;
            bind.eventId     = "temperature";
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.MapDraftPhysicalInterfacesEvent(newPI.id, bind)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get all Mapping PhysicalInterfaces EventType");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetAllDraftPhysicalInterfacesMappedEvents(newPI.id)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Delete Mapping PhysicalInterfaces EventType");
            cli.DeleteDraftPhysicalInterfacesMappedEvents(newPI.id, bind.eventId);
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get All active PhysicalInterfaces");
            PhysicalInterfacesCollection coll = cli.GetAllActivePhysicalInterfaces();

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(coll));
            Console.WriteLine("===============================================================================");
            if (coll.results.Count > 0)
            {
                Console.WriteLine("Get active PhysicalInterfaces");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetActivePhysicalInterfaces(coll.results[0].id)));
                Console.WriteLine("===============================================================================");
                Console.WriteLine("Get active PhysicalInterfaces Events ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetActivePhysicalInterfacesEvents(coll.results[0].id)));
                Console.WriteLine("===============================================================================");
            }
            return(newPI);
        }
Exemple #5
0
        public static SchemaInfo Schema(IBMWIoTP.ApiClient cli)
        {
            Console.WriteLine("Get all draft schima");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetAllDraftSchemas()));
            Console.WriteLine("===============================================================================");
            SchemaDraft sd = new SchemaDraft();

            sd.name       = "test";
            sd.schemaFile = "tempSchemaPi.json";
            Console.WriteLine("Add schima draft");
            SchemaInfo si = cli.AddDraftSchema(sd);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(si));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Updated draft schema content");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.UpdateDraftSchemaContent(si.id, "tempSchema.json")));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Delete draft schema");
            cli.DeleteDraftSchema(cli.AddDraftSchema(sd).id);
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Updated draft schema metadata");
            si.description = "new temp change";
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.UpdateDraftSchemaMetadata(si)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get draft schima metadata");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetDraftSchemaMetadata(si.id)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get draft schima Content");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetDraftSchemaContent(si.id)));
            Console.WriteLine("===============================================================================");

            Console.WriteLine("Get All active schimas");
            SchemaCollection coll = cli.GetAllActiveSchemas();

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(coll));
            Console.WriteLine("===============================================================================");
            if (coll.results.Length > 0)
            {
                Console.WriteLine("Get active schimas");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetActiveSchemaMetadata(coll.results[0].id)));
                Console.WriteLine("===============================================================================");
                Console.WriteLine("Get active schima content ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetActiveSchemaContent(coll.results[0].id)));
                Console.WriteLine("===============================================================================");
            }

            return(si);
        }
Exemple #6
0
        public static EventTypeInfo EventType(IBMWIoTP.ApiClient cli, SchemaInfo sc)
        {
            Console.WriteLine("Event Type sample request");
            Console.WriteLine("Add Draft EventType");
            EventTypeDraft draft = new EventTypeDraft();

            draft.name        = "Temprature";
            draft.description = "eventType for temperature";
            draft.schemaId    = sc.id;
            EventTypeInfo info = cli.AddDraftEventType(draft);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(info));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get All Draft EventType");
            EventTypeCollection collection = cli.GetAllDraftEventType();

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(collection));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Delete Draft");
            //creating another one to delete
            EventTypeInfo del = cli.AddDraftEventType(draft);

            cli.DeleteDraftEventType(del.id);
            Console.WriteLine("Get event type draft of id" + info.id);
            EventTypeInfo reccivedInfo = cli.GetDraftEventType(info.id);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(reccivedInfo));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Update draft");
            reccivedInfo.description = "updated info";
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.UpdateDraftEventType(reccivedInfo)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get all active EventType");
            EventTypeCollection coll = cli.GetAllActiveEventType();

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(coll));
            Console.WriteLine("===============================================================================");
            if (coll.results.Count > 0)
            {
                Console.WriteLine("Get all active EventType with id");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetActiveEventType(coll.results[0].id)));
                Console.WriteLine("===============================================================================");
            }

            return(reccivedInfo);
        }
        public static void Main(string[] args)
        {
            string apiKey            = "";
            string authToken         = "";
            string managedDeviceType = "demotest";
            string managedDeviceId   = "1234";

            if (string.IsNullOrEmpty(apiKey) || string.IsNullOrEmpty(authToken))
            {
                Console.Write("please Enter API Key : ");
                apiKey = Console.ReadLine();
                Console.WriteLine();
                Console.Write("Please Enter Auth Token : ");
                authToken = Console.ReadLine();
            }
            IBMWIoTP.ApiClient client = new IBMWIoTP.ApiClient(apiKey, authToken);
            client.Timeout = 5000;
            try {
                //Organization

                Console.WriteLine("get org info");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetOrganizationDetail()));

                //Bulk Operations

                Console.WriteLine("get all device list");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetAllDevices()));

                IBMWIoTP.RegisterDevicesInfo [] bulk = new IBMWIoTP.RegisterDevicesInfo[1];
                var info = new IBMWIoTP.RegisterDevicesInfo();
                info.deviceId   = "123qwe";
                info.typeId     = managedDeviceType;
                info.authToken  = "1qaz2wsx3edc4rfv";
                info.deviceInfo = new IBMWIoTP.DeviceInfo();
                info.location   = new IBMWIoTP.LocationInfo();
                info.metadata   = new {};
                bulk[0]         = info;

                Console.WriteLine("get Bulk reg ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.RegisterMultipleDevices(bulk)));

                IBMWIoTP.DeviceListElement [] removeBulk = new IBMWIoTP.DeviceListElement[1];
                var del = new IBMWIoTP.DeviceListElement();
                del.deviceId = "123qwe";
                del.typeId   = managedDeviceType;

                removeBulk[0] = del;
                Console.WriteLine("get Bulk remove ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.DeleteMultipleDevices(removeBulk)));

                //Device Types

                Console.WriteLine("GetAllDeviceTypes ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetAllDeviceTypes()));

                DeviceTypeInfo devty = new DeviceTypeInfo();
                devty.classId    = "Gateway";
                devty.deviceInfo = new DeviceInfo();
                devty.id         = "gatewaypi";
                devty.metadata   = new {};
                Console.WriteLine("RegisterDeviceType");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.RegisterDeviceType(devty)));

                Console.WriteLine("UpdateDeviceType ");
                var u = new IBMWIoTP.DeviceTypeInfoUpdate();
                u.description = "test";
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.UpdateDeviceType("gatewaypi", u)));

                Console.WriteLine("GetDeviceType ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceType("gatewaypi")));

                //Devices

                Console.WriteLine("ListDevices");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.ListDevices(managedDeviceType)));

                string newDeviceId = DateTime.Now.ToString("yyyyMMddHHmmssffff");
                var    newdevice   = new RegisterSingleDevicesInfo();
                newdevice.deviceId   = newDeviceId;
                newdevice.authToken  = "testtest";
                newdevice.deviceInfo = new IBMWIoTP.DeviceInfo();
                newdevice.location   = new IBMWIoTP.LocationInfo();
                newdevice.metadata   = new {};
                Console.WriteLine("RegisterDevice");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.RegisterDevice("gatewaypi", newdevice)));

                var update = new IBMWIoTP.UpdateDevicesInfo();
                update.deviceInfo = new IBMWIoTP.DeviceInfo();
                Console.WriteLine("UpdateDeviceInfo");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.UpdateDeviceInfo("gatewaypi", newDeviceId, update)));

                Console.WriteLine("GetDeviceInfo");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceInfo("gatewaypi", newDeviceId)));

                Console.WriteLine("GetGatewayConnectedDevice");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetGatewayConnectedDevice("gatewaypi", newDeviceId)));

                Console.WriteLine("GetDeviceLocationInfo");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceLocationInfo("gatewaypi", newDeviceId)));

                Console.WriteLine("UpdateDeviceLocationInfo");
                var loc = new IBMWIoTP.LocationInfo();
                loc.accuracy         = 1;
                loc.measuredDateTime = DateTime.Now.ToString("o");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.UpdateDeviceLocationInfo("gatewaypi", newDeviceId, loc)));

                Console.WriteLine("GetDeviceManagementInfo");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceManagementInfo(managedDeviceType, managedDeviceId)));

                Console.WriteLine("UnregisterDevice");
                client.UnregisterDevice("gatewaypi", newDeviceId);


                Console.WriteLine("DeleteDeviceType ");
                client.DeleteDeviceType("gatewaypi");


                Console.WriteLine("AddDeviceDiagLogs");
                var log = new IBMWIoTP.LogInfo();
                log.message  = "test";
                log.severity = 1;

                client.AddDeviceDiagLogs(managedDeviceType, managedDeviceId, log);

                Console.WriteLine("GetAllDiagnosticLogs");
                var logResult = client.GetAllDiagnosticLogs(managedDeviceType, managedDeviceId);
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(logResult));



                Console.WriteLine("GetDiagnosticLog");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDiagnosticLog(managedDeviceType, managedDeviceId, logResult[0]["id"])));

                Console.WriteLine("DeleteDiagnosticLog");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.DeleteDiagnosticLog(managedDeviceType, managedDeviceId, logResult[0]["id"])));

                Console.WriteLine("ClearAllDiagnosticLogs");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.ClearAllDiagnosticLogs(managedDeviceType, managedDeviceId)));



                Console.WriteLine("AddErrorCode");
                var err = new IBMWIoTP.ErrorCodeInfo();
                err.errorCode = 0;
                err.timestamp = "";
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.AddErrorCode(managedDeviceType, managedDeviceId, err)));

                Console.WriteLine("GetDeviceErrorCodes");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceErrorCodes(managedDeviceType, managedDeviceId)));

                Console.WriteLine("ClearDeviceErrorCodes");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.ClearDeviceErrorCodes(managedDeviceType, managedDeviceId)));

                Console.WriteLine("Problem ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceConnectionLogs(managedDeviceType, managedDeviceId)));

                Console.WriteLine("data usage ");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDataUsage("2016", "2016", false)));


                Console.WriteLine("Service Status");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetServiceStatus()));

                Console.WriteLine("lastEvents");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetLastEvents(managedDeviceType, managedDeviceId)));

                Console.WriteLine("lastEvents of type");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetLastEventsByEventType(managedDeviceType, managedDeviceId, "test")));


                Console.WriteLine("GetAllDeviceManagementRequests");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetAllDeviceManagementRequests()));

                Console.WriteLine("InitiateDeviceManagementRequest");
                IBMWIoTP.DeviceMgmtparameter [] param = new IBMWIoTP.DeviceMgmtparameter[1];
                IBMWIoTP.DeviceMgmtparameter    p     = new IBMWIoTP.DeviceMgmtparameter();
                p.name   = "rebootAfter";
                p.value  = "100";
                param[0] = p;
                IBMWIoTP.DeviceListElement [] deviceList = new IBMWIoTP.DeviceListElement[1];
                IBMWIoTP.DeviceListElement    ele        = new IBMWIoTP.DeviceListElement();
                ele.typeId    = managedDeviceType;
                ele.deviceId  = managedDeviceId;
                deviceList[0] = ele;
                var response = client.InitiateDeviceManagementRequest("device/reboot", param, deviceList);             //new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<dynamic>(jsonResponse);
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(response));
                string id = response["reqId"];

                Console.WriteLine("GetDeviceManagementRequest");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceManagementRequest(id)));

                Console.WriteLine("GetDeviceManagementRequestStatus");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceManagementRequestStatus(id)));

                Console.WriteLine("GetDeviceManagementRequestStatus");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceManagementRequestStatus(id, ele.typeId, ele.deviceId)));

                Console.WriteLine("DeleteDeviceManagementRequest");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.DeleteDeviceManagementRequest(id)));

                Console.WriteLine("weather");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(client.GetDeviceLocationWeather(managedDeviceType, managedDeviceId)));
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
            Console.Write("Press any key to exit . . . ");
            Console.ReadKey();
        }
Exemple #8
0
 public void ApplicationClientgetApiClient()
 {
     IBMWIoTP.ApiClient cli = testApp.GetAPIClient();
     Assert.IsInstanceOf <IBMWIoTP.ApiClient>(cli);
 }
Exemple #9
0
        public static void sampleSequence(IBMWIoTP.ApiClient cli)
        {
            SchemaDraft sd = new SchemaDraft();

            sd.name       = "tempEventSchema";
            sd.schemaFile = "tempSchemaPi.json";
            Console.WriteLine("Create a draft event schema resource for your event type");
            SchemaInfo sc = cli.AddDraftSchema(sd);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(sc));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Create a draft event type that references the event schema");
            EventTypeDraft draft = new EventTypeDraft();

            draft.name        = "test";
            draft.description = "eventType for temperature";
            draft.schemaId    = sc.id;
            EventTypeInfo info = cli.AddDraftEventType(draft);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(info));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Create a draft physical interface");
            PhysicalInterfaceDraft draftPI = new PhysicalInterfaceDraft();

            draftPI.name        = "TempPI";
            draftPI.description = "new PhysicalInterfaces for temp";
            PhysicalInterfacesInfo newPI = cli.AddDraftPhysicalInterfaces(draftPI);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(newPI));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Add the event type to the draft physical interface");
            EventTypeBind bind = new EventTypeBind();

            bind.eventId     = deviceEvent;
            bind.eventTypeId = info.id;
            EventTypeBind bindResponse = cli.MapDraftPhysicalInterfacesEvent(newPI.id, bind);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(bindResponse));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Update the draft device type to connect the draft physical interface");
            PhysicalInterfacesInfo updatedPI = cli.AddDraftDeviceTypePI(deviceType, newPI);

            Console.WriteLine("===============================================================================");
            Console.WriteLine("Create a draft logical interface schema resource");
            SchemaDraft sdLI = new SchemaDraft();

            sdLI.name       = "temperatureEventSchema";
            sdLI.schemaFile = "tempSchemaLi.json";
            SchemaInfo schemaForLI = cli.AddDraftSchema(sdLI);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(schemaForLI));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Create a draft logical interface that references a draft logical interface schema");
            LogicalInterfaceDraft draftLI = new LogicalInterfaceDraft();

            draftLI.name     = "environment sensor interface";
            draftLI.schemaId = schemaForLI.id;
            LogicalInterfaceInfo newLI = cli.AddDraftLogicalInterfaces(draftLI);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(newLI));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Add the draft logical interface to a device type");
            LogicalInterfaceInfo mappedLI = cli.AddDraftDeviceTypeLI(deviceType, newLI);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(mappedLI));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Define mappings to map properties in the inbound event to properties in the logical interface");
            MappingDraft liMappingDraft = new MappingDraft();

            liMappingDraft.notificationStrategy = "on-every-event";
            liMappingDraft.propertyMappings     = new {
                test = new {
                    temperature = "$event.temp"
                }
            };
            liMappingDraft.logicalInterfaceId = mappedLI.id;
            MappingInfo mappedLiInfo = cli.AddDraftDeviceTypeMapping(deviceType, liMappingDraft);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(mappedLiInfo));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Validate and activate the configuration");
            OperationInfo activate = new OperationInfo(OperationInfo.Activate);
            var           responce = cli.OperateDraftDeviceType(deviceType, activate);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(responce));
            Console.WriteLine("===============================================================================");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetCurrentDeviceState(deviceType, "1qaz2wsx", mappedLI.id)));
        }
Exemple #10
0
        public static void DeviceType(IBMWIoTP.ApiClient cli, LogicalInterfaceInfo li, PhysicalInterfacesInfo pi)
        {
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get all device type");
            var deviceTypes = cli.GetAllDeviceTypes();

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(deviceTypes));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("operate on draft device type");
            OperationInfo work = new OperationInfo(OperationInfo.Validate);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.OperateDraftDeviceType(deviceType, work)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get all draft Logical Interface associated device type");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetAllDraftDeviceTypeLI(deviceType)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Assocate Logical Interface with draft device type");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.AddDraftDeviceTypeLI(deviceType, li)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get all draft Device type mapping");
            MappingInfo[] info = cli.GetAllDraftDeviceTypeMapping(deviceType);
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(info));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Add draft Device type mapping");
            MappingDraft liMappingDraft = new MappingDraft();

            liMappingDraft.notificationStrategy = "on-every-event";
            liMappingDraft.propertyMappings     = new {
                test = new {
                    temperature = "$event.temp"
                }
            };
            liMappingDraft.logicalInterfaceId = li.id;
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.AddDraftDeviceTypeMapping(deviceType, liMappingDraft)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get  draft Device type mapping with LI id");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetDraftDeviceTypeMapping(deviceType, li.id)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Update  draft Device type mapping with LI id");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.UpdatedDraftDeviceTypeMapping(deviceType, liMappingDraft)));

            Console.WriteLine("===============================================================================");
            Console.WriteLine("Add draft Device type To PI ");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.AddDraftDeviceTypePI(deviceType, pi)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get draft Device type To PI ");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetDraftDeviceTypePI(deviceType)));


            Console.WriteLine("===============================================================================");
            Console.WriteLine("Delete draft Device type mapping");
            cli.DeleteDraftDeviceTypeMapping(deviceType, li.id);
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Delete draft Device type To PI ");
            cli.DeleteDraftDeviceTypePI(deviceType);
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Operate on Device type");
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get all active Device type Logical interface");
            LogicalInterfaceInfo[] coll = cli.GetAllActiveDeviceTypeLI(deviceType);
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(coll));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get all active Device type mapping");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetAllActiveDeviceTypeMappings(deviceType)));
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Get active Device type Physical interface");
            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetActiveDeviceTypePI(deviceType)));
            Console.WriteLine("===============================================================================");
            if (coll.Length > 0)
            {
                Console.WriteLine("Get all on Device type mapping");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetActiveDeviceTypeMappingLI(deviceType, coll[0].id)));
                Console.WriteLine("===============================================================================");
                Console.WriteLine("Get Device Type associated with logical interface id");
                Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.GetAllDraftDeviceType("", coll[0].id)));
                Console.WriteLine("===============================================================================");
            }
            OperationInfo action = new OperationInfo(OperationInfo.Deactivate);

            Console.WriteLine(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(cli.OperateDeviceType(deviceType, action)));
        }
Exemple #11
0
        public static void Main(string[] args)
        {
            Console.WriteLine("============================ IBM WatsonIoTP Sample ============================");

            bool isSync = false;
            List <ConectedDevice> devices = new List <ConectedDevice>();

            Console.WriteLine("Gateway connectd device management sample");
            Console.WriteLine("Check Out Following Device manage action on connected device ");
            Console.WriteLine("1.Reboot");
            Console.WriteLine("2.Reset");
            Console.WriteLine("3.Firmware download and update");
            Console.WriteLine("4.Any key to exit");
            Console.Write("Please enter your choice :");
            int val = int.Parse(Console.ReadLine());

            DeviceInfo simpleDeviceInfo = new DeviceInfo();

            simpleDeviceInfo.description         = "My device";
            simpleDeviceInfo.deviceClass         = "My device class";
            simpleDeviceInfo.manufacturer        = "My device manufacturer";
            simpleDeviceInfo.fwVersion           = "Device Firmware Version";
            simpleDeviceInfo.hwVersion           = "Device HW Version";
            simpleDeviceInfo.model               = "My device model";
            simpleDeviceInfo.serialNumber        = "12345";
            simpleDeviceInfo.descriptiveLocation = "My device location";

            GatewayManagement gwMgmtClient = new GatewayManagement("GatewayCreds.txt", isSync);

            gwMgmtClient.deviceInfo    = simpleDeviceInfo;
            gwMgmtClient.mgmtCallback += (string reqestId, string responseCode) => {
                Console.WriteLine("req Id:" + reqestId + "	responseCode:"+ responseCode);
            };
            gwMgmtClient.actionCallback += (string reqestId, string action) => {
                Console.WriteLine("req Id:" + reqestId + "	Action:"+ action + " called");
                if (action == "reboot")
                {
                    gwMgmtClient.sendResponse(reqestId, DeviceManagement.RESPONSECODE_ACCEPTED, "");

                    Thread.Sleep(2000);
                    gwMgmtClient.disconnect();

                    Console.WriteLine("disconnected");
                    Thread.Sleep(5000);

                    Console.WriteLine("Re connected");
                    gwMgmtClient.connect();

                    gwMgmtClient.managedGateway(4000, true, true);
                }
                if (action == "reset")
                {
                    gwMgmtClient.sendResponse(reqestId, DeviceManagement.RESPONSECODE_FUNCTION_NOT_SUPPORTED, "");
                }
            };
            gwMgmtClient.fwCallback += (string action, DeviceFirmware fw) => {
                if (action == "download")
                {
                    gwMgmtClient.setState(DeviceManagement.UPDATESTATE_DOWNLOADING);
                    Console.WriteLine("Start downloading new Firmware from " + fw.uri);
                    Thread.Sleep(2000);
                    Console.WriteLine("completed Download");
                    gwMgmtClient.setState(DeviceManagement.UPDATESTATE_DOWNLOADED);
                }
                if (action == "update")
                {
                    gwMgmtClient.setUpdateState(DeviceManagement.UPDATESTATE_IN_PROGRESS);
                    Console.WriteLine("Start Updating new Firmware ");
                    Thread.Sleep(2000);
                    Console.WriteLine("Updated new Firmware ");
                    gwMgmtClient.setUpdateState(DeviceManagement.UPDATESTATE_SUCCESS);
                }
            };
            gwMgmtClient.connect();
            Console.WriteLine("Manage");
            gwMgmtClient.managedGateway(4000, true, true);
            //Connected device
            ConectedDevice device1 = new ConectedDevice("testgwdev", "1234", gwMgmtClient);

            device1.isActionEnabled    = true;
            device1.isFramewareEnabled = true;
            device1.canReboot          = true;
            device1.canReset           = false;
            devices.Add(device1);
            gwMgmtClient.managedDevice(device1.deviceType, device1.deviceId, 4000, device1.isActionEnabled, device1.isFramewareEnabled);
            gwMgmtClient.connectedDeviceActionCallback += (string devicetype, string deviceid, string reqestId, string action) => {
                Console.WriteLine(devicetype + ": " + deviceid + ":" + reqestId + ":" + action);
                var itm = devices.Find(x => x.deviceId == deviceid);
                if (itm is ConectedDevice)
                {
                    if (action == GatewayManagement.ACTION_REBOOT)
                    {
                        if (itm.canReboot)
                        {
                            gwMgmtClient.sendResponse(reqestId, DeviceManagement.RESPONSECODE_ACCEPTED, "", itm.deviceType, itm.deviceId);
                            Thread.Sleep(2000);
                            gwMgmtClient.managedDevice(itm.deviceType, itm.deviceId, 4000, itm.isActionEnabled, itm.isFramewareEnabled);
                        }
                        else
                        {
                            gwMgmtClient.sendResponse(reqestId, DeviceManagement.RESPONSECODE_FUNCTION_NOT_SUPPORTED, "", itm.deviceType, itm.deviceId);
                        }
                    }
                    if (action == GatewayManagement.ACTION_RESET)
                    {
                        if (itm.canReset)
                        {
                            gwMgmtClient.sendResponse(reqestId, DeviceManagement.RESPONSECODE_ACCEPTED, "", itm.deviceType, itm.deviceId);
                        }
                        else
                        {
                            gwMgmtClient.sendResponse(reqestId, DeviceManagement.RESPONSECODE_FUNCTION_NOT_SUPPORTED, "", itm.deviceType, itm.deviceId);
                        }
                    }
                }
            };



            gwMgmtClient.connectedDevicefwActionCallback += (string devicetype, string deviceid, string action, DeviceActionReq req) => {
                ConectedDevice itm = devices.Find(x => x.deviceId == deviceid);
                switch (action)
                {
                case GatewayManagement.FIRMWARE_ACTION_INFO:
                    itm.infoHandler(req);
                    break;

                case GatewayManagement.FIRMWARE_ACTION_DOWNLOAD:
                    itm.downloadHandler(req);
                    break;

                case GatewayManagement.FIRMWARE_ACTION_UPDATE:
                    itm.updatedHandler(req);
                    break;

                default:

                    break;
                }
            };

            IBMWIoTP.ApplicationClient appClient = new ApplicationClient("AppCreds.txt");
            IBMWIoTP.ApiClient         client    = appClient.GetAPIClient();
            client.Timeout = 5000;
            IBMWIoTP.DeviceMgmtparameter [] param = new IBMWIoTP.DeviceMgmtparameter[1];
            IBMWIoTP.DeviceMgmtparameter    p     = new IBMWIoTP.DeviceMgmtparameter();
            p.name   = "uri";
            p.value  = "https://raw.githubusercontent.com/ibm-watson-iot/iot-python/master/CHANGES.txt";
            param[0] = p;
            IBMWIoTP.DeviceListElement [] deviceList = new IBMWIoTP.DeviceListElement[1];
            IBMWIoTP.DeviceListElement    ele        = new IBMWIoTP.DeviceListElement();
            ele.typeId    = "testgw";
            ele.deviceId  = "1212";
            deviceList[0] = ele;

            switch (val)
            {
            case 1: client.InitiateDeviceManagementRequest("device/reboot", param, deviceList);
                break;

            case 2: client.InitiateDeviceManagementRequest("device/factoryReset", param, deviceList);
                break;

            case 3: client.InitiateDeviceManagementRequest("firmware/download", param, deviceList);
                Thread.Sleep(15000);
                client.InitiateDeviceManagementRequest("firmware/update", new IBMWIoTP.DeviceMgmtparameter[0], deviceList);
                break;

            default:
                gwMgmtClient.disconnect();
                break;
            }
        }