/// <summary> /// Register a new device with Octoblu. /// </summary> /// <param name="dev">JSON object that represent custom properties you want on the device</param> /// <param name="owneruuid">Uuid of the Octoblu account owner to register device under</param> /// <param name="type">device type designation on Octoblu</param> public void RegisterDevice(string name, string devJson, string owneruuid, string type) { ManualResetEvent syncEvent = new ManualResetEvent(false); try { // Read Octoblu configuration from the registry _config.Read(); SetupMeshbluConnection(); // Add the rest of the properties to Octoblu device if (name == null || devJson == null || owneruuid == null || type == null) { throw new ArgumentException("Null argument specified"); } var dev = JObject.Parse(devJson); dev["name"] = name; dev["type"] = "device:" + type; var owners = new JArray(); owners.Add(owneruuid); dev["owner"] = owners; var all = new JArray(); all.Add("*"); if (dev["configureWhitelist"] == null) { dev["configureWhitelist"] = owners; // only owners can configure this device } if (dev["discoverWhitelist"] == null) { dev["discoverWhitelist"] = owners; // only owners are can discover this device } if (dev["receiveWhitelist"] == null) { dev["receiveWhitelist"] = all; // anyone can receive messages from this device } if (dev["sendWhitelist"] == null) { dev["sendWhitelist"] = all; // anyone can send messages to this device } Trace.WriteLine("OctobluClient: Registering device.... for owner:" + owneruuid); _socket.Emit( "register", new AckImpl((newdevicedata) => { Trace.WriteLine(newdevicedata.ToString()); // write the new device uuid and token to user's registry var newDevice = JsonConvert.DeserializeObject <RegisterResponse>(newdevicedata.ToString()); _config.Write(newDevice.uuid, newDevice.token); syncEvent.Set(); }), dev); } catch (Exception e) { syncEvent.Set(); Trace.WriteLine("OctobluClient Exception Registering device : " + e.ToString()); } syncEvent.WaitOne(); }
//////////////////////////////////////////////////// // IOctoblu interface implementation //////////////////////////////////////////////////// /// <summary> /// Initializes a plugin /// </summary> /// <param name="config">Configuration for the plugin's deviec (device uuid and token)</param> /// <param name="plugin">Plugin interface to recieve events on</param> /// <returns></returns> public bool InitializePlugin(IMeshbluConfig config, IMeshbluPlugin plugin) { _config = config; _plugin = plugin; return _config.Read(); }
//////////////////////////////////////////////////// // IOctoblu interface implementation //////////////////////////////////////////////////// /// <summary> /// Initializes a plugin /// </summary> /// <param name="config">Configuration for the plugin's deviec (device uuid and token)</param> /// <param name="plugin">Plugin interface to recieve events on</param> /// <returns></returns> public bool InitializePlugin(IMeshbluConfig config, IMeshbluPlugin plugin) { _config = config; _plugin = plugin; return(_config.Read()); }